# 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.

- Calculator id: `t-test` · Category: Statistics & Probability (`statistics`) · Tool name: `calculate_t_test`
- Canonical page: https://tttkmbb.com/statistics/t-test · This document: https://tttkmbb.com/statistics/t-test.md · JSON definition: https://tttkmbb.com/statistics/t-test.json

## Purpose

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.

**Use when:** 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).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `mode` | enum: one_sample \| two_sample \| paired |  | optional, default "two_sample" | Which t-test to run. |
| `sample_a` | number_list |  | optional | Raw observations of the first (or only) sample. Alternatively give mean_a, sd_a and n_a. |
| `sample_b` | number_list |  | optional | 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 |  | optional | Summary alternative to sample_a: sample mean of A (in paired mode: mean of the differences a − b). |
| `sd_a` | number |  | optional | Sample standard deviation (n − 1) of A, or of the paired differences. (> 0) |
| `n_a` | integer |  | optional | Number of observations in A, or number of pairs. (min 2) |
| `mean_b` | number |  | optional | Summary alternative to sample_b (two_sample only): sample mean of B. |
| `sd_b` | number |  | optional | Sample standard deviation (n − 1) of B. (> 0) |
| `n_b` | integer |  | optional | Number of observations in B. (min 2) |
| `hypothesized_mean` | number |  | optional, default 0 | Null-hypothesis value: the population mean (one_sample) or the mean difference (two_sample, paired). Usually 0 for differences. |
| `alpha` | number |  | optional, default 0.05 | Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha. (> 0) |

## Output

| Field | 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. |

## 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.

## Data Sources

- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.3 Two-Sample t-Test for Equal Means — https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm (government, retrieved 2026-09-24)
- Welch BL (1947) The generalization of 'Student's' problem when several different population variances are involved, Biometrika 34:28-35 — https://doi.org/10.1093/biomet/34.1-2.28 (peer_reviewed, retrieved 2026-09-24)
- Wikipedia – Student's t-test — https://en.wikipedia.org/wiki/Student%27s_t-test (reference, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/t-test?`
- `POST https://tttkmbb.com/api/v1/calculate/t-test` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/t-test · OpenAPI operationId `calculate_t_test` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool: `calculate_t_test` (dedicated) or `run_calculator` with `{"calculator_id": "t-test", "inputs": {…}}`

## Example

- Welch: 5.1, 4.9, 5.6, 5.8, 6.0 vs 4.2, 4.8, 4.4, 4.6, 4.5: inputs `{"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): inputs `{"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
```

## Limitations

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). 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. All values are computed from the formula above; no measurement or live data is involved.

## 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

- [P-Value Calculator](https://tttkmbb.com/statistics/p-value.md) — p-value for a t, z or chi-square statistic you already have.
- [Cohen's d Effect Size Calculator](https://tttkmbb.com/statistics/cohens-d.md) — Effect size of the difference between the two groups.
- [Confidence Interval Calculator](https://tttkmbb.com/statistics/confidence-interval.md) — z-based interval for a single mean.
