{
  "id": "confidence-interval",
  "version": "2bd0e5bbfbbc",
  "status": "published",
  "name": "Confidence Interval Calculator",
  "question": "What is the confidence interval?",
  "summary": "Computes a confidence interval for a population mean (t or z) or a population proportion at any confidence level, with the margin of error and standard error.",
  "category": "statistics",
  "subcategory": "tests",
  "url": "https://www.acalculator.org/statistics/confidence-interval-calculator",
  "markdown": "https://www.acalculator.org/statistics/confidence-interval-calculator.md",
  "kind": "function",
  "method": "Mean: x̄ ± t × s ÷ √n with n − 1 degrees of freedom (or z × σ ÷ √n for a known σ). Proportion: p̂ ± z × √(p̂(1 − p̂) ÷ n). The critical value has an upper tail of (1 − confidence) ÷ 2.",
  "assumptions": [
    "The sample is random, and the sample mean is roughly normal (the data are close to normal or n is large).",
    "The proportion interval is the normal-approximation (Wald) interval; it works best when at least 5 successes and 5 failures are counted. Its limits are cut to 0 and 1."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "type": {
        "title": "Interval for a",
        "description": "A mean (from a sample mean and standard deviation) or a proportion (from a count of successes).",
        "type": "string",
        "enum": [
          "mean",
          "proportion"
        ]
      },
      "mean": {
        "title": "Sample mean (x̄)",
        "description": "The mean of your sample.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      },
      "sd": {
        "title": "Standard deviation",
        "description": "The sample standard deviation, or the population standard deviation σ when it is known.",
        "type": "number",
        "exclusiveMinimum": 0,
        "maximum": 1000000000000
      },
      "method": {
        "title": "Standard deviation is",
        "description": "The sample standard deviation (use the t distribution) or the known population standard deviation σ (use the normal z).",
        "type": "string",
        "enum": [
          "t",
          "z"
        ]
      },
      "x": {
        "title": "Successes (x)",
        "description": "How many in the sample have the trait, from 0 to the sample size.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000
      },
      "n": {
        "title": "Sample size (n)",
        "description": "How many observations are in the sample.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000000000
      },
      "cl": {
        "title": "Confidence level",
        "description": "How confident the interval is, in percent: 95 for a 95% confidence interval.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 1,
        "maximum": 99.9999
      }
    }
  },
  "outputs": {
    "margin": {
      "label": "Margin of error (±)",
      "description": "The critical value times the standard error: the interval is the estimate plus or minus this.",
      "format": "number"
    },
    "lower": {
      "label": "Lower limit",
      "description": "The estimate minus the margin of error.",
      "format": "number"
    },
    "upper": {
      "label": "Upper limit",
      "description": "The estimate plus the margin of error.",
      "format": "number"
    },
    "estimate": {
      "label": "Estimate",
      "description": "The sample mean, or the sample proportion p̂ = x ÷ n.",
      "format": "number"
    },
    "se": {
      "label": "Standard error",
      "description": "s ÷ √n for a mean, or √(p̂(1 − p̂) ÷ n) for a proportion.",
      "format": "number"
    },
    "critical": {
      "label": "Critical value",
      "description": "The t (n − 1 degrees of freedom) or z value with an upper tail of (1 − confidence) ÷ 2.",
      "format": "number"
    },
    "caution": {
      "label": "Caution",
      "description": "Shown for a proportion with fewer than 5 successes or 5 failures, when the interval is rough.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "type": "mean",
      "mean": 68,
      "sd": 3,
      "method": "t",
      "x": 27,
      "n": 36,
      "cl": 95
    },
    "outputs": {
      "margin": 1.01505396412517,
      "lower": 66.98494603587483,
      "upper": 69.01505396412517,
      "estimate": 68,
      "se": 0.5,
      "critical": 2.03010792825034
    },
    "text": "The 95% confidence interval is 66.984946 to 69.015054 (68 ± 1.015054)."
  },
  "examples": [
    {
      "given": {
        "type": "mean",
        "mean": 68,
        "sd": 3,
        "method": "t",
        "n": 36,
        "cl": 95
      },
      "expect": {
        "critical": 2.030107928250343,
        "margin": 1.0150539641251715,
        "lower": 66.98494603587483,
        "upper": 69.01505396412517
      },
      "source": "hand calculation in content.mdx: t = 2.030108 with 35 df, 2.030108 × 3 ÷ 6 = 1.015054; 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"
    },
    {
      "given": {
        "type": "mean",
        "mean": 68,
        "sd": 3,
        "method": "z",
        "n": 36,
        "cl": 90
      },
      "expect": {
        "critical": 1.6448536269514729,
        "margin": 0.8224268134757364,
        "lower": 67.17757318652427,
        "upper": 68.82242681347573
      },
      "source": "OpenStax, Introductory Statistics 2e, §8.1 A Single Population Mean using the Normal Distribution. https://openstax.org/books/introductory-statistics-2e/pages/8-1-a-single-population-mean-using-the-normal-distribution, Example 8.2 (z = 1.645, EBM = 0.8225, interval 67.18 to 68.82)"
    },
    {
      "given": {
        "type": "mean",
        "mean": 9.26146,
        "sd": 0.022789,
        "method": "t",
        "n": 195,
        "cl": 95
      },
      "expect": {
        "lower": 9.258241349743406,
        "upper": 9.264678650256593
      },
      "source": "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 (95% interval 9.258242 to 9.264679)",
      "tolerance": 1e-12
    },
    {
      "given": {
        "type": "proportion",
        "x": 421,
        "n": 500,
        "cl": 95
      },
      "expect": {
        "estimate": 0.842,
        "lower": 0.8100296288520179,
        "upper": 0.873970371147982
      },
      "source": "OpenStax, Introductory Statistics 2e, §8.3 A Population Proportion. https://openstax.org/books/introductory-statistics-2e/pages/8-3-a-population-proportion, Example 8.10 (p′ = 0.842, interval 0.810 to 0.874)"
    },
    {
      "given": {
        "type": "proportion",
        "x": 300,
        "n": 500,
        "cl": 90
      },
      "expect": {
        "estimate": 0.6,
        "margin": 0.03603693741102037
      },
      "source": "OpenStax, Introductory Statistics 2e, §8.3 A Population Proportion. https://openstax.org/books/introductory-statistics-2e/pages/8-3-a-population-proportion, Example 8.11 (EBP = 0.036, interval 0.564 to 0.636)"
    }
  ],
  "sources": [
    "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, §8.1 A Single Population Mean using the Normal Distribution. https://openstax.org/books/introductory-statistics-2e/pages/8-1-a-single-population-mean-using-the-normal-distribution",
    "OpenStax, Introductory Statistics 2e, §8.3 A Population Proportion. https://openstax.org/books/introductory-statistics-2e/pages/8-3-a-population-proportion"
  ],
  "related": [
    "sample-size",
    "t-test",
    "normal-distribution",
    "z-score"
  ],
  "changelog": []
}
