I work with the following two test contingency tables (observed1, observed2) with these resulting variables:
observed1 = [[388,51692],[119,45633]]
expected1 = [[269.8969662278191, 51810.10303377218], [237.10303377218088, 45514.89696622782]]
chi_score1 = 111.0839904758887
df1 = 1
observed2 = [[388,51692],[119,45633],[271,40040]]
expected2 = [[293.3065012342283, 51786.69349876577], [257.66818441759625, 45494.3318155824], [227.02531434817544, 40083.974685651825]]
chi_score2 = 114.36002831520479
df2 = 2
When calculated with Python, I get the following results when extracting the pvalue (replace observed with observed1 or observed2):
import scipy.stats as stats
# include above variables here
X2 = stats.chi2_contingency(observed, correction=False)[0]
# observed1 => pvalue = 5.671618200219206e-26
# observed2 => pvalue = 1.469045936431957e-25
When using Distribution::ChiSquared.cumulative_function from the ruby-statistics package, I get the following results (replace dfwith df1or df2, chi_score likewise):
probability = 1.0 - Statistics::Distribution::ChiSquared.new(df).cumulative_function(chi_score)
p_value = 1.0 - probability
# observed1 => p_value = Infinity
# observed2 => p_value = 1.0000333200206515
While I cannot confirm the Python module yields the correct values, it seems more plausible, considering that the p-value should be in the range [0..1]?
I work with the following two test contingency tables (
observed1,observed2) with these resulting variables:When calculated with Python, I get the following results when extracting the
pvalue(replaceobservedwithobserved1orobserved2):When using
Distribution::ChiSquared.cumulative_functionfrom theruby-statisticspackage, I get the following results (replacedfwithdf1ordf2,chi_scorelikewise):While I cannot confirm the Python module yields the correct values, it seems more plausible, considering that the p-value should be in the range [0..1]?