Quantitative Analysis/ Compare Percentages
Testing a percentage

How to compare percentages with a z-test for proportions

The z-test for proportions checks whether a percentage differs from a target, or whether two percentages differ from each other. This guide explains the logic, shows how to calculate the statistic by hand, compares it with the t-test, and covers how to run it in AnalyZ Solutions.

13 min read Compare Percentages Beginner to Intermediate

01What is the z-test for proportions?

Survey and study results are often stated as percentages: 62% of respondents are satisfied with a service, 48% of graduates found work within six months, 7% of items failed inspection. A percentage from a sample is an estimate, and it carries sampling uncertainty. The z-test for proportions helps you judge that uncertainty in two situations.

In the first, you compare one observed percentage with a target or reference value. Is 62% really above a 50% threshold, or could a sample of this size produce 62% when the true figure is 50%? In the second, you compare two percentages. Is the 68% in one group really different from the 41% in another?

Both rest on the same idea. If the true percentage in the population were a particular value, repeated samples of the same size would give percentages that scatter around it, and for reasonable sample sizes that scatter follows a bell-shaped normal curve. The test measures how many standard errors your observed result lies from the value being tested. A result far out in the tail would be rare if the null hypothesis were true, so it counts as evidence against it.

The null hypothesis is that the true proportion equals the target, or, in the two-sample version, that both groups share the same proportion.

02How the z statistic is calculated

One proportion against a target

Let n be the sample size, x the number of cases with the outcome of interest, and p₀ the target proportion.

p-hat = x / n
standard error = √( p₀ × (1 - p₀) / n )
z = (p-hat - p₀) / standard error
p-value = 2 × (1 - Φ(|z|))

Here p-hat is the observed proportion, and Φ is the area under the standard normal curve up to a given point. Doubling the upper tail area gives a two-tailed p-value, which counts extreme results in either direction. The standard error uses the target p₀ and not the observed proportion, because the test asks what would happen if the null hypothesis were true. In that situation, the spread of sample percentages is fixed by p₀.

Worked calculation. Suppose 149 of 240 respondents say they are satisfied, and the target is 50%.

  1. Observed proportion
    149 divided by 240 gives 0.6208, or 62.1%.
  2. Standard error
    The square root of (0.5 × 0.5 ÷ 240) is 0.0323.
  3. z statistic
    (0.6208 - 0.5) ÷ 0.0323 gives 3.744. The observed percentage sits almost 3.7 standard errors above the target.
  4. p-value
    The chance of a result at least this far out in either direction is about 0.0002, so the difference is significant at the 0.1% level.
Figure 1. Where the observed z sits on the standard normal curveThe standard normal curve with the outer 5 percent shaded and the observed z value of 3.74 far into the right tail.-4-3-2-101234observed z = 3.742.5% in each tailz = 1.96If the true figure were the target,most samples would give z near 0
Figure 1. Where the observed z sits on the standard normal curve

The shaded areas hold the most extreme 5% of results. A z beyond about 1.96 in either direction is significant at the 5% level, and the observed value of 3.74 is far past that point.

The normal approximation behind the test works well when both n × p₀ and n × (1 - p₀) are at least 10. In this example both equal 120, so the condition is met comfortably.

Two proportions

For two samples, let x₁ out of n₁ and x₂ out of n₂ be the cases with the outcome.

p1-hat = x1 / n1 p2-hat = x2 / n2
pooled p = (x1 + x2) / (n1 + n2)
standard error = √( pooled p × (1 - pooled p) × (1/n1 + 1/n2) )
z = (p1-hat - p2-hat) / standard error

The null hypothesis says both groups share one true proportion, so the best estimate of it combines all the cases. That combined value is the pooled proportion, and it replaces p₀ in the standard error.

