One-sample t-test calculator
Is the mean of your sample different from a target value? Get t, the p-value, a confidence interval and the decision.
Separate numbers with commas, spaces or new lines. Use a point for decimals.
What does a one-sample t-test tell me?
It compares the mean of one sample with a value you chose in advance — a target, a specification, a published figure — and asks whether the gap is larger than sampling noise alone would usually produce. The test statistic is t = (x̄ − μ0) ÷ (s ÷ √n), with n − 1 degrees of freedom (NIST/SEMATECH e-Handbook, section 7.2.2). The p-value is the chance of getting a t at least that far from 0 if the true mean really were μ0. A small p-value says the data are hard to square with μ0; it does not say how big or how important the difference is.
Worked example: particle counts on silicon wafers
The NIST/SEMATECH handbook gives particle counts on ten wafers: 50, 48, 44, 56, 61, 52, 53, 55, 67 and 51, and asks whether the long-run process average of 50 has changed. The sample mean is 53.7 and the standard deviation 6.567, so the standard error is 6.567 ÷ √10 = 2.077 and t = 3.7 ÷ 2.077 = 1.782 with 9 degrees of freedom. That is inside ±2.262, the 5% two-sided critical value, so the handbook concludes the process mean can still be taken as 50. The calculator adds the two-sided p-value, 0.1085, and the 95% confidence interval for the mean, 49.0 to 58.4, which contains 50.
Should I use a one-sided or a two-sided test?
Use a two-sided test unless, before seeing the data, you have a reason to care about one direction only. In OpenStax Introductory Statistics (Example 9.16) an instructor suspects the mean first-test score is above 65 and samples ten scores: 65, 65, 70, 67, 66, 63, 63, 68, 72, 71. The mean is 67 and s = 3.1972, so t = 1.9781 with 9 degrees of freedom. The right-tailed p-value is 0.0396, below α = 0.05, so the null hypothesis is rejected; the two-sided p-value is twice that, 0.0793, which would not be significant at 5%. Picking the direction after looking at the data inflates the false-positive rate.
When can I use the z-test with a known standard deviation?
Only when the standard deviation of the whole population is known from outside the sample, for example from a long record of the same process. Then z = (x̄ − μ0) ÷ (σ ÷ √n) is compared with the normal distribution. OpenStax Example 9.14: a swimmer’s long-run mean for 25 yards is 16.43 seconds with σ = 0.8, and 15 swims with new goggles average 16 seconds. Then z = −2.08 and the left-tailed p-value is 0.0187, so at α = 0.05 the goggles look faster. Most of the time σ is not known and the sample standard deviation is used, which is what the t-test does; it is more cautious for small samples because the t distribution has heavier tails.
How is the confidence interval related to the test?
The interval is x̄ ± t × s ÷ √n, where t is the critical value for the confidence level (NIST handbook, section 1.3.5.2). A two-sided test at α rejects μ0 exactly when μ0 lies outside the (1 − α) confidence interval. The handbook’s example is a data set of 195 values (ZARR13.DAT) with mean 9.261460 and standard deviation 0.022789: the 95% interval is 9.258242 to 9.264679, so a hypothesised mean of 5 is far outside it and the t statistic is about 2611. In R’s sleep data (20 values of extra sleep, mean 1.54), t.test gives an interval of 0.5956 to 2.4844, and a hypothesised mean of 1.5 is well inside it: t = 0.0886, one-sided p = 0.4651.
What is Cohen’s d here, and how large a sample do I need?
For one sample, d = (x̄ − μ0) ÷ s: the gap measured in standard deviations, which does not shrink as the sample grows. For the wafers it is 3.7 ÷ 6.567 = 0.56. With a large sample, even a tiny d produces a very small p-value, so report the size of the difference and the interval, not just p. To plan how many observations you need to detect a given d, use the statistical power calculator, which includes the one-sample t-test.
What are the assumptions, and what if they fail?
The observations should be independent (a random sample or a stable process) and the population roughly normal; OpenStax notes that with a large enough sample the t-test works even when the population is not approximately normal. Strong skew or outliers in a small sample can distort the mean and the standard deviation; in that case try the Wilcoxon signed-rank test against a hypothesised median. If your numbers are before-and-after values for the same people, the right test is a one-sample test on the differences, which is exactly the paired t-test. For two separate groups, use the two-sample t-test.
Sources: NIST/SEMATECH e-Handbook of Statistical Methods, sections 7.2.2 (“Are the data consistent with the assumed process mean?”) and 1.3.5.2 (“Confidence limits for the mean”); OpenStax, Introductory Statistics 2e, sections 9.3 and 9.5 (Examples 9.14 and 9.16); documentation of R (stats::t.test and the datasets::sleep data). Related: two-sample t-test calculator, paired t-test calculator, Wilcoxon signed-rank test calculator, standard error calculator, statistical power calculator, confidence interval calculator and p-value calculator.