Statistics/Chi-squared distribution: Difference between revisions

Content added Content deleted
No edit summary
Line 292: Line 292:
from math import gamma, exp
from math import gamma, exp
from scipy.special import gammainc
from scipy.special import gammainc
from matplotlib.pyplot import plot, legend, ylim



def χ2(x, k):
def χ2(x, k):
Line 331: Line 331:
print(
print(
f'\nFor the airport data, diff total is {DTOTAL}, χ2 is {χ2(DTOTAL, 3)}, p value {cdf_χ2(DTOTAL, 3)}')
f'\nFor the airport data, diff total is {DTOTAL}, χ2 is {χ2(DTOTAL, 3)}, p value {cdf_χ2(DTOTAL, 3)}')
X = [x * 0.001 for x in range(10000)]
for k in range(5):
plot(X, [χ2(p, k) for p in X])
legend([0, 1, 2, 3, 4])
ylim(-0.02, 0.5)
</syntaxhighlight>{{out}}
</syntaxhighlight>{{out}}
[[File:Pyplotofchisquared.png|thumb|center]]
<pre>
<pre>
x χ2 k = 1 k = 2 k = 3 k = 4 k = 5
x χ2 k = 1 k = 2 k = 3 k = 4 k = 5