problem-9.3

problem-9.3  The data set gives percentages, but chisq.test() wants proportions. We first define a quick function to compute proportions, then apply the two tests.
> prop = function(x) x/sum(x)
> bagfull = c(15,34,7,19,29,24)
> names(bagfull) = c("blue","brown","green","orange","red","yellow")
> chisq.test(bagfull,p = prop(mandms["milk chocolate",]))

        Chi-squared test for given probabilities

data:  bagfull
X-squared = 7.065, df = 5, p-value = 0.2158

> chisq.test(bagfull,p = prop(mandms["Peanut",]))

        Chi-squared test for given probabilities

data:  bagfull
X-squared = 13.33, df = 5, p-value = 0.02049
    
It appears that the bag is milk chocolate not peanut.