{
  "schemaVersion": 1,
  "slug": "confidence-interval-calculator",
  "category": "statistics",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "12ef34df4ca8afa7fca11416844683d70c99327c65b4ae3a50f39abe33d28b2a",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/confidence-interval-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "CI = x̄ ± t* × s ÷ √n",
    "vars": [
      [
        "x̄",
        "sample mean"
      ],
      [
        "s",
        "standard deviation"
      ],
      [
        "n",
        "sample size"
      ],
      [
        "t*",
        "critical value"
      ],
      [
        "CI",
        "confidence interval"
      ]
    ],
    "note": "Two-sided Student t confidence interval for a mean: mean ± t* × s/√n. Assumes independent observations and approximate normality, especially for small samples; confidence describes long-run coverage of the method."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const empty={interval:null,lower:null,upper:null,intervalWidth:null,marginOfError:null,standardError:null,criticalValue:null};const m=Number(mean),sigma=Number(sd),n=Number(sampleSize),cl=Number(confidence);const Z={80:1.2816,90:1.6449,95:1.96,98:2.3263,99:2.5758};if(![m,sigma,n,cl].every(Number.isFinite)||sigma<0||!Number.isInteger(n)||n<2||n>10000000||!Object.hasOwn(Z,cl))return{...empty,__error:'inputError'};const z=Z[cl],df=n-1,exactT={1:{80:3.0777,90:6.3138,95:12.7062,98:31.8205,99:63.6567},2:{80:1.8856,90:2.92,95:4.3027,98:6.9646,99:9.9248},3:{80:1.6377,90:2.3534,95:3.1824,98:4.5407,99:5.8409},4:{80:1.5332,90:2.1318,95:2.7764,98:3.7469,99:4.6041},5:{80:1.4759,90:2.015,95:2.5706,98:3.3649,99:4.0321},6:{80:1.4398,90:1.9432,95:2.4469,98:3.1427,99:3.7074},7:{80:1.4149,90:1.8946,95:2.3646,98:2.9979,99:3.4995},8:{80:1.3968,90:1.8595,95:2.306,98:2.8965,99:3.3554},9:{80:1.383,90:1.8331,95:2.2622,98:2.8214,99:3.2498},10:{80:1.3722,90:1.8125,95:2.2281,98:2.7638,99:3.1693}};let critical=exactT[df]?.[cl];if(critical===undefined){const nu=df,z2=z*z,z3=z2*z,z5=z3*z2,z7=z5*z2,z9=z7*z2;critical=z+(z3+z)/(4*nu)+(5*z5+16*z3+3*z)/(96*nu**2)+(3*z7+19*z5+17*z3-15*z)/(384*nu**3)+(79*z9+776*z7+1482*z5-1920*z3-945*z)/(92160*nu**4);}const se=sigma/Math.sqrt(n),me=critical*se;return{interval:(m-me)+\" / \"+(m+me),lower:m-me,upper:m+me,intervalWidth:2*me,marginOfError:me,standardError:se,criticalValue:critical};",
    "inputs": [
      {
        "name": "mean",
        "type": "number",
        "default": 100,
        "min": -1000000,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "sd",
        "type": "number",
        "default": 15,
        "step": 0.01
      },
      {
        "name": "sampleSize",
        "type": "number",
        "default": 100,
        "step": 1
      },
      {
        "name": "confidence",
        "type": "select",
        "default": 95,
        "options": [
          {
            "value": 80
          },
          {
            "value": 90
          },
          {
            "value": 95
          },
          {
            "value": 98
          },
          {
            "value": 99
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "interval",
        "type": "text",
        "range": true,
        "precision": 3,
        "unit": ""
      },
      {
        "name": "lower",
        "precision": 3,
        "unit": ""
      },
      {
        "name": "upper",
        "precision": 3,
        "unit": ""
      },
      {
        "name": "intervalWidth",
        "precision": 3,
        "unit": ""
      },
      {
        "name": "marginOfError",
        "precision": 3,
        "unit": ""
      },
      {
        "name": "standardError",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "criticalValue",
        "precision": 4,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
