The Scene

Conducting a test of significance for one proportion.

In particular, suppose we want to test whether a population proportion is equal to the value \(p_0\),

\[H_0: p = p_0\]

against one of these three alternative hypotheses:

The Example

We have a 6-sided die and we believe we roll a four more often than chance would allow!

We let \(p\) denote the proportion of times we’d roll a four in the long run. For a fair 6-sided die, we would expect \(p = 1/6\). The claim here is that for me, \(p > 1/6\).

These two statements give us our hypotheses for a test of significance:

\[ \begin{cases} H_o: p = 1/6 \\ H_a: p > 1/6 \end{cases} \] To conduct the test we gather data. How about I roll 100 times and record how often I roll a four? Hang on while I do that…

Done! It turns out I rolled a four on 22 of my 100 rolls.

To conduct the test we follow the Prepare-Check-Calculate-Conclude procedure:

Prepare for the significance test.

Our sample size is \(n = 100\), and we rolled \(x = 22\) fours, so the sample proportion of fours rolled is \[\hat{p} = \frac{22}{100} = 0.22.\]

Check that the success-failure conditions hold: our success count is 22, our failure count is 78, both at least 10, so the distribution for \(\hat{p}\) is nearly normal.

Calculate

We find the test statistic from our data, which is a z-score in this case, and the p-value associated to this test statistic. We can ask RStudio to do the calculations, and note that the test statistic is given by the formula \[z = \frac{\hat{p}-p_0}{\sqrt{p_0(1-p_0)/n}},\] where \(p_0\) is the value of the proportion in the null hypothesis.

## Conducting a test of significance for one proportion.

# Significance level
alpha=.05 

# Value of p under the null hypothesis: H_0: p = p_0
p_0 = 1/6 

# Data
n=100 #trials
x=22 #successes
phat = x/n

# Standard Error
SE = sqrt(p_0*(1-p_0)/n)

# Test statistic
z = (phat-p_0)/SE

# p-value (for each type of alternative hypothesis)
p_val.lt = pnorm(z) # this is the p-value if H_a: p < p_0
p_val.gt = 1 - pnorm(z) # this is the p-value if H_a: p > p_0
p_val.neq = 2*(1-pnorm(abs(z))) # this is the p-value if H_a: p not equal to p_0


## Generating a readable output:
cat(paste0("Null hypthosis: p = ",round(p_0,4),"\n",
           "sample proportion, phat = ",round(phat,4),"\n",
           "test statistic, z = ",round(z,3),"\n",
           "p-value for H_a: p < p_0: ",round(p_val.lt,4),"\n",
           "p-value for H_a: p > p_0: ",round(p_val.gt,4),"\n",
           "p-value for H_a: p not p_0: ",round(p_val.neq,4),"\n"))
## Null hypthosis: p = 0.1667
## sample proportion, phat = 0.22
## test statistic, z = 1.431
## p-value for H_a: p < p_0: 0.9238
## p-value for H_a: p > p_0: 0.0762
## p-value for H_a: p not p_0: 0.1524

In our example we used \(H_a: p > p_0\), so we obtain this p-value:

(p_value=p_val.gt)
## [1] 0.07620314

Conclude

Now, we compare this p-value to the significance level. In particular, we check whether

p_value < alpha
## [1] FALSE

FALSE! Since the p-value is not smaller than alpha, we fail to reject H_0 in favor of H_a at the significance level 0.05. We do not have sufficient evidence (at the 5% level) to conclude that we roll a 4 more often than chance would allow.

prop.test()

The built-in function prop.test() in R can conduct an hypothesis test on one population proportion as follows:

prop.test(x=22, n=100, p = 1/6, alternative = "greater", correct = FALSE)
## 
##  1-sample proportions test without continuity correction
## 
## data:  22 out of 100, null probability 1/6
## X-squared = 2.048, df = 1, p-value = 0.0762
## alternative hypothesis: true p is greater than 0.1666667
## 95 percent confidence interval:
##  0.1597386 1.0000000
## sample estimates:
##    p 
## 0.22

Notes

  1. The prop.test() print-out gives a value called X-squared. This value is \(z^2\), where \(z\) is the test statistic we computed above, so we can recover our test-statistic (plus or minus) by taking the square root of X-squared:
sqrt(2.048)
## [1] 1.431084
  1. The prop.test() print-out gives a confidence interval whose shape is dependent on the alternative hypothesis. In Section 5.2 we built a 95% confidence interval by focusing on the middle 95% of the N(0,1) distribution, but one can also build upper 95% or lower 95% confidence intervals. The confidence interval displayed in this print-out will be one of these three types depending on your alternative hypothesis. In this example, since \(H_a\) was “greater than”, the confidence interval displayed here is an upper 95% confidence interval.

  2. If we set the continuity correction to be true we obtain a slightly different (more conservative) result.

prop.test(x=22, n=100, p = 1/6, alternative = "greater", correct = TRUE)
## 
##  1-sample proportions test with continuity correction
## 
## data:  22 out of 100, null probability 1/6
## X-squared = 1.682, df = 1, p-value = 0.09733
## alternative hypothesis: true p is greater than 0.1666667
## 95 percent confidence interval:
##  0.1554081 1.0000000
## sample estimates:
##    p 
## 0.22