Worked calculation. Suppose 136 of 200 urban residents own a smartphone, against 82 of 200 rural residents.

  1. Observed proportions
    136 ÷ 200 = 0.68 and 82 ÷ 200 = 0.41, a difference of 0.27, or 27 percentage points.
  2. Pooled proportion
    (136 + 82) ÷ 400 = 0.545.
  3. Standard error
    The square root of (0.545 × 0.455 × (1/200 + 1/200)) is 0.0498.
  4. z statistic
    0.27 ÷ 0.0498 gives 5.42, and the p-value is below 0.001.

There is a useful link with the chi-square test. Squaring this z gives 29.40, which is the chi-square statistic for the same two-by-two table without a continuity correction. The chi-square test in AnalyZ Solutions applies the correction for two-by-two tables and reports 28.32. The two routes lead to the same conclusion.

A confidence interval for a percentage

The test says whether a difference is likely to be real. An interval shows how precisely the percentage is known.

p-hat ± 1.96 × √( p-hat × (1 - p-hat) / n )

For the one-proportion example, the standard error is √(0.6208 × 0.3792 ÷ 240) = 0.0313, so the interval runs from 0.559 to 0.682. The true share of satisfied respondents is probably between 56% and 68%. This standard error uses the observed proportion, because no null hypothesis is assumed. The AnalyZ Solutions module reports the test result and not this interval, so calculate it by hand if you need it, or state the sample size next to the percentage so readers can judge the precision.

03How the z-test differs from the t-test

Both tests ask the same kind of question: how far is an observed value from a reference value, measured in standard errors? They differ in what is being measured and in where the standard error comes from.

Z-test for proportions compared with the t-test
FeatureZ-test for proportionst-test
OutcomeYes or no, summarised as a percentageNumeric, summarised as an average
What is comparedA percentage with a target, or two percentagesAn average with a target, or two averages
Where the standard error comes fromThe proportion itself, because the variance of a yes or no outcome is p × (1 - p)The sample standard deviation, which has to be estimated from the data
Reference curveStandard normal curveStudent's t curve, which depends on degrees of freedom
Degrees of freedomNonen - 1 for one sample, n₁ + n₂ - 2 for two samples
Condition on sample sizeEnough expected successes and failures, at least 10 of eachA roughly normal outcome, or a reasonably large sample
Natural effect sizeDifference in percentage points, or an odds ratioCohen's d
Related test for more groupsChi-square testANOVA

The key difference is in the spread. For a yes or no outcome, once the proportion is known, the spread is known too. A group in which 62% say yes has a variance fixed at 0.62 × 0.38. For a numeric outcome such as income, the average says nothing about how spread out the values are, so the standard deviation has to be estimated from the data. That extra uncertainty is what the t curve allows for, and it matters most in small samples. A proportion has no such extra step, so the normal curve is used directly.

With large samples the two curves are almost identical, so the tests give similar numbers. For the 240 respondents above, coding satisfied as 1 and not satisfied as 0 and running a one-sample t-test against 0.5 gives t = 3.85, against z = 3.74. Both have a p-value of about 0.0002. The small gap arises because the t-test builds its standard error from the observed spread and the z-test builds it from the target. For percentages, the z-test is the principled choice.

04When to use it

Use the z-test for proportions when:

Choose a different method when your situation changes:

05How to run it in AnalyZ Solutions

Open Inferential Analysis, choose Compare Percentages, then Z-test for Proportion. Choose one of the two modes at the top.

One proportion against a target

  1. Select the variable
    Pick the categorical variable that holds the outcome.
  2. Choose the success value
    Pick the category that counts as a success, such as Yes or Employed. Value labels are shown next to the codes.
  3. Enter the hypothesised proportion
    Type the target as a decimal between 0 and 1, for example 0.5 for 50%.
  4. Click Run
    You receive the result table and a plain-language interpretation.

Two proportions

  1. Select Variable 1 and its success value
    Pick the first outcome variable and the category that counts as a success.
  2. Select Variable 2 and its success value
    Do the same for the second variable.
  3. Click Run
    The output shows both percentages, the difference, and the significance level.

