简体   繁体   中英

How to find the critical values of chi-square distribution in python?

I want to calculate the interval estimate of the population standard deviation, for this i need the chi-square critical values for the lower and upper bound. The formula to calculate is this -

公式

To calculate it, i did this -

# variance
var = halloween['Dollars Spent'].var()
# (n-1) degrees of freedom
deg_fred = (halloween.shape[0] - 1)
lower_bound = np.sqrt((deg_fred*var)/ 27.488)
upper_bound = np.sqrt((deg_fred*var)/ 6.262)
(lower_bound, upper_bound)
(17.37, 36.40)

The critical values of chi-square distribution for the lower and upper bound are 27.488 and 6.262 . I find these values using the chi-square distribution table. How can i calculate these values in python rather than calculating it from a table which doesn't give us exact values all the time and it is not helpful if i want to write a function to calculate it.

Using isf() method

import scipy as sp
sp.stats.chi2.isf(0.1, 20, loc=0, scale=1) # P=10%, df=20
# donne 28.412... as in books table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM