Мой пример набора данных:
Код: Выделить всё
# Observed data
observed = np.array([[150, 700], [350, 150]])
# Perform the chi-square test
chi2, p, dof, expected = chi2_contingency(observed)
# Print the results
print(f"Chi2 Statistic: {chi2}")
print(f"P-value: {p}")
print(f"Degrees of Freedom: {dof}")
print("Expected Frequencies:")
print(expected)
Код: Выделить всё
# Results
Chi2 Statistic: 367.7704987889273
P-value: 5.723076338262742e-82
Degrees of Freedom: 1
Expected Frequencies:
[[314.81481481 535.18518519]
[185.18518519 314.81481481]]
Я пытался обойти вычисления, но даже в этом подходе значение p сравнивается с пороговым значением апостериорно.
Код: Выделить всё
from scipy.stats import chi2, chi2_contingency
# Observed data
observed = np.array([[150, 700], [350, 150]])
# Perform the chi-square test
chi2_stat, p_value, dof, expected = chi2_contingency(observed)
# Set your threshold (for example, 0.01)
threshold = 0.01
# Check if p-value is below the threshold
if p_value < threshold:
print(f'P-value is extremely small (
Подробнее здесь: [url]https://stackoverflow.com/questions/79073790/threshold-at-chi2-cdf-below-of-which-it-doesn-t-warrant-the-use-of-computatio[/url]