TExcelTAD
Home › Statistics › Testing a Proportion (Two-Tailed)

Testing a Proportion (Two-Tailed)

A two-tailed test looks for evidence that the true proportion is different from p₀ in either direction. Use it when a deviation in both directions would be interesting, or when you have no prior reason to expect one direction. It is the default choice in most scientific work.

The scenario

About 10% of people are left-handed. A sports scientist suspects the share of left-handers among competitive table-tennis players differs from the general population (it could be higher, since left-handers may have a tactical advantage, or lower, if equipment and coaching favour right-handers). In a random sample of 1,200 registered players, 141 are left-handed.

Step 1–3: Hypotheses, α and conditions

text
H₀: p = 0.10
H₁: p ≠ 0.10     ← two-tailed
α = 0.05
python · try it yourself
n, p0 = 1200, 0.10
print("n*p0 =", round(n * p0), " n*(1-p0) =", round(n * (1 - p0)))
n*p0 = 120  n*(1-p0) = 1080

Step 4: Test statistic

The statistic is the same as for one-tailed tests:

python · try it yourself
import math

x, n, p0 = 141, 1200, 0.10
p_hat = x / n
z = (p_hat - p0) / math.sqrt(p0 * (1 - p0) / n)
print(f"p-hat = {p_hat:.4f},  z = {z:.3f}")
p-hat = 0.1175,  z = 2.021

Step 5: p-value, both tails

In a two-tailed test, a result as extreme in the other direction would count just as much. So the p-value adds both tails, which by symmetry is twice the tail beyond |z|:

text
p-value = 2 × P(Z ≥ |z|)

The critical values split α between the tails: ±z_(α/2), i.e. ±1.96 for α = 0.05.

python · try it yourself
from scipy import stats

z = 2.0207
p_value = 2 * stats.norm.sf(abs(z))
z_crit = stats.norm.ppf(1 - 0.05 / 2)
print(f"p-value = {p_value:.4f}")
print(f"critical values = ±{z_crit:.3f}")
p-value = 0.0433
critical values = ±1.960
python · try it yourself
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

z_obs, z_crit = 2.0207, stats.norm.ppf(0.975)
x = np.linspace(-4, 4, 400)
fig, ax = plt.subplots(figsize=(6.5, 3))
ax.plot(x, stats.norm.pdf(x), color="#2a78d6", linewidth=2)
for tail in (x <= -z_crit, x >= z_crit):
    ax.fill_between(x[tail], stats.norm.pdf(x[tail]), color="#eb6834", alpha=0.5)
ax.axvline(z_obs, color="#0b0b0b", linestyle="--")
ax.set_title("2.5% rejection region in each tail")
ax.set_yticks([])
plt.tight_layout()
plt.show()
print(f"observed z = {z_obs} lies just beyond +{z_crit:.3f}")
observed z = 2.0207 lies just beyond +1.960

Step 6: Conclusion

p ≈ 0.043 < 0.05, so we reject H₀ at the 5% level.

In context: the data provide evidence that the share of left-handers among competitive table-tennis players differs from 10%; the estimate is 11.75%.

The evidence is modest: at α = 0.01 we would not reject. And had the researcher run a right-tailed test, the p-value would have been half as large (about 0.022). That is exactly why the direction must be chosen before seeing the data: picking the tail afterwards would secretly double your Type I error rate for one-sided "discoveries".

Two-tailed tests and confidence intervals

A two-tailed test at level α and a (1 − α) confidence interval are two views of the same information: the test rejects H₀: p = p₀ when p₀ falls outside the interval of plausible values. For proportions there is a catch, though. The z-test computes its standard error from p₀, while the simple Wald interval uses p̂, so near the boundary they can disagree. The Wilson interval is built from the same formula as the z-test, so it always agrees with it:

python · try it yourself
from statsmodels.stats.proportion import proportion_confint

x, n = 141, 1200
for conf in [0.95, 0.99]:
    for method in ["normal", "wilson"]:
        lo, hi = proportion_confint(x, n, alpha=1 - conf, method=method)
        print(f"{conf:.0%} {method:6s} CI: ({lo:.4f}, {hi:.4f})  contains 0.10? {lo <= 0.10 <= hi}")
95% normal CI: (0.0993, 0.1357)  contains 0.10? True
95% wilson CI: (0.1005, 0.1370)  contains 0.10? False
99% normal CI: (0.0936, 0.1414)  contains 0.10? True
99% wilson CI: (0.0956, 0.1436)  contains 0.10? True

Our case sits right on that boundary. The 95% Wald interval just barely includes 0.10, while the 95% Wilson interval excludes it, matching the rejection at α = 0.05. At 99%, both intervals include 0.10, matching the non-rejection at α = 0.01. When a result is this borderline, the choice of method can flip the verdict, which is one more reason not to treat 0.05 as a magic line.

In one call

python · try it yourself
from scipy import stats
from statsmodels.stats.proportion import proportions_ztest

z, p = proportions_ztest(141, 1200, value=0.10, alternative="two-sided", prop_var=0.10)
print(f"z-test: z = {z:.3f}, p = {p:.4f}")
print(f"exact binomial test: p = {stats.binomtest(141, 1200, 0.10).pvalue:.4f}")
z-test: z = 2.021, p = 0.0433
exact binomial test: p = 0.0483

Here the exact test gives a slightly larger p-value than the normal approximation, though both stay below 0.05. With results this close to the threshold, report the exact p-value and avoid overstating the evidence.

Test yourself

A two-tailed z-test gives z = −2.3. What is the p-value?

  1. P(Z ≤ −2.3) ≈ 0.011
  2. 2 × P(Z ≥ 2.3) ≈ 0.021
  3. P(Z ≥ −2.3) ≈ 0.989
  4. 0.023

What are the critical values of a two-tailed z-test at α = 0.05?

  1. ±1.645
  2. ±1.96
  3. ±2.576
  4. 1.96 only

Why is it wrong to choose a one-tailed test after seeing which direction the data went?

  1. One-tailed tests are always wrong
  2. It halves the p-value after the fact and inflates the real Type I error rate
  3. It makes the sample smaller
  4. The data would change