Aim: To test whether there is significant difference between sample proportion and population
proportion.
Problem:
Suppose that 12% of apples harvested in an orchard last year was rotten. 30 out of 214 apples in a
harvest sample this year turns out to be rotten. At .05 significance level, can we reject the null
hypothesis that the proportion of rotten apples in harvest stays below 12% this year?
R – Code:-
The null hypothesis is that p ≤ 0.12. We begin with computing the test statistic.
>pbar=30/214
# sample proportion
> p0=0.12
# hypothesized value
> n=214
# sample size
> z=abs((pbar-p0)/sqrt(p0*(1-p0)/n))
>z
# test statistic
[1] 0.908751
We then compute the critical value at .05 significance level.
>alpha=0.05
>z.alpha=qnorm(1-alpha/2)
>z.alpha# critical value
[1] 1.959964