Last active
October 27, 2023 19:57
-
-
Save MIKEk8/279ecc53a07a7fb17f9eeebe4e86fc1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.stats import chi2 | |
def chi2_test_for_dice(observations): | |
# Рассчет количества граней и общего числа бросков | |
num_faces = len(observations) | |
total_throws = sum(observations) | |
# Ожидаемые частоты (равномерное распределение) | |
expected_frequencies = [total_throws/num_faces] * num_faces | |
# Рассчет статистики хи-квадрат | |
chi2_stat = sum([(obs - exp)**2 / exp for obs, exp in zip(observations, expected_frequencies)]) | |
# Рассчитываем p-значение (num_faces - 1 степеней свободы) | |
p_value = 1 - chi2.cdf(chi2_stat, num_faces - 1) | |
return chi2_stat, p_value | |
# Наблюдаемые частоты выпадений каждой грани | |
observed_frequencies = [3, 1, 2, 1, 2, 1] | |
chi2_value, p_val = chi2_test_for_dice(observed_frequencies) | |
print(f"Значение хи-квадрат: {chi2_value}") | |
print(f"p-значение: {p_val}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment