Skip to content

t-tests

With a spread estimated from a small sample, the standardised mean has heavier tails than the bell, and pairing data can beat adding data.

Helps to know firstp-values

Helps to know first
This topic

First, the picture

With few data, the mean over its estimated spread does not follow the bell. Watch its curve’s tails shrink as the sample grows.

Small samples, heavier tails

The t curve against the standard bell, and how much of each lies beyond ±2.

1 degree of freedom: 0.2952 of the t curve lies beyond ±2, against 0.0455 for the bell. Its tails are so heavy that the 95 % critical value is 12.71.

degrees of freedom
1
t beyond ±2
0.2952
bell beyond ±2
0.0455
95 % critical value
12.71
0.00 / 12.40 s
Describe this picture

One axis from −6 to 6 with two curves: the standard bell, dashed, and the t curve for a given number of degrees of freedom, solid and labelled with them. The area of the t curve beyond −2 and 2 is shaded, and a readout gives it, beside the bell’s 0.0455 and the 95 % critical value. In the clip, over 8 seconds, the degrees of freedom step through 1, 2, 3, 5, 10 and 30, each change a short morph: the t curve starts as a low hump with wide tails and closes onto the bell. The shaded share reads 0.2952, 0.1835, 0.1393, 0.1019, 0.0734 and 0.0546, against 0.0455 for the bell, and the critical value falls from 12.71 to 2.04. Then the curve returns to 2 degrees of freedom, where the slider starts. After the clip a slider, “Degrees of freedom”, sets them from 1 to 30.

The t law

In Confidence intervals, putting the sample standard deviation in place of the true one forced a wider edge than 1.96. Here is the curve behind that.

Draw nn values from a bell with mean μ0\mu_0, and form

T=Xˉ−μ0S/n,T=\frac{\bar X-\mu_0}{S/\sqrt n},

with SS the sample standard deviation, the random version of ss. Here SS is the spread of the draws, not the sample space of What probability measures. For bell-shaped data, TT follows the t law with n−1n-1 degrees of freedom, written tn−1\mathrm{t}_{n-1}. Its curve is a bell with heavier tails. With 2 degrees of freedom, 18.35 % of its area lies beyond ±2\pm2; the bell has only 4.55 % there. As the sample grows the t curve closes onto the bell.

The 95 % edge, t0.975, n−1t_{0.975,\,n-1}, falls with the degrees of freedom, from 12.71 at 1 to 1.96 in the limit.

Why the tails are heavier

The bottom of TT is random too. When a small sample happens to bunch together, its SS is small, and dividing by a small number throws TT far out.

Why the tails are heavier

5000 samples of 3 from a bell, each turned into T = mean/(s/√3) (seed 8300).

Draw 3 values from a bell with mean 0. Divide their mean by its estimated standard error, s/√3: that is T.

samples
0
beyond ±2
0
share
–

Predict first. How often will T land beyond ±2?

0.00 / 12.80 s
Describe this picture

Three panels that stay apart. The first, “the population”, is a bell. The second, “one sample”, shows 3 values drawn from it as dots, with a line at their mean and a bar for their spread ss. The third, “the statistic T”, is a histogram of the values of TT (seed 8300) on an axis from −6 to 6, with the bell, dashed, and the t curve for 2 degrees of freedom drawn over it; the stretches beyond ±2 are lightly shaded. Before the clip a question asks how often TT lands beyond ±2\pm2: about 5 %, about 18 %, or about 30 %. A tap picks one and starts the clip. In the clip ten samples are drawn one by one, each dropping its TT into the histogram, then the other 4990 pour in; samples whose three values bunch together have a small ss and send TT far out, like the seventh, T=7.11T=7.11. Readouts count the samples and the values beyond ±2\pm2: 902 of 5000, 18.0 %. There is no control after the clip.

Before the clip you guessed. About 18 % of the values land beyond ±2\pm2, as the t curve says, not 5 % as the bell would. Of 5000, expect about 918; the clip’s run gave 902.

Watch out

The mean over its estimated standard error is close to a standard bell only for large samples. For small ones, use the t curve: the bell’s 1.96 gives intervals that are too narrow and tests that cry wolf too often.

The one-sample test

To test whether a mean is μ0\mu_0, compute tobs=(xˉ−μ0)/(s/n)t_\text{obs}=(\bar x-\mu_0)/(s/\sqrt n) and read the two-sided pvalp_\text{val} from the t law with n−1n-1 degrees of freedom.

The eight response times of Describing data have xˉ=16.25\bar x=16.25 ms and s=2.9155s=2.9155 ms. Is their mean 15 ms, the target? The standard error is 1.03081.0308, so tobs=1.25/1.0308=1.2127t_\text{obs}=1.25/1.0308=1.2127 with 7 degrees of freedom, and pval=0.26p_\text{val}=0.26: too little evidence to reject 15.

The 95 % interval of Confidence intervals for the same data, 13.81 to 18.69 ms, contains 15. That is the same statement. A 95 % interval holds exactly the values that a two-sided 5 % test would not reject.

Two samples

The two page layouts of p-values gave old times 10, 11, 12, 16 and new times 14, 15, 17, 19. Their means are 12.25 and 16.25, and their sample variances 6.91676.9167 and 4.91674.9167.

