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)
Answers:
from scipy.stats.distributions import chi2
chi2.ppf(0.975, df=2)
7.377758908227871
octave:4> chi2inv(0.975,2)
ans = 7.3778
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
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)
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)
from scipy.stats.distributions import chi2
chi2.ppf(0.975, df=2)
7.377758908227871
octave:4> chi2inv(0.975,2)
ans = 7.3778
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
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)