How to Run a One-sample t-test

Tests whether the mean of a sample differs from an assumed population mean μ₀. It calculates t = (sample mean − μ₀) ÷ (sample standard deviation ÷ √n) and the two-sided p-value from the t distribution with n − 1 degrees of freedom. A p-value below the significance level means the population mean differs from μ₀.

A one-sample t-test asks whether the mean of your data differs from an assumed population mean μ0\mu_0. It is what you use when the standard deviation of the population is unknown and has to be estimated from the sample, which is nearly always.

t=xˉμ0s/nt = \dfrac{\bar{x} - \mu_0}{s / \sqrt{n}}

This tt follows the t distribution with n1n - 1 degrees of freedom. The fewer the degrees of freedom, the heavier the tails of that distribution and the larger the critical value.

Example

With the defaults, the data 12, 15, 18, 20, 25 against an assumed mean of μ0=15\mu_0 = 15. The sample mean is 18 and the sample variance is 24.5, so the sample standard deviation is 24.54.9497\sqrt{24.5} \approx 4.9497.

t=18154.9497/5=32.21361.3553t = \dfrac{18 - 15}{4.9497 / \sqrt{5}} = \dfrac{3}{2.2136} \approx 1.3553

On 51=45 - 1 = 4 degrees of freedom the two-sided p-value is 0.2468. The critical value at a 5% significance level is 2.7764, and t=1.3553|t| = 1.3553 does not reach it. The p-value is above 0.05, so the population mean cannot be said to differ from 15.

Reading the result

The p-value is the probability of a mean straying this far from μ0\mu_0 if the population mean really were μ0\mu_0. When it falls below the significance level, usually 5%, chance becomes an uncomfortable explanation and you conclude that the mean differs.

A large p-value means you have failed to show a difference, not that there is none. With little data, a real difference can easily go unnoticed.

Watch out

This is a two-sided test: it asks whether the mean differs, in either direction. For a one-sided question, halve the p-value.

At least two values are needed, and they must not all be identical. With no spread, s=0s = 0 and tt is undefined.