Unit 6, lesson 41

Hypothesis Tests and P-Values

How a hypothesis test compares data with a null model, what the null and alternative hypotheses, test statistic, null distribution and p-value are, and why the tail rule and significance level are fixed in advance.

  • Video 41
  • The Logic of Hypothesis Tests

A new procedure succeeds in 16 of 20 trials, and the established benchmark success rate is 0.5. Is that convincing evidence of an improvement, or the kind of count a process with rate 0.5 produces fairly often? A hypothesis test answers a precise version of the second question. It asks how unusual the observed result would be if the benchmark model were true, using a rule chosen before the data are seen. This lesson builds that rule, computes the p-value for the example, and separates what a p-value says from what it is often taken to say.

Key terms

Null and alternative hypotheses

Definition A hypothesis test concerns a parameter of a probability model for the data, such as a long-run success probability pp. The null hypothesis H0H_0 states that the parameter equals a given value or lies in a given set, and every probability in the test is computed as if it were true. The alternative hypothesis H1H_1 states the parameter values the investigation is looking for evidence of, and it shares no values with H0H_0. The null model consists of H0H_0 together with the assumptions of the model, such as independent trials that share one success probability.

In plain words The null is the benchmark or skeptical position, and the test looks for evidence against it. The alternative is the departure the question is about. A test either rejects the null or fails to reject it, and failing to reject does not show that the null is true.

Example With pp the new procedure’s long-run success probability and the question whether it beats the benchmark,

H0 ⁣:p=0.5,H1 ⁣:p>0.5.\begin{gathered} H_0\colon p = 0.5, \\[0.4em] H_1\colon p > 0.5. \end{gathered}

The hypotheses are about pp, not about the observed proportion 16/20=0.816/20 = 0.8, which is known exactly once the data are in. If the null is written as p≤0.5p \le 0.5 instead, the calculations below are done at p=0.5p = 0.5, because among the null values that boundary value makes large counts most likely, which gives the largest tail probability.

Test statistic and null distribution

Definition A test statistic is a number computed from the data, together with a rule saying which of its values count as more extreme, meaning further in the direction of H1H_1. Its null distribution is the probability distribution of the test statistic when H0H_0 and the model assumptions hold.

In plain words The test statistic condenses the data into one number that bears on the question. The null distribution says which values of that number a true null would produce, and how often. It comes from the null model, so it is not moved to match the data.

Example Let XX be the number of successes in n=20n = 20 trials. If the trials are independent and each succeeds with probability 0.50.5, then X∼Binomial⁡(20,0.5)X \sim \operatorname{Binomial}(20, 0.5) and

P(X=k)=(20k)2−20P(X = k) = \binom{20}{k} 2^{-20}

for k=0,1,…,20k = 0, 1, \dots, 20. This null distribution has mean 1010. Large counts point toward p>0.5p > 0.5, so here more extreme means larger. The observed value 1616 is compared with this distribution centered at 1010, not with a distribution built from the observed rate 0.80.8, which would be centered at 1616. The independence and common probability assumptions are part of the model and are not checked by the count itself.

P-value

Definition Suppose larger values of a test statistic TT count as more extreme and the observed value is tt. The p-value is

PH0(T≥t),P_{H_0}(T \ge t),

where the subscript means the probability is computed under the null model. In general the p-value is the probability, computed under the null model, that the test statistic is at least as extreme as the observed value according to the extremeness rule chosen in advance. When H0H_0 contains several parameter values, the p-value is the largest of these probabilities over the values in H0H_0, or their supremum when no largest one exists. Defined this way, for every α\alpha with 0<α<10 < \alpha < 1, a true null produces a p-value at most α\alpha with probability at most α\alpha.

In plain words A small p-value says that data at least this extreme would be unusual if the null model were correct. It is a probability about data, computed by assuming the null. It is not the probability that H0H_0 is true, not the probability that the result is a fluke, and not a measure of how large the effect is. A p-value can be as large as 11. In the example, a count of 00 has p-value P(X≥0)=1P(X \ge 0) = 1.

