chi2inv in Python

Question:

What is the corresponding function for calculating the inverse chi squared distribution in python? In MATLAB, for example, a 95% confidence interval with n degrees of freedom is given by

chi2inv(0.95, n)
Asked By: Luke Polson

||

Answers:

from scipy.stats.distributions import chi2
chi2.ppf(0.975, df=2)

7.377758908227871

octave:4> chi2inv(0.975,2)
ans =  7.3778
Answered By: cel

Additional information to the current answer:

chi2.ppf and chi2.cdf are inverse of each-other:

from scipy.stats.distributions import chi2
chi2.ppf(0.95, df=5)     # 11.07
chi2.cdf(11.07, df=5)    # 0.95
Answered By: Basj

This command from the Statistics Toolbox in Matlab:

upperv=chi2inv(1-alpha/2,nu);

is identical to this one from the scipy library:

from scipy import stats
upperv=stats.chi2.isf(1-alpha/2,nu)
Answered By: Tom F
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.