Friday, September 21, 2012

Chi-squared distribution table with sigma values

The table below gives values for the χ²-distribution at key credible intervals (Bayesian confidence intervals) and sigma values (σ, standard deviations). I could only find tables and calculators with p-values online. Shown are the well-used 1σ, 2σ, and 3σ values along with typical confidence intervals such as 90%, 99% and 99.9%. The parameter "k" represents the number of degrees of freedom.

Sigma 1σ 1.28 1.64 1.96 2σ 2.58 3σ 3.29 4σ
CI % 68.3% 80% 90% 95% 95.45% 99% 99.73% 99.9% 99.99%
P-value 0.317 0.20 0.10 0.05 0.0455 0.01 0.0027 0.001 0.00006
chi2(k=1) 1.00 1.64 2.71 3.84 4.00 6.63 9.00 10.83 16.00
chi2(k=2) 2.30 3.22 4.61 5.99 6.18 9.21 11.83 13.82 19.33
chi2(k=3) 3.53 4.64 6.25 7.81 8.02 11.34 14.16 16.27 22.06
chi2(k=4) 4.72 5.99 7.78 9.49 9.72 13.28 16.25 18.47 24.50
chi2(k=5) 5.89 7.29 9.24 11.07 11.31 15.09 18.21 20.52 26.77
chi2(k=6) 7.04 8.56 10.64 12.59 12.85 16.81 20.06 22.46 28.91
chi2(k=7) 8.18 9.80 12.02 14.07 14.34 18.48 21.85 24.32 30.96
chi2(k=8) 9.30 11.03 13.36 15.51 15.79 20.09 23.57 26.12 32.93
chi2(k=9) 10.42 12.24 14.68 16.92 17.21 21.67 25.26 27.88 34.85
chi2(k=10) 11.54 13.44 15.99 18.31 18.61 23.21 26.90 29.59 36.72

The Python script used to generate this table is below. It uses the percentage point function (ppf) and cumulative distribution functions (cdf) from the scipy.stats.chi2 distribution in the SciPy stats library:

#!/usr/bin/python
import scipy.stats
import math

#stand deviations to calculate
sigma = [   1.0,
            math.sqrt(scipy.stats.chi2.ppf(0.8,1)),
            math.sqrt(scipy.stats.chi2.ppf(0.9,1)),
            math.sqrt(scipy.stats.chi2.ppf(0.95,1)),
            2.0,
            math.sqrt(scipy.stats.chi2.ppf(0.99,1)),
            3.0,
            math.sqrt(scipy.stats.chi2.ppf(0.999,1)),
            4.0   ]

#confidence intervals these sigmas represent:
conf_int = [ scipy.stats.chi2.cdf( s**2,1) for s in sigma ]

#degrees of freedom to calculate
dof = range(1,11)

print "sigma     \t" + "\t".join(["%1.2f"%(s) for s in sigma])
print "conf_int  \t" + "\t".join(["%1.2f%%"%(100*ci) for ci in conf_int])
print "p-value   \t" + "\t".join(["%1.5f"%(1-ci) for ci in conf_int])

for d in dof:
    chi_squared = [ scipy.stats.chi2.ppf( ci, d) for ci in conf_int ]
    print "chi2(k=%d)\t"%d + "\t".join(["%1.2f" % c for c in chi_squared])

No comments:

Post a Comment