HomeStatistics & Probability › T-Test Calculator

T-Test Calculator

Runs a one-sample, Welch two-sample (unequal variances) or paired Student t-test from raw samples or summary statistics (mean, SD, n), returning t, degrees of freedom, two- and one-sided p-values, the confidence interval and the decision at the chosen alpha.

When to use

You want to test whether a sample mean differs from a hypothesised value, whether two independent groups have different means, or whether paired before/after measurements changed.

Do not use when: The data are proportions or counts (use proportion-z-test or chi-square-test), you have three or more groups (ANOVA), or you already have t and df and only need the p-value (use p-value).

Formula

one_sample: t = (x̄ − μ0) / (s / √n), df = n − 1. paired: same on the differences d = a − b. two_sample (Welch): t = (x̄a − x̄b − μ0) / √(sa²/na + sb²/nb), df = (sa²/na + sb²/nb)² / ((sa²/na)²/(na − 1) + (sb²/nb)²/(nb − 1)). p = P(|T_df| ≥ |t|); CI = estimate ± t(1 − alpha/2, df) × SE

The two-sample test is Welch's version, which does not assume equal variances and is recommended as the default (the pooled-variance Student test is not offered). p-values come from the regularized incomplete beta function; the test assumes approximately normal data or n large enough for the central limit theorem.

Inputs

ParameterTypeUnitRequiredDescription
modeenum: one_sample | two_sample | paireddefault two_sampleWhich t-test to run.
sample_anumber_listnoRaw observations of the first (or only) sample. Alternatively give mean_a, sd_a and n_a.
sample_bnumber_listnoRaw observations of the second sample (two_sample) or the paired partner values in the same order (paired). Alternatively give mean_b, sd_b and n_b.
mean_anumbernoSummary alternative to sample_a: sample mean of A (in paired mode: mean of the differences a − b).
sd_anumbernoSample standard deviation (n − 1) of A, or of the paired differences. Range: > 0
n_aintegernoNumber of observations in A, or number of pairs. Range: ≥ 2
mean_bnumbernoSummary alternative to sample_b (two_sample only): sample mean of B.
sd_bnumbernoSample standard deviation (n − 1) of B. Range: > 0
n_bintegernoNumber of observations in B. Range: ≥ 2
hypothesized_meannumberdefault 0Null-hypothesis value: the population mean (one_sample) or the mean difference (two_sample, paired). Usually 0 for differences.
alphanumberdefault 0.05Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha. Range: > 0

Outputs

OutputTypeUnitDescription
teststringWhich t-test was run and on how many observations.
mean_anumberSample mean of A (paired mode: mean of the differences).
mean_bnumberSample mean of B (two_sample only).
mean_differencenumbermean_a − hypothesized_mean (one_sample), mean_a − mean_b (two_sample) or mean of a − b (paired).
standard_errornumberStandard error of the estimated difference.
t_statisticnumber(estimated difference − hypothesized_mean) / standard_error.
degrees_of_freedomnumbern − 1 for one-sample and paired tests; Welch–Satterthwaite approximation (fractional) for two samples.
p_value_two_sidednumberP(|T| ≥ |t|) under H0.
p_value_one_sidednumberHalf the two-sided p: for the alternative in the direction of the observed difference.
t_criticalnumbert quantile at 1 − alpha/2 for the degrees of freedom.
ci_lowernumberLower limit of the 100·(1 − alpha) % confidence interval for the mean (one_sample) or the mean difference.
ci_uppernumberUpper limit of the same interval.
significantbooleantrue when p_value_two_sided < alpha.
decisionstringPlain-language conclusion of the two-sided test.

Example

Welch: 5.1, 4.9, 5.6, 5.8, 6.0 vs 4.2, 4.8, 4.4, 4.6, 4.5: {"mode":"two_sample","sample_a":[5.1,4.9,5.6,5.8,6],"sample_b":[4.2,4.8,4.4,4.6,4.5]}{"mean_a":5.48,"mean_b":4.5,"mean_difference":0.98,"standard_error":0.2311,"t_statistic":4.2409,"degrees_of_freedom":5.7504,"p_value_two_sided":0.005979,"p_value_one_sided":0.002989,"t_critical":2.4729,"ci_lower":0.4086,"ci_upper":1.5514,"significant":true}

Paired: Student's sleep data (drug 2 minus drug 1, n = 10): {"mode":"paired","sample_a":[1.9,0.8,1.1,0.1,-0.1,4.4,5.5,1.6,4.6,3.4],"sample_b":[0.7,-1.6,-0.2,-1.2,-0.1,3.4,3.7,0.8,0,2]}{"mean_difference":1.58,"standard_error":0.389,"t_statistic":4.0621,"degrees_of_freedom":9,"p_value_two_sided":0.002833,"ci_lower":0.7001,"ci_upper":2.4599,"significant":true}

GET https://tttkmbb.com/api/v1/calculate/t-test?mode=two_sample&sample_a=5.1%2C4.9%2C5.6%2C5.8%2C6&sample_b=4.2%2C4.8%2C4.4%2C4.6%2C4.5

Machine access

Sources

FAQ

Raw data or summary statistics?

Either: give sample_a / sample_b as lists, or mean, SD (with n − 1) and n for each group. In paired mode the summary values describe the differences a − b.

Why Welch instead of the classic pooled t-test?

Welch's test keeps the nominal error rate when the variances or sample sizes differ and loses almost nothing when they are equal; its degrees of freedom are fractional. R's t.test uses it by default.

Which p-value should I report?

The two-sided p unless the direction was fixed before seeing the data; the one-sided p given here is for the alternative in the observed direction and is half the two-sided value.

Related calculators