-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenerate_chi_square.py
46 lines (34 loc) · 1.42 KB
/
generate_chi_square.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Use this script to generate critical chi-square values.
For each number of degrees of freedom, there is a critical value.
Therefore, the output is a list of chi-square values.
These values additionally depend on the so-called significance level.
You can adjust both parameters below; then run the main method.
You need scipy to run this script!
"""
from scipy.stats import chi2
import meta
import os
degrees_freedom = range(1, 10000)
"""
Range of degrees of freedom.
Distributions with many different values (bins) have many degrees of freedom.
From 1 to any positive integer.
"""
significance = 0.05
"""
Significance level.
Probability of rejecting the null hypothesis when it is in fact true (false negative).
A lower significance level means you are conservative
and require more evidence before rejecting the null hypothesis.
This increases the number of true positives and of false positives.
A higher significance level means you are lenient
and require less evidence before rejecting the null hypothesis.
This increases the number true negatives and of false negatives.
From 0 to 1.
"""
chi_squared_values = [chi2.ppf(1 - significance, df) for df in degrees_freedom]
chi_squared_fmt = "({})".format(", ".join(["{:0.2f}".format(x) for x in chi_squared_values]))
pattern = lambda x: f"CRITICAL_CHI_SQUARE_VALUES = {x}"
updated_value = chi_squared_fmt
meta.update_variable(os.path.join("local", "stats.py"), pattern, updated_value)