Chalk−1

Math · Introductory statistics · Concept

Hypothesis testing: t-tests and p-values

A hypothesis test asks whether data are consistent with a claim. The null hypothesis H0 states the claim, such as μ=500, and the alternative Ha states what you suspect instead. The t statistic counts how many standard errors the sample mean lies from the claim. The p-value is the probability of a result at least that extreme if H0 were true, and a small p-value is evidence against H0.

Try one — Chalk checks each line

A concrete case

Is this coin fair?

A friend hands you a coin and says it is fair. You flip it 20 times and get 16 heads. Is the coin unfair, or did you see a lucky run?

Start by taking your friend at their word. If the coin is fair, the number of heads follows a binomial distribution with n=20 and p=0.5. The chance of 16 or more heads is then 6,196 out of 220=1,048,576, about 0.0059. Four or fewer heads is just as unlikely, so a result at least this lopsided in either direction has probability about 0.012.

That is about 1 chance in 85. Either something rare happened, or the coin is not fair, and most people would doubt the coin. Assuming the claim and asking how surprising the data would be is a hypothesis test, and 0.012 is its p-value.

2⋅61961048576≈0.012

The rule

Two hypotheses

A test starts with two competing claims about a population, here about its mean μ. The null hypothesis H0 is the claim being tested, usually the skeptical position of no change or no effect. It is written with an equals sign, μ=μ0, where μ0 is the claimed value.

The alternative hypothesis Ha is what you suspect instead. It is two-sided, μ≠μ0, unless only one direction mattered before any data were seen. Then it is one-sided, μ<μ0 or μ>μ0.

The hypotheses are about μ, the mean of the whole population, which is unknown. They are never about x¯, which you already know.

H0: μ=μ0,Ha: μ≠μ0
H0: μ=μ0Ha: μ≠μ0

The t statistic

The test statistic counts how far the sample mean x¯ lies from the claimed mean μ0, in standard errors. The standard error s⁢/n uses the sample standard deviation s and the sample size n. A t of −2.33 says the sample mean sits 2.33 standard errors below the claim. If H0 is true and the conditions hold, t follows a t distribution with n−1 degrees of freedom.

t=x¯−μ0s⁢/n

The p-value

The p-value is the probability, computed as if H0 were true, of a t at least as extreme as the one observed, in the direction of Ha. For Ha: μ<μ0 it is the area to the left of t, and for Ha: μ>μ0 the area to the right. A two-sided test counts both tails, so its p-value is twice the area beyond ∣⁢t⁢∣. Software gives it directly, and a t table brackets it between two columns.

p=2P⁢(T≥∣⁢t⁢∣)

The decision

Choose a significance level α before looking at the data, usually 0.05. If p≤α, reject H0. Data like these would be unusual if H0 were true, and they support Ha. If p>α, fail to reject H0. The data are consistent with H0, which is not the same as showing that H0 is true. Either way, state the conclusion as a sentence about the mean, in the problem’s units.

Two ways to be wrong

A test can reach the wrong decision in two ways. A Type 1 error rejects a true H0, a false alarm. When H0 is true, it happens with probability α. A Type 2 error fails to reject a false H0, a missed effect. It is more likely with a small sample or a small true difference.

A trial works the same way. The defendant is presumed innocent, which is H0, and convicting an innocent person is a Type 1 error. Demanding stronger evidence convicts fewer innocent people and lets more guilty ones go. Lowering α trades errors the same way.

The four outcomes of a test
TruthDo not reject H0Reject H0
H0 trueCorrectType 1 error
Ha trueType 2 errorCorrect

Why it works

Why a small p-value counts against H0

The argument works like a proof by contradiction, with probability in place of certainty. Assume H0 is true. Then x¯ varies around μ0 from sample to sample, and t follows a t distribution centered at 0. Values of t near 0 are common, and values far out in the tails are rare. A small p-value says the observed t landed where samples from a true H0 seldom land.

The cutoff α controls the false alarms. Suppose H0 is true and you reject whenever p≤0.05. When the conditions hold, a t that far out happens in 5⁢% of samples, so 5⁢% of such tests reject a true H0. That is why α is the Type 1 error rate.

The test and the confidence interval are one calculation read two ways. A two-sided test at α=0.05 rejects when ∣⁢t⁢∣>t∗, where t∗ is the critical value of a 95⁢% interval. Multiply both sides by the standard error. The test rejects exactly when μ0 is more than t∗⋅SE from x¯, which means μ0 lies outside x¯±t∗⋅SE.

