2
votes

I wanted to calculate the probability associated to a given chi-squared value for any given number of degrees of freedom k. I could easily come up with this code:

P[chisquare_, k_] = Manipulate[NIntegrate[PDF[ChiSquareDistribution[k], x], {x, chisquare, Infinity}], {chisquare, 0, 10}, {k, 1, 10}]

but I was wondering: is there any way to do the opposite? I mean having the probability P as an input and getting the associated chi squared value? like if I wanted to compile a chi-squared table such as this https://www.medcalc.org/manual/chi-square-table.php

I tried using Solve but did not accomplish anything, is there an easy way around this?

1
Note there is a Stack Exchange group specifically for Mathematica : mathematica.stackexchange.comChris Degnen

1 Answers

1
votes

You can do the integration with CFD and reverse with Quantile, e.g.

NIntegrate[PDF[ChiSquareDistribution[2], a], {a, 0, 3.0}]

0.77687

p = CDF[ChiSquareDistribution[2], 3.0]

0.77687

Quantile[ChiSquareDistribution[2], p]

Re. your link

enter image description here

Quantile[ChiSquareDistribution[2], 1 - #] & /@ {0.995, 0.975, 0.20, 0.10, 0.05};
SetPrecision[#, If[# < 1, 3, 4]] & /@ %

{0.0100, 0.0506, 3.219, 4.605, 5.991}