How to Perform a One Proportion Z-Test in R (With Examples)

A one proportion z-test is used to compare an observed proportion to a theoretical one.

This test uses the following null hypotheses:

  • H0p = p0 (population proportion is equal to hypothesized proportion p0)

The alternative hypothesis can be either two-tailed, left-tailed, or right-tailed:

  • H1 (two-tailed): p ≠ p0 (population proportion is not equal to some hypothesized value p0)
  • H1 (left-tailed): p < p0 (population proportion is less than some hypothesized value p0)
  • H1 (right-tailed): p > p0 (population proportion is greater than some hypothesized value p0)

The test statistic is calculated as:

z = (p-p0) / √p0(1-p0)/n


  • p: observed sample proportion
  • p0: hypothesized population proportion
  • n: sample size

If the p-value that corresponds to the test statistic z is less than your chosen significance level (common choices are 0.10, 0.05, and 0.01) then you can reject the null hypothesis.

One Proportion Z-Test in R

To perform a one proportion z-test in R, we can use one of the following functions:

  • If n ≤ 30: binom.test(x, n, p = 0.5, alternative = “two.sided”)
  • If n> 30: prop.test(x, n, p = 0.5, alternative = “two.sided”, correct=TRUE)


  • x: The number of successes
  • n: The number of trials
  • p: The hypothesized population proportion
  • alternative: The alternative hypothesis
  • correct: Whether or not to apply Yates’ continuity correction

The following example shows how to carry out a one proportion z-test in R.

Example: One Proportion Z-Test in R

Suppose we want to know whether or not the proportion of residents in a certain county who support a certain law is equal to 60%. To test this, we collect the following data on a random sample:

  • p0: hypothesized population proportion = 0.60
  • x: residents who support law: 64
  • n: sample size = 100

Since our sample size is greater than 30, we can use the prop.test() function to perform a one sample z-test:

prop.test(x=64, n=100, p=0.60, alternative="two.sided")

	1-sample proportions test with continuity correction

data:  64 out of 100, null probability 0.6
X-squared = 0.51042, df = 1, p-value = 0.475
alternative hypothesis: true p is not equal to 0.6
95 percent confidence interval:
 0.5372745 0.7318279
sample estimates:

From the output we can see that the p-value is 0.475. Since this value is not less than α = 0.05, we fail to reject the null hypothesis. We do not have sufficient evidence to say that the proportion of residents who support the law is different from 0.60.

The 95% confidence interval for the true proportion of residents in the county that support the law is also found to be:

95% C.I. = [0.5373, 7318]

Since this confidence interval contains the proportion 0.60, we do not have evidence to say that the true proportion of residents who support the law is different from 0.60. This matches the conclusion we came to using just the p-value of the test.

Additional Resources

An Introduction to the One Proportion Z-Test
One Proportion Z-Test Calculator
How to Perform a One Proportion Z-Test in Excel

One Reply to “How to Perform a One Proportion Z-Test in R (With Examples)”

  1. prop.test(x=64, n=100, p=0.60, alternative=”two.sided”) DOES NOT use the test statistics z = (p-p0) / sqrt(p0(1-p0)/n).
    Using your example, we have z=(0.64-0.6)/sqrt(0.6*0.4/100) = 0.8165.
    The p-value is 2P(Z >= 0.8165), where Z is N(0,1), i.e.,
    The corresponding 95% confidence interval is
    [0.64-1.959964*sqrt(0.64*0.36/100), 0.64+1.959964*sqrt(0.64*0.36/100) ]=
    [0.54592173, 0.7340783].
    I used 1.959964 instead of 1.96, for better accuracy.
    prop.test(x=64, n=100, p=0.60, alternative=”two.sided”) USES a X2 test statistics, wich value for your example (using Yates continuity correction), is given by
    X-squared=((|36-40|-0.5)^2)/40+((|64-60|-0.5)^2)/60=0.51041(6) . This is the X-squared in the output: 0.51042.
    In this case, the p-value is given by P(Q >= 0.51042)=0.4749571, which is the p-value in the output: 0.475 (Q is distributed according to a chi-squared distribution with 1 df).
    I don’t know how the corresponding confidence interval is obtained (but I would very much like to know!) and and also don’t know if there is a function in R that allow us to perform the test for proportions using the Z statistic. I also would very much like to know this!

Leave a Reply

Your email address will not be published. Required fields are marked *