∣⁢t⁢∣>t∗∣x¯−μ0∣>t∗⋅S⁢E

The method

A t-test in four steps

Every test in this course runs the same four steps. The table runs them for the bottle-filling machine in the first worked example. The last step is a sentence about the mean, never only “reject H0”.

A two-sided t-test of the mean fill
StepWhat to doFor the bottles
1Prepare. State H0, Ha and α, and write down x¯, s and n.H0: μ=500, Ha: μ≠500, α=0.05. x¯ =497.2, s=6, n=25.
2Check the conditions.Random bottles, measured independently, fills roughly normal.
3Calculate SE, t, the degrees of freedom and the p-value.SE =6⁢/25 =1.2, t =(497.2−500)⁢/1.2 ≈−2.33, 24 df, p ≈0.028.
4Conclude in context.0.028 ≤0.05, so reject H0. The data give convincing evidence that the mean fill is below 500 mL.

Reading a p-value from a t table

A t table lists critical values, not p-values, so it brackets p between two columns. For the bottles, ∣⁢t⁢∣=2.33 with 24 degrees of freedom. The table’s row for 24 gives 2.064 under a two-tailed area of 0.05 and 2.492 under 0.02. 2.33 lies between them, so p is between 0.02 and 0.05. Software, or the Distributions panel in Statistics, gives the value itself, 0.0283.

Where it breaks

Where it breaks

The t-test needs a random sample of independent observations and a sample mean close to normal. With fewer than 30 observations there should be no clear outliers, and with 30 or more no extreme ones. No test rescues a biased sample.

The p-value is not the probability that H0 is true. It is computed by assuming H0 is true, so it cannot also measure how likely H0 is. For the bottles, p=0.028 says data this extreme would turn up in about 2.8⁢% of samples if the mean were 500 mL.

Failing to reject is not accepting. Eight students sleeping an average of 6 hours, with s=2, gave a one-sided p≈0.10 against a claimed mean of 7. The same mean and spread from 32 students gives a one-sided p≈0.004. The small sample could not tell, and it never showed that the mean is 7.

Significant does not mean large. With 10,000 people, an average blood-pressure drop of 0.4 mmHg can give p below 0.0001. Report the estimate and a confidence interval beside the decision, so a reader can judge the size.

A one-sided alternative chosen after looking at the data halves the p-value for free. Choose the direction before the data, or test two-sided.

Run 20 tests of true null hypotheses at α=0.05, and about one will reject by chance. A result picked out of many tests needs a smaller α or a fresh sample.

Check your answer

Check your answer

A t and its p-value should agree with each other and with the interval, before you trust either.

The sign of t matches the data. x¯ below μ0 gives a negative t, and x¯ above gives a positive one. In a one-sided test, a t on the wrong side of 0 gives a p-value above 0.5.

The size of p matches the size of t. With 20 or more degrees of freedom, ∣⁢t⁢∣ near 2 gives a two-sided p near 0.05, and a larger ∣⁢t⁢∣ gives a smaller p. A ∣⁢t⁢∣ below 1 gives a two-sided p above 0.3, whatever the degrees of freedom.

The interval agrees. A two-sided test at α=0.05 rejects exactly when μ0 lies outside the 95⁢% t interval. For the bottles, 494.72 to 499.68 mL leaves out 500, and the test rejects.

To have Chalk check the work, put the givens on the first row of a Math box, as x¯=497.2, s=6, n=25. Write SE=s⁢/n=6⁢/25=1.2 on the next row, and the Checker marks it ✓, or ✗ when a number is wrong. Then write t=(497.2−500)⁢/1.2 ≈−2.33. With x¯, s and n on the givens row and SE just above, the row reads ✓ “Correct: t = (x̄ − μ₀)/SE, to the digits shown.” and a wrong value reads ✗.

The claimed mean can go on the givens row too, as x¯=497.2, s=6, n=25, μ0=500. With it there, dividing by s instead of the standard error, t=(497.2−500)⁢/6 ≈−0.47, reads ✗. Without μ0 in the box, that row reads ?, because Chalk can’t tell which number is the claimed mean, so check that the bottom of t is s⁢/n. Chalk does not compute the p-value either, so read it from Statistics and give the decision in words.

