P-Value Calculator

Instantly compute exact p-values for Z, t, and chi-squared tests — with formula working shown.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

A p-value calculator that covers the three workhorses of inferential statistics: the Z-test (standard normal distribution), Student’s t-test (t-distribution), and the chi-squared test (χ²-distribution). Paste in your test statistic, set the degrees of freedom and tail type, and get the exact p-value with the full formula working shown — no look-up tables, no Excel, no Python needed. Everything runs in your browser; no numbers are sent anywhere.

How the maths works

Z-test (standard normal)

The Z-test applies when you know the population standard deviation or have a large enough sample that the central limit theorem makes the normal approximation valid. The standard normal CDF Φ(z) is:

Φ(z) = ½ · (1 + erf(z / √2))

where erf is the error function. The tool evaluates erf via the Horner-form polynomial approximation from Abramowitz & Stegun (equation 7.1.26), accurate to within 1.5 × 10⁻⁷.

  • Two-tailed: p = 2 · min(Φ(z), 1 − Φ(z))
  • Right-tailed: p = 1 − Φ(z)
  • Left-tailed: p = Φ(z)

t-test (Student’s t-distribution)

When the population variance is unknown and estimated from the sample, the t-distribution with df degrees of freedom is appropriate. Its CDF is expressed via the regularised incomplete beta function:

P(T ≤ t | df) = 1 − ½ · I_{df/(df+t²)}(df/2, 1/2)

The incomplete beta function is evaluated via Lentz’s continued-fraction algorithm (Numerical Recipes §6.4) with the symmetry relation applied when x > (a+1)/(a+b+2) for better convergence. As df → ∞ the t-distribution converges to the standard normal, so the p-values also converge.

Chi-squared test (χ²-distribution)

The chi-squared statistic with k degrees of freedom follows a distribution whose CDF is the regularised lower incomplete gamma function:

P(χ² ≤ x | k) = γ(k/2, x/2) / Γ(k/2) = P(k/2, x/2)

The p-value is the right-tail area: p = 1 − P(k/2, x/2). The tool evaluates γ via a series expansion when x < a+1 and via a continued fraction otherwise, using the log-Gamma function (Lanczos approximation, g=7) for numerical stability.

Worked example — t-test

A nutritionist measures the daily calorie intake for a sample of 20 adults and reports a sample mean of 2,150 kcal. The assumed population mean is 2,000 kcal and the sample standard deviation is 320 kcal. The one-sample t-statistic is:

t = (x̄ − μ₀) / (s / √n) = (2150 − 2000) / (320 / √20) = 150 / 71.55 ≈ 2.096

With df = 19, the two-tailed p-value is approximately 0.050 — right on the conventional threshold. Entering t = 2.096, df = 19, two-tailed into the calculator reproduces this.

ScenariotdfTailp-valueSignificant at 5%?
Nutrition study (above)2.09619Two0.0499Yes (barely)
Drug efficacy3.2130Two0.0031Yes
Exam score increase1.4514Right0.0841No
Height difference−2.5825Left0.0080Yes

Formula note — why these algorithms?

Direct numerical evaluation of these CDFs requires special functions (erf, incomplete beta, incomplete gamma) that are not built in to JavaScript. The implementations here follow standard numerical analysis references:

  • erf: Abramowitz & Stegun 7.1.26 — five-coefficient Horner polynomial, max error < 1.5 × 10⁻⁷.
  • Incomplete beta: Lentz continued fraction (Numerical Recipes §6.4) — the standard approach in scientific computing libraries including SciPy.
  • Log-Gamma: Lanczos approximation with g = 7, accurate to ~15 significant figures.

All three algorithms are validated against the worked examples in this page and against R’s pt(), pnorm(), and pchisq() functions.

Ad placeholder (rectangle)