Home › Statistics & 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
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
mode | enum: one_sample | two_sample | paired | default two_sample | Which t-test to run. | |
sample_a | number_list | no | Raw observations of the first (or only) sample. Alternatively give mean_a, sd_a and n_a. | |
sample_b | number_list | no | Raw 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_a | number | no | Summary alternative to sample_a: sample mean of A (in paired mode: mean of the differences a − b). | |
sd_a | number | no | Sample standard deviation (n − 1) of A, or of the paired differences. Range: > 0 | |
n_a | integer | no | Number of observations in A, or number of pairs. Range: ≥ 2 | |
mean_b | number | no | Summary alternative to sample_b (two_sample only): sample mean of B. | |
sd_b | number | no | Sample standard deviation (n − 1) of B. Range: > 0 | |
n_b | integer | no | Number of observations in B. Range: ≥ 2 | |
hypothesized_mean | number | default 0 | Null-hypothesis value: the population mean (one_sample) or the mean difference (two_sample, paired). Usually 0 for differences. | |
alpha | number | default 0.05 | Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha. Range: > 0 |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
test | string | Which t-test was run and on how many observations. | |
mean_a | number | Sample mean of A (paired mode: mean of the differences). | |
mean_b | number | Sample mean of B (two_sample only). | |
mean_difference | number | mean_a − hypothesized_mean (one_sample), mean_a − mean_b (two_sample) or mean of a − b (paired). | |
standard_error | number | Standard error of the estimated difference. | |
t_statistic | number | (estimated difference − hypothesized_mean) / standard_error. | |
degrees_of_freedom | number | n − 1 for one-sample and paired tests; Welch–Satterthwaite approximation (fractional) for two samples. | |
p_value_two_sided | number | P(|T| ≥ |t|) under H0. | |
p_value_one_sided | number | Half the two-sided p: for the alternative in the direction of the observed difference. | |
t_critical | number | t quantile at 1 − alpha/2 for the degrees of freedom. | |
ci_lower | number | Lower limit of the 100·(1 − alpha) % confidence interval for the mean (one_sample) or the mean difference. | |
ci_upper | number | Upper limit of the same interval. | |
significant | boolean | true when p_value_two_sided < alpha. | |
decision | string | Plain-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
- API:
GET https://tttkmbb.com/api/v1/calculate/t-test(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/t-test · Markdown: https://tttkmbb.com/statistics/t-test.md · JSON definition: https://tttkmbb.com/statistics/t-test.json
- MCP: server
https://tttkmbb.com/mcp, toolcalculate_t_test - OpenAPI operationId:
calculate_t_test - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
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
- P-Value Calculator — p-value for a t, z or chi-square statistic you already have.
- Cohen's d Effect Size Calculator — Effect size of the difference between the two groups.
- Confidence Interval Calculator — z-based interval for a single mean.