A two-sided t-test gives p=0.03. From the same data, does the 95⁢% interval contain μ0? Does the 99⁢% interval?

The 95⁢% interval leaves μ0 out, and the 99⁢% interval contains it. A two-sided test rejects at level α exactly when μ0 lies outside the interval with confidence 1−α. p=0.03 is below 0.05, so the test rejects at that level. It is above 0.01, so it does not reject there, and the wider 99⁢% interval reaches μ0.

Power, many tests and other tests

The chance that a test catches a real difference is its power, 1 minus the Type 2 error rate. Power grows with the sample size and with the size of the true difference, and it falls as α shrinks. A careful study chooses n large enough to give power of about 80⁢% for the smallest difference that would matter.

When H0 is true and the conditions hold exactly, the p-value is equally likely to fall anywhere between 0 and 1. That is why a cutoff of 0.05 gives false alarms in 5⁢% of tests, and why 20 such tests give about one. The Bonferroni correction divides α among the tests, testing each of 20 at 0.0025.

The t-test is one member of a large family. The same logic, a statistic measured against its distribution under H0, gives tests for proportions, for the difference between two groups and for counts in categories. A permutation test even builds the distribution under H0 by shuffling the data, with no normal model at all.

Common mistakes

  • Reading p=0.028 as a 2.8⁢% chance that H0 is true. The p-value assumes H0 is true, so it is the chance of data this extreme under H0, not the chance of H0 itself.
  • Concluding that students sleep 7 hours on average because p=0.10 is above 0.05. Failing to reject is not accepting. With only eight students, the test could easily miss a real shortfall.
  • Choosing Ha: μ<500 after seeing x¯=497.2. The direction must be set before the data. Picking it afterward halves the p-value and doubles the rate of false alarms.
  • Reporting the one-tail area 0.0142 for the two-sided bottle test. A two-sided p-value counts both tails, so it is 2×0.0142≈0.028.
  • Dividing by s instead of the standard error. (52.3−50)⁢/6.4≈0.36 understates the evidence. The mean varies by s⁢/n=1.6, so t=2.3⁢/1.6≈1.44.
  • Writing the hypotheses about x¯, as H0: x¯=500. The sample mean is already known to be 497.2. Hypotheses are claims about the unknown population mean, H0: μ=500.

Key terms

Hypothesis test
A way to check whether data are consistent with a null hypothesis: compute a test statistic and ask how surprising it would be if the null were true. A test can give evidence against the null, but it never proves the alternative.
Null hypothesis
H0, the claim a test assumes so it can compute probabilities, usually “no effect” or a specific value such as μ=50. Failing to reject it doesn’t prove it true.
Alternative hypothesis
Ha, the claim you are looking for evidence of, such as μ>50 (one-sided) or μ≠50 (two-sided). Choose it from the question before looking at the results.
p-value
The probability, assuming the null hypothesis is true, of a result at least as extreme as the one observed. A small p-value is evidence against the null. It is not the probability that the null is true.
Significance level
α, the cutoff chosen before a test, often 0.05. Reject the null hypothesis if the p-value is at or below it. It is the chance, when the null hypothesis is true, of rejecting it.
t-test
A test about a mean, or a difference in means, that uses the t distribution. A paired test works on the differences within pairs. Welch’s two-sample test doesn’t assume equal variances.
Student t distribution
A bell-shaped distribution like the standard normal but with heavier tails, used when the population standard deviation is estimated from the sample. With more degrees of freedom it gets closer to the normal.
Degrees of freedom
The number of values free to vary once estimates have been fixed, such as n−1 for one sample’s standard deviation. It sets the shape of the t, chi-square and F distributions.

Work through an example

A filling machine should put 500 mL in each bottle. A random sample of 25 bottles has mean 497.2 mL and standard deviation 6 mL. Test H0: μ=500 against Ha: μ≠500 at α=0.05.

Run a one-sample t-test →

Run a one-sided t-test from raw data →

Interpret a p-value correctly →

Sources and scope

Authored study material. Tool results depend on the stated inputs and model assumptions.

After reading

Try it, then study it

Open the example in its tool to check steps or change values, then review the key terms as flashcards.

Find the p-value in Statistics Check t in Math See α=0.05 as the intervals that miss μ in Confidence-Interval Coverage Study the 8 key terms Open worked example on a board Confidence interval in Math Reference

Your existing work stays on this device. Examples open as editable copies.