In: Statistics and Probability
We know that given frequencies are known as observed frequencies.
Hence, total of frequency = N = 400.
Given that, probabilities of the color peanut.
Now we obtain expected frequency = (probabilities*observed frequency)
Now the hypothesis is,
H0 : Peanut M&Ms follow the distribution stated by M&M/Mars
vs H1 : peanut M&Ms does not follow the distribution stated by M&M/Mars
If Oi = observed frequency and ei = expected frequency then the test statistic for testing above hypothesis is
Hence R code for the above problem is
R-code:
o=c(53,66,38,96,88,59) ## o = Observed Frequency
N=sum(o) ## N = Total Frequency
pr=c(0.12,0.15,0.12,0.23,0.23,0.15) ## pr = Given probabilities
e=N*pr ## e = Expected Frequency
chisq.test(x=o,p=pr) ## chisquare test for goodness of fit
## Now manual calculations
chi_test=sum(((o-e)^2)/e) ## chisquare test statistic
pvalue=pchisq(chi_test,df=5,lower.tail=FALSE) ## pvalue for test
print(c(chi_test,pvalue))
R code with output:
> o=c(53,66,38,96,88,59) ## o = Observed Frequency
> N=sum(o) ## N = Total Frequency
> pr=c(0.12,0.15,0.12,0.23,0.23,0.15) ## pr = Given
probabilities
> e=N*pr ## e = Expected Frequency
> chisq.test(x=o,p=pr) ## chisquare test for goodness of fit
# Output : Chi-squared test for given probabilities
data: o
X-squared = 3.5687, df = 5, p-value = 0.613
> ## Now manual calculations
>
> chi_test=sum(((o-e)^2)/e) ## chisquare test statistic
> pvalue=pchisq(chi_test,df=5,lower.tail=FALSE) ## pvalue for
test
> print(c(chi_test,pvalue))
# Output:
[1] 3.568659 0.613025
From the above output, we get
Chi-square test statistic = 3.5687
p-value = 0.613
Let level of significance = 0.05
Since p-value = 0.613 > level of significance = 0.05, hence we cannot reject the null hypothesis H0 at 5% level of significance and conclude that peanut M&Ms follow the distribution stated by M&M/Mars at 5% level of significance.