{
  "id": "test-statistic",
  "version": "ba4918c62b4f",
  "status": "published",
  "name": "Test Statistic Calculator",
  "question": "What is my test statistic?",
  "summary": "Computes the z or t test statistic, its standard error, degrees of freedom and p-value for one mean, two means, one proportion or two proportions, from summary numbers.",
  "category": "statistics",
  "subcategory": "tests",
  "url": "https://www.acalculator.org/statistics/test-statistic-calculator",
  "markdown": "https://www.acalculator.org/statistics/test-statistic-calculator.md",
  "kind": "function",
  "method": "z = (x̄ − μ₀) ÷ (σ ÷ √n); t = (x̄ − μ₀) ÷ (s ÷ √n), n − 1 df; two means: t = (x̄₁ − x̄₂) ÷ √(s₁²/n₁ + s₂²/n₂) (Welch df) or ÷ (sₚ√(1/n₁ + 1/n₂)) (pooled, n₁ + n₂ − 2 df); one proportion: z = (p̂ − p₀) ÷ √(p₀(1 − p₀)/n); two proportions: z = (p̂₁ − p̂₂) ÷ √(p̂(1 − p̂)(1/n₁ + 1/n₂)).",
  "assumptions": [
    "Random, independent samples. t tests assume roughly normal data or large samples; z tests for proportions use the normal approximation, which needs enough successes and failures (often 10 or more of each).",
    "The two-means test compares x̄₁ − x̄₂ with 0.",
    "p-values: two-tailed = 2 × the upper tail beyond |statistic| (at most 1); left = the lower tail below it; right = the upper tail above it."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "test": {
        "title": "Test",
        "description": "Which hypothesis test to compute the statistic for.",
        "type": "string",
        "enum": [
          "z",
          "t",
          "two",
          "prop",
          "twoprop"
        ]
      },
      "tail": {
        "title": "Alternative",
        "description": "Two-tailed (≠), left-tailed (<) or right-tailed (>).",
        "type": "string",
        "enum": [
          "two",
          "left",
          "right"
        ]
      },
      "m1": {
        "title": "Sample mean x̄₁",
        "description": "The mean of the (first) sample.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "mu": {
        "title": "Hypothesized mean μ₀",
        "description": "The population mean under the null hypothesis.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "sd1": {
        "title": "Standard deviation",
        "description": "σ for a z test; the sample standard deviation s for a t test.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1000000000000
      },
      "n1": {
        "title": "Sample size n₁",
        "description": "How many observations are in the (first) sample.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000000000
      },
      "m2": {
        "title": "Sample mean x̄₂",
        "description": "The mean of the second sample.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "sd2": {
        "title": "Standard deviation s₂",
        "description": "The standard deviation of the second sample.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1000000000000
      },
      "n2": {
        "title": "Sample size n₂",
        "description": "How many observations are in the second sample.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000000000
      },
      "var": {
        "title": "Variances",
        "description": "Welch’s test for unequal variances, or the pooled test for equal variances.",
        "type": "string",
        "enum": [
          "welch",
          "pooled"
        ]
      },
      "x1": {
        "title": "Successes x₁",
        "description": "How many of the (first) sample have the trait.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000
      },
      "p0": {
        "title": "Hypothesized proportion p₀",
        "description": "The population proportion under the null hypothesis, between 0 and 1.",
        "type": "number",
        "exclusiveMinimum": 0,
        "exclusiveMaximum": 1
      },
      "x2": {
        "title": "Successes x₂",
        "description": "How many of the second sample have the trait.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000
      }
    }
  },
  "outputs": {
    "statistic": {
      "label": "Test statistic",
      "description": "The estimate minus the null value, divided by its standard error.",
      "format": "number"
    },
    "kind": {
      "label": "Statistic",
      "description": "z (standard normal) or t (Student’s t).",
      "format": "text"
    },
    "se": {
      "label": "Standard error",
      "description": "The standard error under the null hypothesis.",
      "format": "number"
    },
    "df": {
      "label": "Degrees of freedom",
      "description": "For t: n − 1, n₁ + n₂ − 2 (pooled) or the Welch–Satterthwaite value.",
      "format": "number"
    },
    "p": {
      "label": "p-value",
      "description": "The chance of a statistic at least this extreme in the chosen direction, if the null hypothesis holds.",
      "format": "number"
    },
    "estimate": {
      "label": "Estimate",
      "description": "x̄, x̄₁ − x̄₂, p̂ or p̂₁ − p̂₂.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "test": "t",
      "tail": "two",
      "m1": 53.7,
      "mu": 50,
      "sd1": 6.567,
      "n1": 10,
      "m2": 30.48101,
      "sd2": 6.10771,
      "n2": 79,
      "var": "welch",
      "x1": 26,
      "p0": 0.1,
      "x2": 30
    },
    "outputs": {
      "statistic": 1.781700524230701,
      "kind": "t",
      "se": 2.0766677394325748,
      "df": 9,
      "p": 0.10848447147266896,
      "estimate": 53.7
    },
    "text": "The test statistic is t = 1.7817, with a p-value of 0.1085."
  },
  "examples": [
    {
      "given": {
        "test": "t",
        "tail": "two",
        "m1": 53.7,
        "mu": 50,
        "sd1": 6.567,
        "n1": 10
      },
      "expect": {
        "statistic": 1.781700524230701,
        "df": 9
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2 (t = (Ȳ − μ₀) ÷ (s ÷ √N), N − 1 df; 10 wafers, mean 53.7, s 6.567, μ₀ 50: t = 1.782). https://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm"
    },
    {
      "given": {
        "test": "two",
        "tail": "two",
        "var": "pooled",
        "m1": 20.14458,
        "sd1": 6.4147,
        "n1": 249,
        "m2": 30.48101,
        "sd2": 6.10771,
        "n2": 79
      },
      "expect": {
        "statistic": -12.620585000444759,
        "df": 326
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-Sample t-Test (AUTO83B.DAT: N 249 and 79, means 20.14458 and 30.48101, SD 6.41470 and 6.10771; pooled T = −12.62059, 326 df). https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm"
    },
    {
      "given": {
        "test": "prop",
        "tail": "right",
        "x1": 26,
        "n1": 200,
        "p0": 0.1
      },
      "expect": {
        "statistic": 1.414213562373095,
        "estimate": 0.13,
        "p": 0.07864960352514261
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.4 (z = (p̂ − p₀) ÷ √(p₀(1 − p₀) ÷ N); 26 of 200, p₀ 0.10: z = 1.414). https://www.itl.nist.gov/div898/handbook/prc/section2/prc24.htm"
    },
    {
      "given": {
        "test": "z",
        "tail": "two",
        "m1": 103,
        "mu": 100,
        "sd1": 15,
        "n1": 25
      },
      "expect": {
        "statistic": 1,
        "se": 3,
        "p": 0.31731050786291415
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2 (z = (Ȳ − μ₀) ÷ (σ ÷ √N)). https://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm; hand calculation in content.mdx: (103 − 100) ÷ (15 ÷ 5) = 1; p = 2 × (1 − Φ(1)) = 0.3173"
    },
    {
      "given": {
        "test": "twoprop",
        "tail": "two",
        "x1": 45,
        "n1": 100,
        "x2": 30,
        "n2": 100
      },
      "expect": {
        "statistic": 2.1908902300206647,
        "estimate": 0.15
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §7.3.3 (z = (p̂₁ − p̂₂) ÷ √(p̂(1 − p̂)(1/n₁ + 1/n₂)), p̂ = (x₁ + x₂) ÷ (n₁ + n₂)). https://www.itl.nist.gov/div898/handbook/prc/section3/prc33.htm; hand calculation in content.mdx: p̂ = 0.375; 0.15 ÷ √(0.375 × 0.625 × 0.02) = 2.1909"
    }
  ],
  "sources": [
    "NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2 Are the data consistent with the assumed process mean? (z and t for one mean; wafer example t = 1.782, 9 df). https://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm (retrieved 2026-10-01)",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-Sample t-Test for Equal Means (pooled and unequal-variance T, Welch–Satterthwaite df; AUTO83B example T = −12.62059, 326 df). https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm (retrieved 2026-10-01)",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.4 Does the proportion of defectives meet requirements? (z for one proportion; 26 of 200 against 0.10, z = 1.414). https://www.itl.nist.gov/div898/handbook/prc/section2/prc24.htm (retrieved 2026-10-01)",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §7.3.3 How can we determine whether two processes produce the same proportion of defectives? (z for two proportions with the pooled p̂). https://www.itl.nist.gov/div898/handbook/prc/section3/prc33.htm (retrieved 2026-10-01)"
  ],
  "related": [
    "t-test",
    "z-score",
    "p-value",
    "critical-value"
  ],
  "changelog": []
}
