How do I perform a One Proportion Z-Test in R, and what are some examples of its use?

A One Proportion Z-Test in R is a statistical test used to determine if the proportion of a certain characteristic in a sample is significantly different from a known population proportion. This test is commonly used in research studies and quality control processes to analyze data and make inferences about a population. To perform a One Proportion Z-Test in R, the user must have a dataset containing the sample proportions and the total number of observations. The test calculates a Z-score, which is then compared to a critical value from a standard normal distribution to determine the significance of the results. Some examples of its use include testing the effectiveness of a new treatment, comparing the proportion of defective products in a sample to a standard, or analyzing the success rate of a marketing campaign. This test is a valuable tool for decision making and drawing conclusions based on data in various fields such as healthcare, business, and social sciences.

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

where:

  • 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)

where:

  • 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

  • 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:
   p 
0.64 

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

x