Example For 1616 successes and H1 ⁣:p>0.5H_1\colon p > 0.5, the outcomes at least as extreme are the counts 1616 through 2020, so

P(X≥16)=∑k=1620(20k)2−20=61961048576≈0.00591.\begin{aligned} &P(X \ge 16) \\[0.4em] &\quad = \sum_{k=16}^{20} \binom{20}{k} 2^{-20} \\[0.4em] &\quad = \frac{6196}{1048576} \\[0.4em] &\quad \approx 0.00591 . \end{aligned}

If the benchmark model were correct, about 0.59 percent of repeated sets of 20 trials would give 16 or more successes. That is evidence against the benchmark model. The probability that p=0.5p = 0.5 given these data is a different quantity, and computing it would need a prior distribution for pp that gives the value 0.50.5 itself positive probability, as in Bayesian methods.

One-sided and two-sided tests

Definition A test of H0 ⁣:p=p0H_0\colon p = p_0 is one-sided when H1H_1 lies on one side of p0p_0, as in p>p0p > p_0 or p<p0p < p_0, so that only departures in that direction count as extreme. It is two-sided when H1H_1 is p≠p0p \ne p_0, so that departures in both directions count. A two-sided test must also say how departures in the two directions are compared. Common rules order the outcomes by distance from the null mean, double the smaller one-sided p-value and cap the result at 11, or order the outcomes by their null probability. For a discrete null distribution that is not symmetric these rules can give different p-values.

In plain words The direction comes from the research question, not from the data. A one-sided test ignores departures in the other direction, so a sharp drop in the success rate would give a large p-value in a test that looks only for an increase. A two-sided test watches both directions.

Example If the question were whether the rate differs from 0.50.5 in either direction, then H1 ⁣:p≠0.5H_1\colon p \ne 0.5. Ordering outcomes by distance from the null mean 1010, the observed 1616 is 66 away, so the counts at most 44 and at least 1616 are at least as extreme. The null distribution is symmetric about 1010, so the two tails are equal and

P(∣X−10∣≥6)=2⋅61961048576≈0.0118.\begin{aligned} &P(\lvert X - 10 \rvert \ge 6) \\[0.4em] &\quad = 2 \cdot \frac{6196}{1048576} \\[0.4em] &\quad \approx 0.0118 . \end{aligned}

Doubling is not automatic. For X∼Binomial⁡(10,0.3)X \sim \operatorname{Binomial}(10, 0.3) and an observed 66, ordering by distance from the mean 33 gives about 0.07560.0756, while doubling the upper tail P(X≥6)≈0.0473P(X \ge 6) \approx 0.0473 gives about 0.09470.0947.

Significance level

Definition The significance level α\alpha, with 0<α<10 < \alpha < 1, is chosen before the data are examined. The test rejects H0H_0 when the p-value is at most α\alpha, and the result is then called statistically significant at level α\alpha. Since a true null gives a p-value at most α\alpha with probability at most α\alpha, the probability that the test rejects a true null is at most α\alpha under the model. For a discrete test statistic that probability can be strictly less than α\alpha.

In plain words The level is the rate of false alarms the analyst accepts when the null is true, fixed before looking. A significant result is evidence against the null model, not proof of H1H_1, and by itself it says nothing about whether the effect is large enough to matter. A result that is not significant has not shown that the null is true.

Example At α=0.05\alpha = 0.05 the one-sided p-value 0.005910.00591 and the two-sided p-value 0.01180.0118 are both at most 0.050.05, so each test, planned in advance, rejects H0H_0. The upper-tail test rejects exactly when X≥15X \ge 15, because P(X≥15)≈0.0207P(X \ge 15) \approx 0.0207 is at most 0.050.05 while P(X≥14)≈0.0577P(X \ge 14) \approx 0.0577 is not. Its actual probability of rejecting a true null is therefore about 0.02070.0207, below the nominal 0.050.05, because the attainable tail probabilities of a count jump in steps.

