{
  "schemaVersion": 1,
  "slug": "p-value-calculator",
  "category": "statistics",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "1ef8c86a879561faf9910a9c2ffad4e8eb15c961321b93f3f3c9fdb8f907f21e",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/p-value-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": "z = (x − m0) ÷ (s ÷ √(n)); p_upper = 1 − Φ(z); p_lower = Φ(z); p_two = 2 × [1 − Φ(|z|)]; Φ(z) = 0.5 × [1 + erf(z ÷ √(2))]",
    "vars": [
      [
        "x",
        "Sample mean"
      ],
      [
        "m0",
        "Hypothesised mean"
      ],
      [
        "s",
        "Population standard deviation"
      ],
      [
        "n",
        "Sample size"
      ],
      [
        "N",
        "Standard normal CDF"
      ]
    ],
    "note": "Computes a one-sample z statistic (sample mean − null mean)/(known SD/√n) and normal-tail probabilities. Sample size must be an integer. This assumes independent observations and a known population SD; it is not a t-test."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-12",
    "sources": [
      {
        "name": "NIST — Normal, t and chi-square distribution definitions",
        "url": "https://www.itl.nist.gov/div898/handbook/eda/section3/eda366.htm"
      }
    ],
    "referenceRole": "definition",
    "implementationHash": "1ef8c86a879561faf9910a9c2ffad4e8eb15c961321b93f3f3c9fdb8f907f21e",
    "basis": "z = (x − m0) ÷ (s ÷ √(n)); p_upper = 1 − Φ(z); p_lower = Φ(z); p_two = 2 × [1 − Φ(|z|)]; Φ(z) = 0.5 × [1 + erf(z ÷ √(2))]",
    "limitations": "The references explain definitions and methods; any extra preset must be checked against the assumptions on this page."
  },
  "contract": {
    "compute": "if(!Number.isInteger(sampleSize))return{pValue:null,zScore:null,oneTailedP:null,twoTailedP:null,standardError:null,__error:'inputError'};const erf=x=>{const s=x<0?-1:1,ax=Math.abs(x),t=1/(1+.3275911*ax),y=1-((((1.061405429*t-1.453152027)*t+1.421413741)*t-.284496736)*t+.254829592)*t*Math.exp(-ax*ax);return s*y},cdf=x=>.5*(1+erf(x/Math.SQRT2)),se=sd/Math.sqrt(sampleSize),z=(sampleMean-nullMean)/se,upper=1-cdf(z),lower=cdf(z),two=Math.min(1,2*(1-cdf(Math.abs(z)))),one=alternative==='less'?lower:upper,p=Number(tails)===1?one:two;return{pValue:Math.min(1,Math.max(0,p)),zScore:z,oneTailedP:Math.min(1,Math.max(0,one)),twoTailedP:two,standardError:se};",
    "inputs": [
      {
        "name": "sampleMean",
        "type": "number",
        "default": 102,
        "min": -1000000,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "nullMean",
        "type": "number",
        "default": 100,
        "min": -1000000,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "sd",
        "type": "number",
        "default": 15,
        "min": 0.0001,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "sampleSize",
        "type": "number",
        "default": 30,
        "min": 2,
        "max": 10000000,
        "step": 1
      },
      {
        "name": "tails",
        "type": "select",
        "default": 2,
        "options": [
          {
            "value": 1
          },
          {
            "value": 2
          }
        ]
      },
      {
        "name": "alternative",
        "type": "select",
        "default": "greater",
        "options": [
          {
            "value": "greater"
          },
          {
            "value": "less"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "pValue",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "zScore",
        "precision": 3,
        "unit": ""
      },
      {
        "name": "oneTailedP",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "twoTailedP",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "standardError",
        "precision": 4,
        "unit": ""
      }
    ],
    "interpret": [
      {
        "max": 0.01,
        "key": "pVeryStrong"
      },
      {
        "max": 0.05,
        "key": "pSignificant"
      },
      {
        "max": 0.1,
        "key": "pWeak"
      },
      {
        "max": null,
        "key": "pNotSignificant"
      }
    ]
  }
}
