← All resources

How to Do Hypothesis Testing for Proportions in 4 Steps

7 min read
How to Do Hypothesis Testing for Proportions in 4 Steps

To carry out hypothesis testing proportions, state a null and an alternative hypothesis about the population proportion p, check that your sample is large enough for a normal approximation, compute the z statistic, and compare its p-value with your significance level. For one proportion, z = (p̂ − p₀) / √(p₀(1 − p₀) / n). For two proportions, you pool the groups before computing the standard error.

Most errors happen in the details. Students put the sample proportion into the standard error when the null value belongs there. Others pick the tail direction after seeing the data, or read a large p-value as proof that nothing happened. Each of these slips changes your answer.

This guide covers four steps, with one worked example for a single proportion and one for two proportions. You will also see how to run both tests in Python, and how PlotStudio AI, a research analysis workspace that generates inspectable Python for statistical tests, handles the same calculation.

Before you start: what the test needs

What a proportion test answers

A proportion is the share of a population with a yes/no trait, such as patients readmitted within 30 days. Hypothesis testing for a proportion asks whether a sample is consistent with a claimed value. With one sample, you compare p̂ to a benchmark p₀. With two samples, you ask whether two groups have the same underlying proportion.

The outcome must be binary. Recode every observation as success or failure before you begin.

Conditions to check

The z-test relies on a normal approximation to the binomial distribution. That approximation holds only when these conditions are met:

  • The data come from a random sample or a randomized experiment, and observations are independent.
  • Every observation has exactly two possible outcomes.
  • One sample: n × p₀ and n × (1 − p₀) are both at least 10. Some textbooks accept 5.
  • Two samples: each group has at least 10 successes and 10 failures, and the groups are independent.
  • If you sample without replacement, the sample is under 10% of the population.

When counts are too small, use the exact binomial test for one proportion or Fisher's exact test for two.

If the conditions fail, the z-test p-value cannot be trusted, however clean the arithmetic looks.

Step 1. State the hypotheses and significance level

Write H0 and H1 about p

The null hypothesis always contains an equals sign: H0: p = p₀. The alternative is one of p < p₀, p > p₀, or p ≠ p₀. Hypotheses describe the population parameter p, never the sample proportion p̂.

Here is the running example. A hospital's 30-day readmission rate has been 20%. After a new discharge program, 32 of 200 patients return, so p̂ = 0.16. Did the rate fall? Then H0: p = 0.20 and H1: p < 0.20.

Fix the tails and α first

Choose α, usually 0.05, and the tail direction from your research question before you look at results. Choosing afterward inflates your false-positive rate. The table gives the critical z values you will compare against.

Alternative hypothesis Test type Critical z at α = 0.05 Critical z at α = 0.01
p < p₀ Left-tailed −1.645 −2.326
p > p₀ Right-tailed 1.645 2.326
p ≠ p₀ Two-tailed ±1.960 ±2.576

Decide α and the direction of H1 before you see the data, or the p-value stops meaning what it says.

Step 2. Check conditions and compute the test statistic

The z formula for one proportion

The test statistic is z = (p̂ − p₀) / √(p₀(1 − p₀) / n). It counts how many standard errors your sample proportion sits from the null value. Use p₀ in the standard error, because the test assumes H0 is true. Confidence intervals are different and use p̂.

Worked example

Run the checks first, then compute:

  1. Conditions: n × p₀ = 200 × 0.20 = 40, and n × (1 − p₀) = 160. Both exceed 10.
  2. Standard error: √(0.20 × 0.80 / 200) = √0.0008 ≈ 0.0283.
  3. Test statistic: z = (0.16 − 0.20) / 0.0283 ≈ −1.41.

If you had used p̂ = 0.16 in the standard error, you would get 0.0259 and z ≈ −1.54, a noticeably different result.

The standard error uses the null proportion p₀, not the sample proportion p̂.

Step 3. Find the p-value and decide

Turn z into a decision

The p-value is the probability of a z at least this extreme if H0 were true. For a left-tailed test, it is the area below z: P(Z ≤ −1.41) ≈ 0.079. A right-tailed test uses the area above z. A two-tailed test doubles the smaller tail area.

Compare p to α. Reject H0 when p ≤ α, otherwise fail to reject. Here 0.079 > 0.05, so you fail to reject. The critical value method agrees: −1.41 does not fall below −1.645.

Write the conclusion in context: "At the 5% level, the sample does not provide sufficient evidence that the readmission rate fell below 20%." Do not write that H0 is true or that the program failed. With 200 patients, a four-point drop can still be chance.

Run it in software

In Python, statsmodels reproduces the hand calculation. Setting prop_var to the null value matches the formula above:

from statsmodels.stats.proportion import proportions_ztest

z, p = proportions_ztest(count=32, nobs=200, value=0.20,
                         alternative="smaller", prop_var=0.20)
print(round(z, 2), round(p, 3))  # -1.41 0.079

In PlotStudio AI, you upload the CSV and ask whether the rate fell below 20%. You can review the planned method in Verification Mode before it runs, then inspect the generated code. You still own the choices of tails and α.

If p is above α, you have failed to find evidence, which is not the same as showing there is no effect.

Step 4. Compare two proportions

The two-proportion z-test

For comparing two proportions with adequate counts, the two-proportion z-test is the standard choice. H0 is p₁ = p₂. Under H0 both groups share one proportion, so pool the data: p̂ = (x₁ + x₂) / (n₁ + n₂). Then z = (p̂₁ − p̂₂) / √(p̂(1 − p̂)(1/n₁ + 1/n₂)).

Example: 90 of 150 treated patients improved (60%), against 70 of 140 controls (50%). The pooled proportion is 160 / 290 ≈ 0.552. The standard error is √(0.552 × 0.448 × (1/150 + 1/140)) ≈ 0.0584, so z = 0.10 / 0.0584 ≈ 1.71. The two-sided p-value is about 0.087, so at α = 0.05 you fail to reject. A one-sided test would give 0.044, which is exactly why tails must be fixed beforehand.

z, p = proportions_ztest(count=[90, 70], nobs=[150, 140])
print(round(z, 2), round(p, 3))  # 1.71 0.087

When another test fits better

Some situations call for a different test:

  • Small counts: use Fisher's exact test for two groups, or the exact binomial test for one.
  • Two-by-two table: the squared two-sided z statistic equals the Pearson chi-square statistic without continuity correction, so both give the same p-value.
  • Same subjects measured twice: use McNemar's test, because the groups are not independent.
  • More than two groups: use a chi-square test of homogeneity.

Pool the proportions only because H0 says they are equal, and never pool when you build a confidence interval for the difference.

Putting the four steps to work

Every proportion test follows the same path. State H0 and H1 about p, fix α and the tails, compute z with the right standard error, then turn it into a p-value and a plain-language conclusion. For two groups, pool the proportions. Check conditions first, and switch to an exact test when counts are small.

Doing this by hand once makes the output of any software easier to judge. When you are ready to run tests on your own datasets, you can try PlotStudio AI free. The trial includes 30 credits and needs no credit card or API key, and you can review the plan and read the generated Python for every test.