Pooled. If both groups share one spread, combine their variances, weighted by their degrees of freedom: sp2=(3×6.9167+3×4.9167)/6=5.9167s_\text{p}^2=(3\times6.9167+3\times4.9167)/6=5.9167. The standard error of the difference is sp1/4+1/4=1.7200s_\text{p}\sqrt{1/4+1/4}=1.7200, so tobs=4.0/1.7200=2.3256t_\text{obs}=4.0/1.7200=2.3256 with 4+4−2=64+4-2=6 degrees of freedom, and two-sided pval=0.059p_\text{val}=0.059.

Welch. If the spreads may differ, use each group’s own variance, s12/n1+s22/n2\sqrt{s_1^2/n_1+s_2^2/n_2}, and a reduced number of degrees of freedom. With equal group sizes the standard error is the same here; the degrees of freedom fall to 5.835.83, and pval=0.060p_\text{val}=0.060. Welch’s version is the safer default.

The exact shuffle test gave 0.08570.0857 for the same data. With four values per group, the t law and the shuffle disagree in the second digit: small samples make every method rough.

Pairs

Five people were timed before and after a change: before 20, 24, 18, 22, 26, after 23, 25, 22, 24, 31. Each person was measured twice, so look at each person’s difference: 3, 1, 4, 2, 5. Their mean is 3 and their ss is 1.5811, so the standard error is 0.7071 and tobs=4.243t_\text{obs}=4.243 with 4 degrees of freedom: pval=0.013p_\text{val}=0.013.

Treat the same numbers as two unrelated groups and the answer changes. The means are 22 and 25, the variances 10 and 12.5, the pooled variance 11.25, and the standard error 4.5=2.1213\sqrt{4.5}=2.1213: tobs=1.414t_\text{obs}=1.414 with 8 degrees of freedom, pval=0.195p_\text{val}=0.195.

The people differ from each other far more than the change moves any one of them. Pairing takes those differences between people away, and the effect shows. A paired test is a one-sample test on the differences.

What the test assumes

  • Independence. The values must not influence each other. This matters most and cannot be fixed afterwards.
  • A rough bell. For tiny samples the data should be roughly bell-shaped. For larger samples The central limit theorem makes the mean close to a bell anyway, and the test holds up.
  • No wild values. One outlier changes both the mean and ss, as in Describing data; look at the data first.

Worked example

1. The response times against 15 ms. tobs=1.2127t_\text{obs}=1.2127, 7 degrees of freedom, pval=0.26p_\text{val}=0.26. At the 5 % level, 1.211.21 is below the edge 2.3652.365: not rejected.

2. The layouts. Pooled: tobs=2.3256t_\text{obs}=2.3256, 6 degrees of freedom, pval=0.059p_\text{val}=0.059. Welch: 5.83 degrees of freedom, pval=0.060p_\text{val}=0.060.

3. Before and after. Paired: pval=0.013p_\text{val}=0.013. Unpaired: pval=0.195p_\text{val}=0.195.

4. The 95 % edges.

Degrees of freedom1234571030unlimited
Edge12.7064.3033.1822.7762.5712.3652.2282.0421.960

Try it yourself. For the same tobst_\text{obs}, the pvalp_\text{val} is larger with 3 degrees of freedom than with 30: the tails are heavier. As the sample grows without limit, the t curve becomes the bell.

Where you’ll meet this

Small comparisons. Comparing two versions of a product on a handful of units, or two lab methods on a few samples, is a two-sample t-test.

Measurement against a standard. Checking whether an instrument’s mean reading matches a reference value is a one-sample t-test.

Before and after. Studies that measure the same people, machines or sites twice use paired tests, and gain a great deal from it.

In signal processing · standard error and testing

Averaging EEG trials and asking whether a response at 300 ms differs from zero is a t-test across trials, with the trials’ scatter as ss. EEG and rhythms in the signal processing course uses it.

Reference card

QuantityFormulaNotes
t statisticT=(Xˉ−μ0)/(S/n)T=(\bar X-\mu_0)/(S/\sqrt n)follows tn−1\mathrm{t}_{n-1} for bell-shaped data
Heavier tailsbeyond ±2\pm2: 0.2952, 0.1835 at 1, 2 degrees of freedomthe bell: 0.0455
One sampletobs=(xˉ−μ0)/(s/n)t_\text{obs}=(\bar x-\mu_0)/(s/\sqrt n), n−1n-1 degrees of freedommatches the t interval
Pooled two-samplesp2=(n1−1)s12+(n2−1)s22n1+n2−2s_\text{p}^2=\frac{(n_1-1)s_1^2+(n_2-1)s_2^2}{n_1+n_2-2}, SE sp1/n1+1/n2s_\text{p}\sqrt{1/n_1+1/n_2}n1+n2−2n_1+n_2-2 degrees of freedom
WelchSE s12/n1+s22/n2\sqrt{s_1^2/n_1+s_2^2/n_2}the safer default
Pairedone-sample test on the differencesremoves unit-to-unit spread
Assumesindependence; a rough bell for tiny nn; no wild values

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look