Pre-specification

Definition Pre-specification means fixing the hypotheses, the test statistic, the extremeness rule (including whether the test is one-sided or two-sided), the significance level and the sample size or stopping rule before the outcome data are examined. The error rate a test claims holds for the procedure as specified. Choices that depend on the observed outcomes define a different procedure, whose error rate has to be worked out for that procedure, or else the analysis needs a method that accounts for the selection.

In plain words If the data are used first to pick a favorable test and then to evaluate it, the same evidence is counted twice. A plan written down in advance keeps the stated error rate true.

Example Suppose a test statistic ZZ has a standard normal distribution under H0H_0. An analyst who looks at the sign of ZZ, picks the matching one-sided test and rejects when its p-value is at most 0.050.05 is really using the rule that rejects when ∣Z∣≥z0.95\lvert Z \rvert \ge z_{0.95}, where z0.95≈1.645z_{0.95} \approx 1.645 is the 0.950.95 quantile of the standard normal distribution. Under H0H_0 that happens with probability 2×0.05=0.102 \times 0.05 = 0.10, twice the stated level.

Check yourself

  1. A checkout page completes 30 percent of visits under the old design. A team wants to know whether a redesign changes the completion rate in either direction. State the hypotheses and say whether the test is one-sided or two-sided. What would change if the team cared only about an improvement?
Show the answer

Let pp be the long-run completion probability under the redesign. The hypotheses are H0 ⁣:p=0.3H_0\colon p = 0.3 and H1 ⁣:p≠0.3H_1\colon p \ne 0.3, and the test is two-sided because a change in either direction matters. If only an improvement mattered, the alternative would be H1 ⁣:p>0.3H_1\colon p > 0.3 and the test would be one-sided. That choice has to be made before the data are examined.

  1. In the benchmark study, with H0 ⁣:p=0.5H_0\colon p = 0.5 and H1 ⁣:p>0.5H_1\colon p > 0.5, suppose the 20 trials give 12 successes instead. Find the p-value and the decision at α=0.05\alpha = 0.05. Does the result show that p=0.5p = 0.5?
Show the answer

The outcomes at least as extreme are the counts 1212 through 2020. Their binomial coefficients add to 263950263950, so

P(X≥12)=2639501048576≈0.252.\begin{aligned} P(X \ge 12) &= \frac{263950}{1048576} \\[0.4em] &\approx 0.252 . \end{aligned}

This is larger than 0.050.05, so the test fails to reject H0H_0. That does not show p=0.5p = 0.5. Counts of 12 or more occur about a quarter of the time under the null, and 12 is also exactly the expected count if pp were 0.60.6. A count of 12 in 20 trials does not separate these values, and an interval estimate for pp shows which values remain plausible.

  1. A researcher wants to know whether a success rate differs from 0.50.5 in either direction. In 30 independent trials she sees 20 successes, then reports the upper-tail p-value P(X≥20)≈0.0494P(X \ge 20) \approx 0.0494 for X∼Binomial⁡(30,0.5)X \sim \operatorname{Binomial}(30, 0.5) and calls the result significant at 0.050.05. What went wrong, and what should she report?
Show the answer

Her question was two-sided, and she chose the upper tail after seeing an increase. The planned two-sided test, ordering by distance from the null mean 1515, counts outcomes at most 1010 or at least 2020 as extreme. By symmetry its p-value is twice the upper tail, about 0.09870.0987, which is above 0.050.05, so the result is not significant at that level. Picking the favorable tail after looking amounts to rejecting when X≥20X \ge 20 or X≤10X \le 10, and a true null produces such a count with probability about 0.09870.0987, roughly twice the level she claimed. She should report the 20 successes in 30 trials, the binomial assumptions, the estimate 20/30≈0.66720/30 \approx 0.667, the two-sided p-value of about 0.0990.099, and the fact that the test was two-sided by design.

How this lesson connects