Proportion test in R

A proportion test is a statistical method used to compare proportions or percentages between one or more groups. It helps determine whether observed differences in proportions are statistically significant or simply due to random sampling variation.

Proportion tests are widely used in healthcare, marketing, manufacturing, education, finance, political polling, A/B testing, and quality control.

In this tutorial, you’ll learn the assumptions, hypotheses, types of proportion tests, and how to perform them in R using the built-in prop.test() function.

What Is a Proportion Test?

A proportion test evaluates whether the proportion of successes in one or more populations differs from a specified value or from another population.

Examples include:

  • Comparing conversion rates between two websites.
  • Comparing vaccine effectiveness.
  • Evaluating product defect rates.
  • Comparing customer satisfaction percentages.
  • Comparing election polling results.
  • Measuring email campaign response rates.

Unlike a t-test, which compares means, a proportion test compares categorical outcomes, typically classified as success/failure or yes/no.


When Should You Use a Proportion Test?

Use a proportion test when:

  • The outcome variable is binary (success/failure).
  • You want to compare proportions.
  • Observations are independent.
  • Sample sizes are sufficiently large for the normal approximation.

Examples include:

  • Purchased vs Did Not Purchase
  • Passed vs Failed
  • Defective vs Non-defective
  • Recovered vs Not Recovered
  • Clicked vs Not Clicked

Assumptions of a Proportion Test

Before performing a proportion test, verify the following assumptions:

1. Random Sampling

Each sample should be collected using simple random sampling.

2. Independent Samples

Observations should be independent within and between samples.

3. Sufficient Sample Size

For the chi-square approximation used by prop.test(), each group should generally have at least:

  • 10 successes
  • 10 failures

4. Population Size

Each population should be much larger than the sample. A common guideline is that the population size should be at least 20 times the sample size when sampling without replacement.

Note: When sample sizes are very small or the success/failure counts are low, an exact binomial test (binom.test()) is often more appropriate than prop.test().


Types of Proportion Tests

The most common proportion tests include:

  • One-sample proportion test
  • Two-sample proportion test
  • Multiple-sample proportion test

One-Sample Proportion Test

A one-sample proportion test determines whether the observed population proportion differs from a specified value.

Example

A manufacturer claims that 95% of products pass inspection.

You inspect 200 products and want to determine whether the actual pass rate differs from 95%.


Two-Sample Proportion Test

A two-sample proportion test compares the proportions of two independent populations.

Examples include:

  • Website A vs Website B
  • Treatment vs Control
  • Product A vs Product B
  • Marketing Campaign A vs Campaign B

Hypotheses

Two-Sided Test

Null hypothesis:H0:pA=pBH_0:p_A=p_BH0​:pA​=pB​

Alternative hypothesis:HA:pApBH_A:p_A\neq p_BHA​:pA​=pB​

This determines whether the proportions are different.


One-Sided Test (Greater)

H0:pApBH_0:p_A\le p_BH0​:pA​≤pB​ HA:pA>pBH_A:p_A>p_BHA​:pA​>pB​


One-Sided Test (Less)

H0:pApBH_0:p_A\ge p_BH0​:pA​≥pB​ HA:pA<pBH_A:p_A<p_BHA​:pA​<pB​


The prop.test() Function in R

The basic syntax is:

prop.test(
x,
n,
p = NULL,
alternative = "two.sided",
correct = TRUE
)

Arguments

ArgumentDescription
xNumber of successes
nTotal sample size
pHypothesized proportion (one-sample test)
alternative"two.sided", "greater", or "less"
correctApply Yates’ continuity correction (default = TRUE)

One-Sample Proportion Test in R

Suppose 490 out of 500 customers are satisfied.

You want to determine whether the satisfaction rate differs from 95%.

prop.test(
x = 490,
n = 500,
p = 0.95
)

The output includes:

  • Chi-square statistic
  • Degrees of freedom
  • p-value
  • Confidence interval
  • Estimated proportion

Two-Sample Proportion Test

Suppose:

  • Group A: 490 successes out of 500
  • Group B: 400 successes out of 500
prop.test(
x = c(490,400),
n = c(500,500)
)

This performs a two-sided test by default.


One-Sided Test (Less)

prop.test(
x = c(400,350),
n = c(500,500),
alternative = "less"
)

This tests whether the first population proportion is smaller.


One-Sided Test (Greater)

prop.test(
x = c(400,350),
n = c(500,500),
alternative = "greater"
)

This tests whether the first proportion is larger.


Example Output

2-sample test for equality of proportions

X-squared = 14.26

df = 1

p-value = 0.00017

95 percent confidence interval:
0.052 0.188

sample estimates:
prop 1 = 0.98
prop 2 = 0.80

Interpreting the Results

Suppose the output reports:

p-value = 0.00017

Since

0.00017 < 0.05

we reject the null hypothesis.

There is strong statistical evidence that the two population proportions differ.

The confidence interval also provides an estimate of the magnitude of the difference between the proportions.


Yates’ Continuity Correction

By default, prop.test() applies Yates’ continuity correction, which adjusts the chi-square statistic for 2×2 contingency tables.

You can disable it if desired:

prop.test(
x = c(490,400),
n = c(500,500),
correct = FALSE
)

For large sample sizes, the difference is usually minimal.


Exact Binomial Test

When sample sizes are small or expected counts are low, use binom.test() instead of prop.test().

Example:

binom.test(
x = 8,
n = 10,
p = 0.5
)

This calculates an exact p-value without relying on the normal approximation.


Practical Applications

Proportion tests are widely used in:

  • Clinical trials
  • Public health
  • Marketing analytics
  • Digital A/B testing
  • Election polling
  • Customer satisfaction surveys
  • Manufacturing quality control
  • Financial fraud detection
  • Website conversion optimization
  • Educational assessment

Common Mistakes

Avoid these common errors:

  • Using a proportion test for continuous data.
  • Applying prop.test() with very small sample sizes instead of binom.test().
  • Ignoring the assumption of independent observations.
  • Misinterpreting a non-significant result as proof that proportions are identical.
  • Reporting only the p-value without confidence intervals or observed proportions.

Conclusion

The proportion test is an essential statistical tool for comparing binary outcomes across one or more groups. In R, the prop.test() function provides a simple and effective way to conduct one-sample and two-sample proportion tests, while binom.test() offers an exact alternative for smaller samples.

Before performing the analysis, ensure that the assumptions are met, particularly regarding random sampling, independence, and adequate sample sizes. By selecting the appropriate test and carefully interpreting the p-value, confidence interval, and estimated proportions, you can make reliable, data-driven decisions in fields ranging from healthcare and manufacturing to marketing and A/B testing.

You may also like...

1 Response

Leave a Reply

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

fifteen − seven =