An R Introduction to Statistics

Two-Tailed Test of Population Proportion

The null hypothesis of the two-tailed test about population proportion can be expressed as follows:

p = p0

where p0 is a hypothesized value of the true population proportion p.

Let us define the test statistic z in terms of the sample proportion and the sample size:

        ¯p− p0
z = ∘------------
      p0(1− p0)∕n

Then the null hypothesis of the two-tailed test is to be rejected if z ≤−zα∕2 or z zα∕2 , where zα∕2 is the 100(1 α) percentile of the standard normal distribution.

Problem

Suppose a coin toss turns up 12 heads out of 20 trials. At .05 significance level, can one reject the null hypothesis that the coin toss is fair?

Solution

The null hypothesis is that p = 0.5. We begin with computing the test statistic.

> pbar = 12/20           # sample proportion 
> p0 = .5                # hypothesized value 
> n = 20                 # sample size 
> z = (pbarp0)/sqrt(p0(1p0)/n) 
> z                      # test statistic 
[1] 0.89443

We then compute the critical values at .05 significance level.

> alpha = .05 
> z.half.alpha = qnorm(1alpha/2) 
> c(z.half.alpha, z.half.alpha) 
[1] 1.9600  1.9600

Answer

The test statistic 0.89443 lies between the critical values -1.9600 and 1.9600. Hence, at .05 significance level, we do not reject the null hypothesis that the coin toss is fair.

Alternative Solution 1

Instead of using the critical value, we apply the pnorm function to compute the two-tailed p-value of the test statistic. It doubles the upper tail p-value as the sample proportion is greater than the hypothesized value. Since it turns out to be greater than the .05 significance level, we do not reject the null hypothesis that p = 0.5.

> pval = 2  pnorm(z, lower.tail=FALSE)  # upper tail 
> pval                   # twotailed pvalue 
[1] 0.37109

Alternative Solution 2

We apply the prop.test function to compute the p-value directly. The Yates continuity correction is disabled for pedagogical reasons.

> prop.test(12, 20, p=0.5, correct=FALSE) 
 
        1sample proportions test without continuity 
        correction 
 
data:  12 out of 20, null probability 0.5 
Xsquared = 0.8, df = 1, pvalue = 0.3711 
alternative hypothesis: true p is not equal to 0.5 
95 percent confidence interval: 
  0.38658 0.78119 
sample estimates: 
  p 
0.6