{
  "id": "t-test",
  "version": "6381cf841cf1",
  "status": "published",
  "name": "T-Test Calculator",
  "question": "What does my t-test show?",
  "summary": "Runs a one-sample, two-sample (Welch or pooled), or paired t-test from means, standard deviations, and sample sizes, with the t statistic, degrees of freedom, p-value, and decision.",
  "category": "statistics",
  "subcategory": "tests",
  "url": "https://www.acalculator.org/statistics/t-test-calculator",
  "markdown": "https://www.acalculator.org/statistics/t-test-calculator.md",
  "kind": "function",
  "method": "t = (estimate − μ₀) ÷ SE. One-sample and paired: SE = s ÷ √n, df = n − 1. Welch: SE = √(s₁²/n₁ + s₂²/n₂), df = SE⁴ ÷ ((s₁²/n₁)²/(n₁ − 1) + (s₂²/n₂)²/(n₂ − 1)). Pooled: sp² = ((n₁ − 1)s₁² + (n₂ − 1)s₂²) ÷ (n₁ + n₂ − 2), SE = sp √(1/n₁ + 1/n₂), df = n₁ + n₂ − 2.",
  "assumptions": [
    "The observations are independent, and each mean is roughly normal (the data are close to normal, or the samples are large).",
    "Standard deviations are sample standard deviations (divided by n − 1).",
    "Welch’s degrees of freedom are fractional; the t distribution is evaluated at that fractional value."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "type": {
        "title": "Test",
        "description": "One-sample compares a mean with a value; two-sample compares two independent groups; paired compares two measurements on the same subjects.",
        "type": "string",
        "enum": [
          "one",
          "two",
          "paired"
        ]
      },
      "m1": {
        "title": "Mean (x̄₁)",
        "description": "The sample mean, or the mean of group 1 for a two-sample test.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "s1": {
        "title": "Standard deviation (s₁)",
        "description": "The sample standard deviation of the sample or of group 1.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1000000000000
      },
      "n1": {
        "title": "Sample size (n₁)",
        "description": "How many observations are in the sample or in group 1, at least 2.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "m2": {
        "title": "Mean (x̄₂)",
        "description": "The sample mean of group 2.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "s2": {
        "title": "Standard deviation (s₂)",
        "description": "The sample standard deviation of group 2.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1000000000000
      },
      "n2": {
        "title": "Sample size (n₂)",
        "description": "How many observations are in group 2, at least 2.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "dm": {
        "title": "Mean of the differences (d̄)",
        "description": "The mean of the paired differences (after − before, or first − second).",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "ds": {
        "title": "SD of the differences (s(d))",
        "description": "The sample standard deviation of the paired differences.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1000000000000
      },
      "np": {
        "title": "Number of pairs (n)",
        "description": "How many pairs there are, at least 2.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "var": {
        "title": "Variances",
        "description": "Welch’s test does not assume equal variances; the pooled test assumes the two groups have the same variance.",
        "type": "string",
        "enum": [
          "welch",
          "pooled"
        ]
      },
      "mu0": {
        "title": "Hypothesized value (μ₀)",
        "description": "The mean under the null hypothesis (one-sample), or the difference μ₁ − μ₂ or mean difference under the null hypothesis, usually 0.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "tail": {
        "title": "Alternative hypothesis",
        "description": "Two-tailed tests for any difference; left- and right-tailed test for a difference in one direction.",
        "type": "string",
        "enum": [
          "two",
          "left",
          "right"
        ]
      },
      "alpha": {
        "title": "Significance level (α)",
        "description": "The cut-off for the p-value, for example 0.05.",
        "type": "number",
        "minimum": 1e-10,
        "maximum": 0.5
      }
    }
  },
  "outputs": {
    "t": {
      "label": "t statistic",
      "description": "The estimate minus the hypothesized value, divided by its standard error.",
      "format": "number"
    },
    "df": {
      "label": "Degrees of freedom",
      "description": "n − 1 (one-sample, paired), n₁ + n₂ − 2 (pooled), or the Welch–Satterthwaite value (Welch).",
      "format": "number"
    },
    "pValue": {
      "label": "P-value",
      "description": "The chance of a t statistic at least this extreme, in the chosen direction, if the null hypothesis is true.",
      "format": "number"
    },
    "critical": {
      "label": "Critical value",
      "description": "The t value that starts the rejection region: reject when |t| reaches it (two-tailed), t is at or below it (left), or at or above it (right).",
      "format": "number"
    },
    "decision": {
      "label": "Decision",
      "description": "Reject the null hypothesis when the p-value is α or less.",
      "format": "text"
    },
    "estimate": {
      "label": "Estimate",
      "description": "The sample mean (one-sample), x̄₁ − x̄₂ (two-sample), or the mean difference (paired).",
      "format": "number"
    },
    "se": {
      "label": "Standard error",
      "description": "The standard error of the estimate, the denominator of t.",
      "format": "number"
    },
    "pooledSd": {
      "label": "Pooled standard deviation",
      "description": "The common standard deviation of the pooled test. Shown for the pooled test only.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "type": "two",
      "m1": 75,
      "s1": 10,
      "n1": 30,
      "m2": 70,
      "s2": 12,
      "n2": 35,
      "dm": 1.5,
      "ds": 2,
      "np": 10,
      "var": "welch",
      "mu0": 0,
      "tail": "two",
      "alpha": 0.05
    },
    "outputs": {
      "t": 1.8321510564377976,
      "df": 62.958820084919275,
      "pValue": 0.0716594520199214,
      "critical": 1.9983661227705063,
      "decision": "Do not reject the null hypothesis",
      "estimate": 5,
      "se": 2.7290326212083005
    },
    "text": "t = 1.832151 with 62.95882 degrees of freedom and a p-value of 0.071659. Do not reject the null hypothesis at α = 0.05."
  },
  "examples": [
    {
      "given": {
        "type": "two",
        "m1": 75,
        "s1": 10,
        "n1": 30,
        "m2": 70,
        "s2": 12,
        "n2": 35,
        "var": "welch",
        "mu0": 0,
        "tail": "two",
        "alpha": 0.05
      },
      "expect": {
        "t": 1.8321510564377976,
        "df": 62.958820084919275,
        "pValue": 0.07165945201992106,
        "decision": "Do not reject the null hypothesis"
      },
      "source": "hand calculation in content.mdx: 5 ÷ √(100/30 + 144/35) = 1.8322; 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"
    },
    {
      "given": {
        "type": "two",
        "m1": 20.14458,
        "s1": 6.4147,
        "n1": 249,
        "m2": 30.48101,
        "s2": 6.10771,
        "n2": 79,
        "var": "pooled",
        "mu0": 0,
        "tail": "two",
        "alpha": 0.05
      },
      "expect": {
        "t": -12.62058500044476,
        "df": 326,
        "pooledSd": 6.342600815210088,
        "critical": 1.9672675222597709
      },
      "source": "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 (T = −12.62059, sp = 6.34260, ν = 326, critical value 1.9673)"
    },
    {
      "given": {
        "type": "one",
        "m1": 9.26146,
        "s1": 0.022789,
        "n1": 195,
        "mu0": 5,
        "tail": "two",
        "alpha": 0.05
      },
      "expect": {
        "t": 2611.2620289139318,
        "df": 194,
        "critical": 1.9722675325821355,
        "decision": "Reject the null hypothesis"
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.2 Confidence Limits for the Mean (one-sample t-test). https://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm (T = 2611.284, ν = 194, critical value 1.9723)"
    },
    {
      "given": {
        "type": "paired",
        "dm": 1.5,
        "ds": 2,
        "np": 10,
        "mu0": 0,
        "tail": "right",
        "alpha": 0.05
      },
      "expect": {
        "t": 2.3717082451262845,
        "df": 9,
        "pValue": 0.020895900388556515,
        "critical": 1.8331129326562372
      },
      "source": "hand calculation in content.mdx: 1.5 ÷ (2 ÷ √10) = 2.3717; OpenStax, Introductory Statistics 2e, §10.4 Matched or Paired Samples. https://openstax.org/books/introductory-statistics-2e/pages/10-4-matched-or-paired-samples"
    },
    {
      "given": {
        "type": "one",
        "m1": 12,
        "s1": 3,
        "n1": 9,
        "mu0": 10,
        "tail": "left",
        "alpha": 0.05
      },
      "expect": {
        "t": 2,
        "df": 8,
        "pValue": 0.9597418810213687,
        "critical": -1.859548037530898
      },
      "source": "hand calculation in content.mdx: (12 − 10) ÷ (3 ÷ 3) = 2; NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.2 Confidence Limits for the Mean (one-sample t-test). https://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm"
    }
  ],
  "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",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.2 Confidence Limits for the Mean. https://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm",
    "OpenStax, Introductory Statistics 2e, §10.4 Matched or Paired Samples. https://openstax.org/books/introductory-statistics-2e/pages/10-4-matched-or-paired-samples"
  ],
  "related": [
    "p-value",
    "critical-value",
    "confidence-interval",
    "standard-deviation"
  ],
  "changelog": []
}
