{
  "id": "degrees-of-freedom",
  "version": "2240ea130d23",
  "status": "published",
  "name": "Degrees of Freedom Calculator",
  "question": "What are my degrees of freedom?",
  "summary": "Finds the degrees of freedom for a one-sample, paired, pooled or Welch t test, a chi-square goodness-of-fit or independence test, or a one-way ANOVA.",
  "category": "statistics",
  "subcategory": "tests",
  "url": "https://www.acalculator.org/statistics/degrees-of-freedom-calculator",
  "markdown": "https://www.acalculator.org/statistics/degrees-of-freedom-calculator.md",
  "kind": "function",
  "method": "t: n − 1; pooled: n₁ + n₂ − 2; Welch: (s₁²/n₁ + s₂²/n₂)² ÷ [(s₁²/n₁)²/(n₁ − 1) + (s₂²/n₂)²/(n₂ − 1)]; goodness of fit: k − (parameters + 1); table: (r − 1)(c − 1); ANOVA: k − 1 and N − k.",
  "assumptions": [
    "Welch’s degrees of freedom are not rounded; tables and some software round them down.",
    "For goodness of fit, k counts the non-empty categories, and the parameters are those estimated from the data.",
    "For a paired t test, n is the number of pairs."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "test": {
        "title": "Test",
        "description": "The statistical test you are running.",
        "type": "string",
        "enum": [
          "one",
          "paired",
          "pooled",
          "welch",
          "gof",
          "table",
          "anova"
        ]
      },
      "n": {
        "title": "Sample size (n)",
        "description": "How many values (or pairs, for a paired test) there are.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "n1": {
        "title": "Sample 1 size (n₁)",
        "description": "How many values are in sample 1.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "n2": {
        "title": "Sample 2 size (n₂)",
        "description": "How many values are in sample 2.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "s1": {
        "title": "Sample 1 standard deviation",
        "description": "The sample 1 standard deviation, greater than 0.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1e+300
      },
      "s2": {
        "title": "Sample 2 standard deviation",
        "description": "The sample 2 standard deviation, greater than 0.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1e+300
      },
      "k": {
        "title": "Categories (k)",
        "description": "How many non-empty categories (cells) there are.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "m": {
        "title": "Estimated parameters",
        "description": "How many parameters of the expected distribution you estimated from the data (0 when it was given in advance).",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000
      },
      "r": {
        "title": "Rows (r)",
        "description": "How many rows the contingency table has.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000
      },
      "c": {
        "title": "Columns (c)",
        "description": "How many columns the contingency table has.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000
      },
      "groups": {
        "title": "Groups (k)",
        "description": "How many groups are compared.",
        "type": "integer",
        "minimum": 2,
        "maximum": 1000000000
      },
      "total": {
        "title": "Total values (N)",
        "description": "How many values there are in all groups together.",
        "type": "integer",
        "minimum": 3,
        "maximum": 1000000000
      }
    }
  },
  "outputs": {
    "df": {
      "label": "Degrees of freedom",
      "description": "The degrees of freedom of the test statistic (between groups, for ANOVA).",
      "format": "number"
    },
    "within": {
      "label": "df within groups",
      "description": "N − k, the second degrees of freedom of the ANOVA F statistic.",
      "format": "integer"
    },
    "totalDf": {
      "label": "df total",
      "description": "N − 1 for the ANOVA.",
      "format": "integer"
    },
    "pooled": {
      "label": "Pooled df (equal variances)",
      "description": "n₁ + n₂ − 2, for comparison with Welch’s value.",
      "format": "integer"
    },
    "formula": {
      "label": "Formula",
      "description": "The formula with your numbers in it.",
      "format": "text"
    },
    "summary": {
      "label": "In words",
      "description": "The test and its degrees of freedom.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "test": "one",
      "n": 10,
      "n1": 12,
      "n2": 15,
      "s1": 4,
      "s2": 9,
      "k": 6,
      "m": 0,
      "r": 3,
      "c": 4,
      "groups": 3,
      "total": 15
    },
    "outputs": {
      "df": 9,
      "formula": "n − 1 = 10 − 1 = 9",
      "summary": "A one-sample t test with n = 10 has 9 degrees of freedom."
    },
    "text": "A one-sample t test with n = 10 has 9 degrees of freedom."
  },
  "examples": [
    {
      "given": {
        "test": "one",
        "n": 10
      },
      "expect": {
        "df": 9
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.2 Confidence Limits for the Mean (t with N − 1 degrees of freedom), https://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm (retrieved 2026-10-02)"
    },
    {
      "given": {
        "test": "pooled",
        "n1": 249,
        "n2": 79
      },
      "expect": {
        "df": 326
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-Sample t-Test for Equal Means (ν = N₁ + N₂ − 2 for equal variances; the Welch–Satterthwaite ν otherwise; N₁ = 249, N₂ = 79 gives ν = 326), https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm (retrieved 2026-10-02)"
    },
    {
      "given": {
        "test": "welch",
        "n1": 249,
        "n2": 79,
        "s1": 6.4147,
        "s2": 6.10771
      },
      "expect": {
        "df": 136.8749900936937,
        "pooled": 326
      },
      "source": "hand calculation in content.mdx: s₁²/n₁ = 0.165255, s₂²/n₂ = 0.472204; NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-Sample t-Test for Equal Means (ν = N₁ + N₂ − 2 for equal variances; the Welch–Satterthwaite ν otherwise; N₁ = 249, N₂ = 79 gives ν = 326), https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm (retrieved 2026-10-02); Python 3"
    },
    {
      "given": {
        "test": "gof",
        "k": 6,
        "m": 2
      },
      "expect": {
        "df": 3
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.15 Chi-Square Goodness-of-Fit Test (k − c degrees of freedom, k non-empty cells, c = estimated parameters + 1), https://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm (retrieved 2026-10-02)"
    },
    {
      "given": {
        "test": "table",
        "r": 3,
        "c": 4
      },
      "expect": {
        "df": 6
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §7.4.5 How can we compare the results of classifying according to several categories? ((r − 1)(c − 1) for r rows and c columns), https://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm (retrieved 2026-10-02)"
    },
    {
      "given": {
        "test": "anova",
        "groups": 3,
        "total": 15
      },
      "expect": {
        "df": 2,
        "within": 12,
        "totalDf": 14
      },
      "source": "NIST/SEMATECH e-Handbook of Statistical Methods, §7.4.3.4 One-way ANOVA calculations (k − 1 for treatments, N − k for error), https://www.itl.nist.gov/div898/handbook/prc/section4/prc434.htm (retrieved 2026-10-02)"
    }
  ],
  "sources": [
    "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.2 Confidence Limits for the Mean (the t distribution with N − 1 degrees of freedom). https://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm (retrieved 2026-10-02)",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-Sample t-Test for Equal Means (ν = N₁ + N₂ − 2 for equal variances, the Welch–Satterthwaite ν for unequal ones; the car example with N₁ = 249, N₂ = 79 and ν = 326). https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm (retrieved 2026-10-02)",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.15 Chi-Square Goodness-of-Fit Test (k − c degrees of freedom). https://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm (retrieved 2026-10-02)",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §7.4.5 How can we compare the results of classifying according to several categories? ((r − 1)(c − 1) for a contingency table). https://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm (retrieved 2026-10-02)",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §7.4.3.4 One-way ANOVA calculations (k − 1 and N − k degrees of freedom). https://www.itl.nist.gov/div898/handbook/prc/section4/prc434.htm (retrieved 2026-10-02)"
  ],
  "related": [
    "t-test",
    "chi-square",
    "anova",
    "critical-value"
  ],
  "changelog": []
}