The two-proportion mode compares the share of successes in two separate variables, so it suits data where the two groups occupy separate columns, for example one column of results for one set of sites and another for a second set. If your data has a single outcome column and a separate column that identifies the group, use the chi-square test on the two variables. For a two-by-two table, it answers the same question.

Choose the target before you look at the data. A target taken from a published standard, a national figure, or an earlier study is a fair comparison. A target chosen after seeing your result is not.

06Interpreting the result

The figures below are invented to show the steps, and they follow the results tables in AnalyZ Solutions, with a few columns left out to save space. Suppose 149 of 240 respondents say they are satisfied with a service, and the target is that at least half are satisfied. This example uses the one-proportion mode.

Test result
NSuccessesObserved pHypothesised pzp-valueSig
2401490.62080.53.7439< 0.001***

Reading it step by step

  1. Read the observed percentage
    The observed proportion is 0.6208, which is 62.1%. The target is 0.5, so the sample sits 12.1 percentage points above it.
  2. Check the sample size
    There are 149 successes and 91 failures, both well above 10, so the normal approximation behind the z-test is sound.
  3. Check significance
    The z value of 3.7439 is far from zero and the p-value is below 0.001 with three stars. A sample of 240 would almost never show 62% if the true figure were 50%, so the gap is significant at the 0.1% level.
  4. Judge whether the gap matters
    Twelve points is a clear margin on a percentage, and it is the number to report because everyone can read it. The test itself does not give a confidence interval, so say how many people were surveyed next to the percentage.

In plain words

About 62% of the 240 respondents were satisfied with the service, above the 50% target. The gap is significant at the 0.1% level. In two-proportion mode, the reading works the same way: report the difference in percentage points from the Diff column, and use the z value and p-value to say whether it is real.

07Common mistakes

Ignoring the sample size. A percentage from 20 respondents is far less certain than one from 2,000, even when the number looks the same.

Comparing overlapping groups. The two-proportion test assumes the two samples are separate. Using it on two questions answered by the same respondents violates this.

Ignoring clustering. If respondents were sampled in schools or workplaces, the test understates the uncertainty.

Reporting the z statistic instead of the difference. Readers understand percentage points far better than z values.

Treating a significant result as an important one. A one-point gap can be significant in a very large sample. Judge the size of the difference as well as its significance.

Frequently Asked Questions
How is this different from the chi-square test?
For two percentages from two groups, the two tests answer the same question. Squaring the z statistic gives the chi-square statistic without continuity correction, so the conclusions agree. The z-test also handles a single percentage against a target, which the chi-square test does not.
How is it different from the t-test?
The t-test compares averages of a numeric outcome and estimates the spread from the data. The z-test compares percentages of a yes or no outcome, where the spread follows directly from the percentage itself. That is why the z-test uses the normal curve with no degrees of freedom.
Can I run a t-test on yes or no data coded as 0 and 1?
You can, and with large samples the answer is close to the z-test, but it is not the right tool. The t-test builds its standard error from the observed spread, while the z-test builds it from the target value or the pooled proportion. The z-test is the standard choice for proportions.
How big does my sample need to be?
The normal approximation works well when you expect at least 10 successes and 10 failures under the tested value. With a target of 50% that means a sample of about 20, but for targets near 0% or 100% you need much more.
Can I test against a target of 0 or 1?
Not meaningfully. At those extremes the standard error is zero and the z statistic cannot be calculated. Choose a target between 0 and 1.
Does the test give a confidence interval?
No. The module reports the observed percentage, the target, the z statistic, and the significance level. The article shows how to calculate an interval by hand, and you should state the sample size next to the percentage so readers can judge how precise it is.
Should I use a one-tailed or two-tailed test?
The z-test in AnalyZ Solutions is two-tailed, which detects a difference in either direction. This is the more defensible choice for most reports.

Test a percentage in your data

Open Compare Percentages in AnalyZ Solutions. Free to sign up, free to analyze.

Get started
Related Guides