{"id":416855,"date":"2024-06-30T01:12:23","date_gmt":"2024-06-30T01:12:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=416855"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=416855","title":{"rendered":"<span>\u0421\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432 \u0445\u0438-\u043a\u0432\u0430\u0434\u0440\u0430\u0442: \u0447\u0442\u043e \u0443 \u043d\u0438\u0445 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0438 \u043a\u0430\u043a\u0438\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u044f\u0447\u0435\u0441\u043b\u0430\u0432 \u0417\u043e\u0442\u043e\u0432, \u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a \u0432 \u0441\u0442\u0443\u0434\u0438\u0438 Whalekit. \u0412 \u044d\u0442\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b, \u043a\u0430\u043a\u043e\u0432\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u044c <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u043e\u0432 \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0432\u043e\u0440\u043e\u043d\u043e\u043a. \u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043d\u0430 Python.<\/p>\n<p>\u0422\u0435\u0441\u0442 <em>\u03c7<\/em>\u00b2 \u2014 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u043e\u0432 \u043d\u0435\u0434\u043e\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0443. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0435\u043b\u043e\u0435 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432 <em>\u03c7<\/em>\u00b2, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u044b <em>\u03c7<\/em>\u00b2 \u0447\u0430\u0441\u0442\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0445 \u0438 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0430 \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/b96\/000\/41f\/b9600041f1c7b54a351de958b564890d.jpg\" width=\"1920\" height=\"1080\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b96\/000\/41f\/b9600041f1c7b54a351de958b564890d.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<h2>1. \u03c7\u00b2-\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a:<\/p>\n<pre><code class=\"python\">import warnings warnings.filterwarnings('ignore')  import os import math import random import re  import pandas as pd import numpy as np  import scipy.stats as stats  from matplotlib import pyplot as plt import matplotlib.ticker as mtick import seaborn as sns from matplotlib import cm import matplotlib.colors<\/code><\/pre>\n<p>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u0438 \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b:<\/p>\n<pre><code class=\"python\">np.random.seed(1234)  size = 10000 # \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 loc = 0 scale = 1  result = pd.DataFrame([[0] * size], index = ['chi2_1']).T  plt.figure(figsize = (15, 5))  # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b k for k in range(2, 22, 3):          # \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0440\u0435\u0439\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432     current_result = pd.DataFrame([[0] * size], index = [1]).T          # \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0443\u0436\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0443\u043c\u043c\u0443 \u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432     for i in range(1, k + 1): current_result[i] = pd.Series(np.random.normal(loc = loc, scale = scale, size = size))          # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0443\u043c\u043c\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432     current_result['chi2'] = (current_result * current_result).sum(axis = 1)          sns.kdeplot(current_result['chi2'], label = 'k = {}'.format(k))      plt.legend(title = '\u0421\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b'), plt.ylabel('$f_k(x)$'), plt.xlabel('$x$'), plt.title('\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f $\\chi_k^2$') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/844\/a3b\/f7c\/844a3bf7caecd7e815ed30b19124b0c9.png\" width=\"834\" height=\"304\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/844\/a3b\/f7c\/844a3bf7caecd7e815ed30b19124b0c9.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>2. \u03c7\u00b2-\u0442\u0435\u0441\u0442\u044b<\/h2>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430.<\/p>\n<ol>\n<li>\n<p>\u0422\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c (test of homogeneity, \u043e\u043d \u0436\u0435 goodness of fit) \u2014 \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439, \u043e\u0434\u043d\u043e\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e. \u0412 Python \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>scipy.stats.chisquare<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c (\u043e\u043d \u0436\u0435 test of independence\/association) \u2014 \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439, \u043e\u0434\u043d\u043e\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438. \u0412 Python \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>scipy.stats.chi2_contingency<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442 \u0434\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f), \u043e\u0434\u043d\u043e\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u043e\u0433\u0443. \u0412 Python \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0442\u0435\u0441\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u044f \u041f\u0438\u0440\u0441\u043e\u043d\u0430 (\u041a\u0421\u041f), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2. \u0422\u0440\u0435\u0442\u0438\u0439 \u0442\u0435\u0441\u0442 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0432\u0443\u043c \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442, \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2 (\u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0438\u0436\u0435).<\/p>\n<p>\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u044f \u041f\u0438\u0440\u0441\u043e\u043d\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\large\\frac{(O-E)^2}{E}\" alt=\"\\large\\frac{(O-E)^2}{E}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/880\/1a0\/756\/8801a07568141ace3d348094ca63eaee.svg\" width=\"100\" height=\"57\"\/><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c:<\/p>\n<ul>\n<li>\n<p><em>O<\/em> \u2014 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435;<\/p>\n<\/li>\n<li>\n<p><em>E <\/em>\u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u041a\u0421\u041f \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u043c \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 (\u043d\u0430\u043c \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0439, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u043a\u0442 \u0438\u0445 \u043d\u0430\u043b\u0438\u0447\u0438\u044f) \u0438 \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0435 \u0440\u043e\u0441\u043b\u0430).<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u044d\u0442\u0430\u043b\u043e\u043d\u043e\u0432, \u0442\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u041a\u0421\u041f \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0430\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\large\\sum_{i}{\\frac{(O_{i}-E_{i})^2}{E_{i}}}\" alt=\"\\large\\sum_{i}{\\frac{(O_{i}-E_{i})^2}{E_{i}}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b22\/c8c\/5d3\/b22c8c5d3d96cbef4a694832f6561bb8.svg\" width=\"153\" height=\"69\"\/><\/p>\n<p>\u0412 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 <em>O <\/em>\u0438 <em>E <\/em>\u0438\u043c\u0435\u044e\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u041a\u0421\u041f \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0435\u0441\u0442 \u0441 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>H0: \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>H1: \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043d\u0435\u0442, \u0442\u043e \u041a\u0421\u041f \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0443\u043b\u044e. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/480\/d77\/b05\/480d77b05af8a76bc3bbba25af4dc20e.png\" width=\"724\" height=\"406\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/480\/d77\/b05\/480d77b05af8a76bc3bbba25af4dc20e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u0441\u0442\u044b \u0441 \u041a\u0421\u041f, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 (\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u044e\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439) \u0438 \u043e\u0434\u043d\u043e\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 (\u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u2014 \u0432\u043e\u0442<a href=\"https:\/\/stats.stackexchange.com\/questions\/171074\/chi-square-test-why-is-the-chi-squared-test-a-one-tailed-test\"> <u>\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f<\/u><\/a> \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u0441\u0442 \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0441 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c (\u0431\u0435\u0437 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u043c\u0435\u0449\u0435\u043d\u043d\u044b\u0445 \u043e\u0446\u0435\u043d\u043e\u043a \u043a\u0430\u043a \u0432 <em>z<\/em>&#8212; \u0438 <em>t<\/em>-\u0442\u0435\u0441\u0442\u0430\u0445).<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043d\u044e\u0430\u043d\u0441 \u2014 <em>O<\/em> \u0438 <em>E <\/em>\u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u043c\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f (\u0432\u043e\u0442 <a href=\"https:\/\/www.real-statistics.com\/chi-square-and-f-distributions\/goodness-of-fit\/\"><u>\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435<\/u><\/a> \u043f\u043e \u0442\u0435\u043c\u0435).<\/p>\n<h3>2.1 \u03c7\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c (homogeneity, goodness of fit)<\/h3>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0432 \u0433\u0440\u0443\u043f\u043f\u0430\u0445 (Observed) \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f (Expected):<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/51f\/478\/8d8\/51f4788d8be6c96a3a39b2f14d4aa24f.png\" width=\"210\" height=\"172\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/51f\/478\/8d8\/51f4788d8be6c96a3a39b2f14d4aa24f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430 goodness of fit \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>H0: <em>O<\/em>\u2081 = <em>O<\/em>\u2082 = <em>O<\/em>\u2083 = &#8230; = <em>O<\/em>\u2099 (\u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u0441 \u0440\u0430\u0432\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u0440\u0443\u043f\u043f);<\/p>\n<\/li>\n<li>\n<p>H1: \u0425\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u0430 \u0438\u0437 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 <em>O<\/em><a href=\"https:\/\/unicode-table.com\/en\/sets\/superscript-and-subscript-letters\/\"><em>\u1d62<\/em><\/a> \u043d\u0435 \u0440\u0430\u0432\u043d\u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0438\u043b\u0438 \u0442\u0430\u043a\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>H0: <em>O<\/em>\u2081 = <em>E<\/em>\u2081, <em>O<\/em>\u2082 = <em>E<\/em>\u2082, <em>O<\/em>\u2083 = <em>E<\/em>\u2083, &#8230;, <em>O<\/em>\u2099 = <em>E<\/em>\u2099 (\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e);<\/p>\n<\/li>\n<li>\n<p>H1: \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <em>O<\/em><a href=\"https:\/\/unicode-table.com\/en\/sets\/superscript-and-subscript-letters\/\"><em>\u1d62<\/em><\/a> \u043d\u0435 \u0440\u0430\u0432\u043d\u0430 <em>E<\/em><a href=\"https:\/\/unicode-table.com\/en\/sets\/superscript-and-subscript-letters\/\"><em>\u1d62<\/em><\/a> (\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 (<a href=\"https:\/\/www.jmp.com\/en_ca\/statistics-knowledge-portal\/chi-square-test\/chi-square-goodness-of-fit-test.html\"><u>\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/u><\/a>):<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c p-value \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <em>\u03c7<\/em>\u00b2 \u043f\u0440\u0438 \u0447\u0438\u0441\u043b\u0435 \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b <em>d <\/em>= (<em>n<\/em>-1) = 4:<\/p>\n<pre><code class=\"python\">1 - stats.chi2.cdf(52.75, 4)<\/code><\/pre>\n<p><code>9.612521889579284e-11<\/code><\/p>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u0432 \u0435\u0433\u043e \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 \u03b1 = 0.05, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0443\u043b\u0435\u0432\u0430\u044f \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430 \u043e\u0442\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u043e\u043d\u0444\u0435\u0442\u044b \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u043e \u0432\u043a\u0443\u0441\u0430\u043c \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e.<\/p>\n<p>\u0415\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0441\u0447\u0435\u0442\u0430:<a href=\"https:\/\/www.sbcc.edu\/mathematics\/mathlab\/docs\/worksheets\/chisquare.pdf\"> <u>\u043e\u0434\u0438\u043d<\/u><\/a> \u0438<a href=\"https:\/\/online.stat.psu.edu\/stat500\/lesson\/8\/8.2\"> <u>\u0432\u0442\u043e\u0440\u043e\u0439<\/u><\/a>.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"python\">def diy_chisquare(observed, expected):     # \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443     k = len(observed)                                                         # \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b      statistic = (((observed - expected)**2)\/expected).sum()                   # \u041a\u0421\u041f          # \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c p-value      p_value = 1 - stats.chi2.cdf(statistic, k - 1)                            # \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435          return k - 1, statistic, p_value<\/code><\/pre>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u043c \u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\"># \u0437\u0430\u0434\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 np.random.seed(1234)  data = np.array([180, 250, 120, 225, 225]) expected = np.array([200, 200, 200, 200, 200])  # \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0430\u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 display(diy_chisquare(data, expected))  # \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 from scipy.stats import chisquare chisquare(data, expected)<\/code><\/pre>\n<p><code>(4, 52.75, 9.612521889579284e-11)  <\/code><\/p>\n<p><code>Power_divergenceResult(statistic=52.75, pvalue=9.612518035368181e-11)  <\/code><\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0430 \u0440\u0430\u0434\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u041a\u0421\u041f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e <em>\u03c7<\/em>\u00b2. \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"python\">def generate_max_likelihood_distro(size, num_samples, sample_size, k_range, ax, ax2, ax3, title):          ks_results = []     for line_i, k in enumerate(k_range): # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f)          data = pd.Series(np.random.choice(k, size, p = [1 \/ k] * k))                    # \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0433\u0440\u0443\u043f\u043f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439          max_likelihood = []         for i in range(num_samples):             observed = data.sample(sample_size, replace = True).value_counts()          # \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439             expected = sample_size\/k                                                    # \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439             max_likelihood += [[i,                                  k - 1,                                  (((observed - expected)**2)\/expected).sum()             # \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u0435                                ]]           max_likelihood = pd.DataFrame(max_likelihood, columns = ['Sample #', 'Degrees of freedom', 'Max likelyhood distribution'])                  # \u0441\u0442\u0440\u043e\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439         sns.kdeplot(max_likelihood['Max likelyhood distribution'], label = 'k = {}'.format(k), ax = ax)         ax.legend(title = '\u0421\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b'), ax.set_ylabel('$f_k(x)$'), ax.set_xlabel('$x$'), ax.set_title(title)                  # \u0441\u0442\u0440\u043e\u0438\u043c qq-\u0433\u0440\u0430\u0444\u0438\u043a\u0438         stats.probplot(max_likelihood['Max likelyhood distribution'],                         dist = stats.chi2, sparams = (k - 1), # chi2 \u0441 \u0447\u0438\u0441\u043b\u043e\u043c \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b k-1                        plot = ax2, fit = False)         line_index = (line_i + 1) * 2         (ax2.get_lines()[line_index - 2].set_color(ax.get_lines()[line_i].get_color()),           ax2.get_lines()[line_index - 2].set_label('k = {}'.format(k)),           ax2.get_lines()[line_index - 2].set_markersize(3),           ax2.get_lines()[line_index - 2].set_alpha(0.5)         )         ax2.get_lines()[line_index - 1].set_color('lightgrey'), ax2.get_lines()[line_index - 1].set_linestyle(':')         ax2.set_title('\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e $\\chi^2$'), ax2.legend(title = '\u0421\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b')                  # \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u041a\u0421-\u0442\u0435\u0441\u0442         ks_stat, ks_p = stats.kstest(max_likelihood['Max likelyhood distribution'], 'chi2', args = (k - 1, ))         ks_results.append([k, ks_stat, ks_p])              ks_results = pd.DataFrame(ks_results, columns = ['k', 'statistic', 'p']).set_index('k')     ks_results[['p']].plot(ax = ax3, xticks = ks_results.index, label = '$p$-value')     ax3.axhline(0.05 \/ len(k_range), color = 'red', linestyle = ':', label = 'alpha = {:.2f}'.format(0.05 \/ len(k_range))) # \u0441 \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u0435\u0439 \u0411\u043e\u043d\u0444\u0435\u0440\u0440\u043e\u043d\u0438     ax3.set_ylabel('$p$-value'), ax3.set_xlabel('$k$ (\u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b)'), ax3.set_title('\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u041a\u0421-\u0442\u0435\u0441\u0442\u0430'), ax3.legend()<\/code><\/pre>\n<p>\u0418\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e <em>\u03c7<\/em>\u00b2:<\/p>\n<pre><code class=\"python\">np.random.seed(12345)  size = 100000             # \u0440\u0430\u0437\u043c\u0435\u0440 \u00ab\u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u0438\u00bb \u2014 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 num_samples = 1000 sample_size = 100  plt.figure(figsize = (25, 12)) sample_sizes = [10, 50, 100, 500, 1000, 2000] for i, sample_size in enumerate(sample_sizes):     generate_max_likelihood_distro(size, num_samples, sample_size,                                     range(2, 22, 3),                                     title = '\u0420\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 $n = {}$'.format(sample_size),                                     ax = plt.subplot(3, len(sample_sizes), i + 1),                                    ax2 =  plt.subplot(3, len(sample_sizes), len(sample_sizes) + i + 1),                                    ax3 =  plt.subplot(3, len(sample_sizes), len(sample_sizes) * 2 + i + 1),                                   ) plt.tight_layout()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ada\/796\/a6a\/ada796a6a3e855e206797b5a26d95a6b.png\" width=\"1625\" height=\"773\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ada\/796\/a6a\/ada796a6a3e855e206797b5a26d95a6b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u0432\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0435 \u0448\u0443\u043c\u043d\u044b\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0441\u0430\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 <em>\u03c7<\/em>\u00b2;<\/p>\n<\/li>\n<li>\n<p>QQ-plot \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u043a <em>\u03c7<\/em>\u00b2 \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u043c\u0430\u043b\u044b\u0445 <em>k,<\/em> \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 100 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0435\u0441\u0442 \u041a\u043e\u043b\u043c\u043e\u0433\u043e\u0440\u043e\u0432\u0430-\u0421\u043c\u0438\u0440\u043d\u043e\u0432\u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u043a<em> \u03c7<\/em>\u00b2.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438 \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438, \u0447\u0442\u043e \u041a\u0421\u041f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2.<\/p>\n<h3>2.2 \u03c7\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c<\/h3>\n<p>\u0422\u0435\u0441\u0442 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c (test of independence\/association) \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0433\u0438\u043f\u043e\u0442\u0435\u0437:<\/p>\n<ul>\n<li>\n<p>H0: \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 A \u0438 B \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b;<\/p>\n<\/li>\n<li>\n<p>H1: \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 A \u0438 B \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 (\u0438\u0437<a href=\"https:\/\/www.khanacademy.org\/math\/ap-statistics\/chi-square-tests\/chi-square-tests-two-way-tables\/v\/chi-square-test-association-independence\"> <u>\u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/u><\/a>). \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 (observed) \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/953\/b2e\/111\/953b2e1117455ac577d2a6b912039181.png\" width=\"866\" height=\"175\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/953\/b2e\/111\/953b2e1117455ac577d2a6b912039181.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0442\u0435\u043e\u0440\u0435\u043c\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439, \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u0434\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b A \u0438 B \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0440\u0430\u0432\u043d\u0430 <em>P(AB) <\/em>= <em>P(A) \u22c5 P(B)<\/em>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u0448\u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 (expected) \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0441\u0432\u0435\u0441\u0442\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3fd\/2b4\/787\/3fd2b47870e9c833ffce299ca99a2d3c.png\" width=\"863\" height=\"234\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3fd\/2b4\/787\/3fd2b47870e9c833ffce299ca99a2d3c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\large\\sum_{ij}{\\frac{(O_{ij}-E_{ij})^2}{E_{ij}}}\" alt=\"\\large\\sum_{ij}{\\frac{(O_{ij}-E_{ij})^2}{E_{ij}}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d51\/360\/52e\/d5136052e31405cd744c86571ed23c1d.svg\" width=\"167\" height=\"73\"\/><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1f5\/c5b\/d1a\/1f5c5bd1a433db80810cec85f6b8bf1c.png\" width=\"589\" height=\"148\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f5\/c5b\/d1a\/1f5c5bd1a433db80810cec85f6b8bf1c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0413\u043e\u0442\u043e\u0432\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 CDF \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <em>\u03c7<\/em>\u00b2 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c p-value.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">def diy_chi2_contingency(contingency_table):          # \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439     total = contingency_table.sum().sum()          # \u0441\u0443\u043c\u043c\u044b \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c     col_probs = contingency_table.sum(axis = 0).values     row_probs = contingency_table.sum(axis = 1).values          # \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u0445 \u0432 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438     col_probs = col_probs \/ total     row_probs = row_probs \/ total          # \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f     expected = np.array([col_probs]).T @ np.array([row_probs])              # \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440-\u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0440\u044f\u0434\u0430\u0445 \u043d\u0430 \u0432\u0435\u043a\u0442\u043e\u0440-\u0441\u0442\u043e\u0440\u043e\u043a\u0443 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445     expected = expected.T       expected = expected * total          # \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443     statistic = ((contingency_table.values - expected)**2)\/expected     statistic = statistic.sum()      # \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b     dof = (contingency_table.shape[0] - 1) * (contingency_table.shape[1] - 1)          # \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c p-value      p_value = 1 - stats.chi2.cdf(statistic, dof)                            # \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044e \u041c\u041f                return dof, statistic, p_value  contingency_table = pd.DataFrame([[11, 3, 8], [2, 9, 14], [12, 13, 28]]) diy_chi2_contingency(contingency_table)<\/code><\/pre>\n<p><code>(4, 11.942092624356777, 0.01778711460986071)  <\/code><\/p>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"python\">from scipy.stats import chi2_contingency chi2_contingency(contingency_table)[0:3]<\/code><\/pre>\n<p><code>(11.942092624356777, 0.0177871146098607, 4)  <\/code><\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b.<\/p>\n<h3>2.3 \u03c7\u00b2-\u0442\u0435\u0441\u0442 \u0434\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438<\/h3>\n<p>\u0422\u0440\u0435\u0442\u0438\u0439 \u0432\u0438\u0434 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\large \\frac{(n - 1)S^2}{\\sigma^2}\" alt=\"\\large \\frac{(n - 1)S^2}{\\sigma^2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cea\/52c\/a4b\/cea52ca4b04b63530528d2220c537b3b.svg\" width=\"106\" height=\"57\"\/><\/p>\n<p>\u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\chi^2_{n-1}\" alt=\"\\chi^2_{n-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a4\/b5f\/b0e\/3a4b5fb0e418cc820a910d986e0cc53f.svg\" width=\"40\" height=\"26\"\/><\/p>\n<p>\u0412\u043e\u0442 <a href=\"https:\/\/www.real-statistics.com\/chi-square-and-f-distributions\/one-sample-hypothesis-testing-variance\/\"><u>\u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e<\/u><\/a>. \u0417\u0434\u0435\u0441\u044c <em>S<\/em> \u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0435 \u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u043e\u0435 \u0421\u041a\u041e, \u0430 \u03c3 \u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0421\u041a\u041e.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438<a href=\"https:\/\/towardsdatascience.com\/making-inferences-about-a-single-population-variance-814a15b44857\"> <u>\u0442\u0443\u0442<\/u><\/a>.<\/p>\n<p>\u0412 Python \u043d\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<a href=\"https:\/\/stats.stackexchange.com\/questions\/495912\/chi2-test-for-the-variance-in-python\"> <u>\u043f\u0440\u0438\u043c\u0435\u0440<\/u><\/a>.<\/p>\n<p>\u0422\u0435\u0441\u0442 \u03c7\u00b2 \u0434\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043e\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e<a href=\"https:\/\/opentextbc.ca\/introbusinessstatopenstax\/chapter\/test-of-two-variances\/\"> <u>\u0441\u043b\u0443\u0436\u0438\u0442<\/u><\/a> <em>F<\/em>-\u0442\u0435\u0441\u0442 (\u043e\u0447\u0435\u043d\u044c \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445), \u0430 \u0434\u043b\u044f \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0442\u0435\u0441\u0442\u044b \u041b\u0435\u0432\u0435\u043d\u0430 \u0438\u043b\u0438 \u0411\u0430\u0440\u0442\u043b\u0435\u0442\u0442\u0430 (\u043e\u0431\u0430 \u0435\u0441\u0442\u044c \u0432 Python).<\/p>\n<p>\u041d\u0430\u0441, \u043a\u0430\u043a \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0432, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442 \u0434\u043b\u044f \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043c\u044b \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438).<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0438 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043e\u0446\u0435\u043d\u0438\u043c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"python\">np.random.seed(1234)  size = 100000             # \u0440\u0430\u0437\u043c\u0435\u0440 \u00ab\u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u0438\u00bb \u2014 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 num_samples = 1000 sample_size = 1000  std_threshold = 1.1  data_norm = pd.Series(np.random.normal(0, std_threshold, size)) data_exp = pd.Series(np.random.exponential(std_threshold, size))  plt.figure(figsize = (25, 5)) sample_sizes = [10, 30, 50, 100, 500, 1000] for i, sample_size in enumerate(sample_sizes):          statistics = []     for j in range(num_samples):         statistics += [[j,                          (sample_size - 1) *  data_norm.sample(sample_size, replace = True).var() \/ (std_threshold ** 2), # \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445                         (sample_size - 1) * data_exp.sample(sample_size, replace = True).var() \/ (std_threshold ** 2)  # \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0434\u043b\u044f \u0436\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445                        ]]      statistics = pd.DataFrame(statistics, columns = ['Sample #', 'Statistic (normal data)', 'Statistic (exponential data)'])      # \u0441\u0442\u0440\u043e\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439     ax = plt.subplot(1, len(sample_sizes), i + 1)     sns.kdeplot(statistics['Statistic (normal data)'], label = '\u041d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435', color = 'orange', linestyle = ':', ax = ax)     sns.kdeplot(statistics['Statistic (exponential data)'], label = '\u042d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435', color = 'orange', ax = ax)     sns.kdeplot(pd.Series(np.random.chisquare(sample_size - 1, size)), color = 'blue', label = '\u042d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 $\\chi^2$', ax = ax)     plt.title('\u0420\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438: {}'.format(sample_size)), plt.xlabel('\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430'), plt.ylabel('\u0427\u0430\u0441\u0442\u043e\u0442\u0430')     if i == 0: plt.legend()      plt.tight_layout()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/547\/092\/9e6\/5470929e6899b351d1668df2045d351a.png\" width=\"1599\" height=\"322\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/547\/092\/9e6\/5470929e6899b351d1668df2045d351a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\chi^2_{n-1}\" alt=\"\\chi^2_{n-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/226\/1ef\/a9b\/2261efa9bf3e9feeb125b6f0548d8cdb.svg\" width=\"40\" height=\"26\"\/><\/p>\n<ul>\n<li>\n<p>\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435, \u043f\u043e\u0445\u043e\u0436\u0435, \u0440\u0430\u0441\u0442\u0435\u0442 \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b\u0432\u043e\u0434: \u043f\u0440\u043e\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u0439 \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442.<\/p>\n<h2>3. \u0421\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 z-\u0442\u0435\u0441\u0442\u043e\u043c \u0438 \u03c7\u00b2-\u0442\u0435\u0441\u0442\u043e\u043c (\u0438 \u0442\u0435\u0441\u0442\u043e\u043c \u0424\u0438\u0448\u0435\u0440\u0430)<\/h2>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u0432\u043c\u0435\u0441\u0442\u043e <em>z<\/em>-\u0442\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <em>z<\/em>-\u0442\u0435\u0441\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0443 \u0434\u043b\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441 \u0434\u0432\u0443\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438. \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443:<\/p>\n<ul>\n<li>\n<p>\u0434\u0432\u0443\u0445\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u043c <em>z<\/em>-\u0442\u0435\u0441\u0442\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0435\u0441\u0442\u043e\u043c <em>\u03c7<\/em>\u00b2 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 (test of independence) \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c 2 x 2.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"python\">np.random.seed(1234)  size = 1000 p = 0.4 data = pd.Series(np.random.choice(2, size, p = [1 - p, p]))<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0435\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043d\u0438\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">contingency_table = pd.DataFrame([data.value_counts().values, [500, 500]], index = ['Observed', 'Expected']) contingency_table<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f99\/29b\/7cb\/f9929b7cb7bca5a32f9dda4cd7ab3376.png\" width=\"135\" height=\"87\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f99\/29b\/7cb\/f9929b7cb7bca5a32f9dda4cd7ab3376.png\"\/><figcaption><\/figcaption><\/figure>\n<p> \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c:  <\/p>\n<pre><code class=\"python\">from scipy.stats import chi2_contingency chi2_statistic, p_value, dof, exp = chi2_contingency(contingency_table, correction = False) # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u044e (\u0441 \u043d\u0435\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f) chi2_statistic, p_value<\/code><\/pre>\n<p><code>(14.555161038503186, 0.00013611529553341273)  <\/code><\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0432\u0443\u0445\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u043e\u0433\u043e <em>z<\/em>-\u0442\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439:<\/p>\n<pre><code class=\"python\">from statsmodels.stats.proportion import proportions_ztest z_statistic, p_value = proportions_ztest(contingency_table[0], contingency_table.sum(axis = 1), alternative = 'two-sided') z_statistic, p_value<\/code><\/pre>\n<p><code>(3.815122676730484, 0.00013611529553341327)  <\/code><\/p>\n<p>p-value \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, <em>z<\/em>-\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0440\u0430\u0432\u043d\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u043c\u0443 \u043a\u043e\u0440\u043d\u044e \u0438\u0437 <em>\u03c7<\/em>\u00b2-\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438:<\/p>\n<pre><code class=\"python\">z_statistic, math.sqrt(chi2_statistic)<\/code><\/pre>\n<p><code>(3.815122676730484, 3.8151226767304856)  <\/code><\/p>\n<p>\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438: <a href=\"https:\/\/stats.stackexchange.com\/questions\/173415\/at-what-level-is-a-chi2-test-mathematically-identical-to-a-z-test-of-propo\">\u0442\u0443\u0442<\/a> \u0438 <a href=\"https:\/\/www.real-statistics.com\/chi-square-and-f-distributions\/goodness-of-fit\/\">\u0442\u0443\u0442<\/a>.  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d <em>z<\/em>-\u0442\u0435\u0441\u0442\u0443:<\/p>\n<pre><code class=\"python\">from scipy.stats import chisquare chi2_statistic, p_value = chisquare(contingency_table.loc['Observed'], f_exp = contingency_table.loc['Expected']) # \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c chi2_statistic, p_value<\/code><\/pre>\n<p><code>(28.9, 7.62129129638297e-08)  <\/code><\/p>\n<p>\u0422\u0435\u0441\u0442 \u0424\u0438\u0448\u0435\u0440\u0430 \u0447\u0430\u0441\u0442\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 2 \u0445 2 \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u044b (\u044f\u0447\u0435\u0439\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f &lt;= 5). \u0415\u0441\u043b\u0438 \u0442\u0435\u0441\u0442 \u0424\u0438\u0448\u0435\u0440\u0430 \u0434\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0443, \u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u0438 <em>z<\/em>-\u0442\u0435\u0441\u0442\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, p-value \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438:<\/p>\n<pre><code class=\"python\">from scipy.stats import fisher_exact fisher_exact(contingency_table, alternative = 'two-sided')<\/code><\/pre>\n<p><code>(1.4096385542168675, 0.00016169735747221216)<\/code><\/p>\n<h2>4. \u0420\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u03c7\u00b2-\u0442\u0435\u0441\u0442\u0430<\/h2>\n<p><a href=\"https:\/\/www.researchgate.net\/post\/Large_Sample_Size_and_Differences_in_Chi-Square_Statistic\"><u>\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442\u0441\u044f<\/u><\/a>, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u043e\u0439, \u0447\u0442\u043e\u0431\u044b:<\/p>\n<ul>\n<li>\n<p>\u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u044f\u0447\u0435\u0435\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0431\u044b\u043b\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 5 (\u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u044d\u0442\u043e \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044c);<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u044d\u043c\u043f\u043b\u0430 \u0431\u044b\u043b \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 500, \u0442\u0430\u043a \u043a\u0430\u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u044d\u043c\u043f\u043b\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u043e\u0441\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043b\u043e\u0436\u043d\u043e\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u043d\u0443\u043b\u0435\u0432\u0443\u044e \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0443 (\u044d\u0442\u043e \u0441\u043b\u0435\u0433\u043a\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432) \u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<\/p>\n<pre><code class=\"python\"># \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 test_table = pd.DataFrame([[6, 5.5, 11], [6.25, 7, 12.5], [13.25, 13.25, 26.5]])  # \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 result = [] for mult in range(1, 100, 1):     current = test_table * mult     statistic_ind, p_ind, _, _ = chi2_contingency(current) # \u0442\u0435\u0441\u0442 \u043f\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435     result += [[current.sum().sum(), p_ind, statistic_ind]] result = pd.DataFrame(result, columns = ['sample_size', 'p-value', 'statistic']).set_index('sample_size')  # \u0433\u0440\u0430\u0444\u0438\u043a p-value ax = result['p-value'].plot(figsize = (10, 5), color = 'red', grid = True) plt.ylabel('p-value'), plt.xlabel('\u0420\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438')  # \u0433\u0440\u0430\u0444\u0438\u043a \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 ax2 = ax.twinx() result['statistic'].plot(ax = ax2, color = 'blue', label = '\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430')  # \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u0435\u0433\u0435\u043d\u0434\u0443 lines, labels = ax.get_legend_handles_labels() lines2, labels2 = ax2.get_legend_handles_labels() ax2.legend(lines + lines2, labels + labels2, loc = 1, title = '\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b')  plt.ylabel('\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430'), plt.title('\u0412\u043b\u0438\u044f\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0435\u0441\u0442\u0430 $\\chi^2$');<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/092\/302\/fbd\/092302fbd486f86c5aac690e88dd4e98.png\" width=\"586\" height=\"306\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/092\/302\/fbd\/092302fbd486f86c5aac690e88dd4e98.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0440\u0430\u0441\u0442\u0435\u0442 \u043b\u0438\u043d\u0435\u0439\u043d\u043e, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c p-value \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0441\u044f \u043a 0 \u0438 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0442\u0435\u0441\u0442 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043f\u0440\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u044f\u0445.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0430\u043b\u044b\u0439 (\u0432\u0438\u0434\u0438\u043c\u043e, 500 \u2014 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430).<\/p>\n<h2>5. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u03c7\u00b2-\u0442\u0435\u0441\u0442\u043e\u0432 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439<\/h2>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f, \u0447\u0442\u043e <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a (\u0441\u043a\u0430\u0436\u0435\u043c, \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 A\/B-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f) \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0435\u0440\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 <em>z<\/em>-\u0442\u0435\u0441\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0435\u0441\u0442 <em>\u03c7<\/em>\u00b2. \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0438\u0437 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a.<\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043d\u0435\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0442\u0435\u0441\u0442 <em>\u03c7<\/em>\u00b2 \u0434\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u043c\u0438\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u0432\u0438\u0434\u0430\u043c\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 <em>\u03c7<\/em>\u00b2, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0410\/B \u0442\u0435\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u0432\u0430 \u0432\u0438\u0434\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u2014 \u0432\u043e\u0440\u043e\u043d\u043a\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b (A) \u0438 \u0432\u043e\u0440\u043e\u043d\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b (B).<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1bb\/001\/2ee\/1bb0012ee645776f5acd185de3c51751.png\" width=\"439\" height=\"166\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1bb\/001\/2ee\/1bb0012ee645776f5acd185de3c51751.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438, <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u043e\u0440\u043e\u043d\u043a\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u043a\u0430\u043a \u043d\u0430\u0431\u043e\u0440 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (expected), \u0430 \u0432\u043e\u0440\u043e\u043d\u043a\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u2014 \u043a\u0430\u043a \u043d\u0430\u0431\u043e\u0440 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (observed). \u0422\u043e\u0433\u0434\u0430 \u0442\u0435\u0441\u0442 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 observed \u0438 expected.<\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043b\u044e\u0431\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0435\u0441\u0442 \u043f\u043e\u043a\u0430\u0436\u0435\u0442, \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u00ab\u0448\u0430\u0433\u0438 \u0432\u043e\u0440\u043e\u043d\u043a\u0438\u00bb \u043e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u00ab\u0433\u0440\u0443\u043f\u043f\u0430 \u0442\u0435\u0441\u0442\u0430\u00bb \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/003\/840\/809\/003840809ed47b85c9970bf7d39d9e55.png\" width=\"606\" height=\"165\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/003\/840\/809\/003840809ed47b85c9970bf7d39d9e55.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0437\u0434\u0435\u0441\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u044e\u0430\u043d\u0441. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0431\u043e\u0438\u0445 \u0432\u0438\u0434\u043e\u0432 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u0438\u0445 \u0432\u0445\u043e\u0434 \u043f\u043e\u0434\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0422\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e. \u042d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0432\u043e\u0440\u043e\u043d\u043a\u0430\u043c\u0438 \u2014 \u044d\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c) \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0438 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u0445.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u2014 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0443\u0448\u043b\u043e \u0438\u0437 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0448\u0430\u0433\u043e\u0432. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0437 \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/277\/36c\/465\/27736c46517dc3368060d59dba370052.png\" width=\"700\" height=\"166\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/277\/36c\/465\/27736c46517dc3368060d59dba370052.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u0440\u044b\u0433\u0438\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0448\u0430\u0433\u0438 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u043e \u043e\u0442\u0432\u0430\u043b\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0440\u0430\u0432\u043d\u043e \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0434\u0432\u0443\u0445 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0448\u0430\u0433\u0430\u0445.<\/p>\n<p>\u0415\u0441\u0442\u044c \u043b\u0438 \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u0445, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u043f\u0440\u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0432 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b \u0442\u0430\u0431\u043b\u0438\u0446 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438? \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0435\u0441\u0442, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0434\u0430\u0441\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u2014 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/310\/1c8\/a43\/3101c8a431e7354ccd363bbbda4b5141.png\" width=\"602\" height=\"352\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/310\/1c8\/a43\/3101c8a431e7354ccd363bbbda4b5141.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u044f\u0432\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f, \u043d\u043e <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u0434\u043b\u044f \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0439, \u0430 \u0442\u043e\u0442 \u0436\u0435 \u0442\u0435\u0441\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0435\u0441\u0442\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/aad\/d70\/2c5\/aadd702c54cda615450ac300feed46ce.png\" width=\"1295\" height=\"205\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aad\/d70\/2c5\/aadd702c54cda615450ac300feed46ce.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0434\u0430\u0435\u043c \u0438\u0445 \u0432 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041d\u043e \u0433\u0434\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0432\u044b\u0448\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u043d, \u0438 \u0432 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0444\u043e\u0440\u043c\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c.<\/p>\n<h3>5.1 \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u03c7\u00b2-\u0442\u0435\u0441\u0442\u043e\u0432 \u043e\u0442 \u0444\u043e\u0440\u043c\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a<\/h3>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0442 \u0444\u043e\u0440\u043c\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 (\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0442\u0430\u043c, \u0433\u0434\u0435 \u0438\u0445 \u043d\u0435\u0442). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0441\u0435\u0440\u0438\u044e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437 \u0442\u0440\u0435\u0445 \u0448\u0430\u0433\u043e\u0432. \u041a\u0430\u0436\u0434\u0430\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u043e\u0439 \u0447\u0438\u0441\u0435\u043b \u2014 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433 \u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0438\u0437 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0432 \u0442\u0440\u0435\u0442\u0438\u0439. \u0422\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0440\u043e\u043d\u043a\u0430 100 -> 50 -> 25 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u043e\u0439 \u0447\u0438\u0441\u0435\u043b [0.5, 0.5];<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c N \u043f\u0430\u0440 \u0432\u044b\u0431\u043e\u0440\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043f\u0430\u0440 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c 5 \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p><em>z<\/em>-\u0442\u0435\u0441\u0442, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0434\u043e\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0434\u043e\u0441\u0442\u0438\u0433\u0448\u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0448\u0430\u0433\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a:<\/p>\n<pre><code class=\"python\"># \u0441\u0442\u0440\u043e\u0438\u043c \u0432\u043e\u0440\u043e\u043d\u043a\u0438, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 # pop_size \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u043e\u0440\u043e\u043d\u043a\u0435 # coeffs \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 # rel \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0442\u0435\u043c, \u043a\u0430\u043a\u0430\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u2014 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f (\u0434\u043e\u043b\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0432\u043e\u0440\u043e\u043d\u043a\u0438) \u0438\u043b\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f (\u0434\u043e\u043b\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0448\u0430\u0433\u0430) def generate_funnel_log(pop_size, coeffs, rel = False, random_state = 12345):          # \u0437\u0430\u0434\u0430\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0433     result = pd.DataFrame([[0, 1]] * pop_size, columns = ['step', 'user_id'])     result['user_id'] = result['user_id'].apply(lambda x: ''.join(random.choice('abcdefghij1234567890') for i in range(10)))          # \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0431\u0435\u0440\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0434\u043e\u0441\u0442\u0438\u0433\u0448\u0438\u0445 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0448\u0430\u0433\u0430     for step, step_coeff in enumerate(coeffs):         current = result.query('step == @step')         # \u0435\u0441\u043b\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0430, \u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0443\u043d\u0438\u043a\u043e\u0432 \u043d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u0430\u043a % \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f, \u0442\u043e \u043e\u0442 \u0432\u0441\u0435\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0446\u0438\u0438         current_pop = pop_size         if rel: current_pop = current['user_id'].nunique()         current = current.sample(int(np.ceil(current_pop * step_coeff)), random_state = random_state)         current['step'] = step + 1         result = result.append(current)              return result<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u043c \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0440\u0430\u0437\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b:<\/p>\n<pre><code class=\"python\"># \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a  # steps \u2014 \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u044b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0448\u0430\u0433\u0438 \u0432\u043e\u0440\u043e\u043d\u043e\u043a # pop_size \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u043e\u0440\u043e\u043d\u043a\u0435 # differences \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 # file_name \u2014 \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u0430 (\u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0435\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f) def generate_funnel_set(steps, pop_size, differences = [], file_name = None):          result = pd.DataFrame()     funnel_num = 0          # \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043b\u043e\u0433\u0430 \u0432\u043e\u0440\u043e\u043d\u043a\u0438     if file_name is not None:         try:             return pd.read_csv(file_name)         except:             print(f'{file_name} \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442.')          # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c 1 \u043a \u0441\u043f\u0438\u0441\u043a\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0432\u043e\u0440\u043e\u043d\u043a\u0443     differences = [1] + differences      for first_step_prob in np.linspace(0, 1, num = steps):         for second_step_prob in np.linspace(0, 1, num = steps):                          # \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0440\u043e\u043d\u043a\u0430 \u043f\u043b\u043e\u0441\u043a\u0430\u044f             if first_step_prob == 0 or second_step_prob == 0: continue             funnel_coeffs = [first_step_prob, second_step_prob]                          # \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u043e\u0440\u043e\u043d\u043a\u0438             # \u0437\u0434\u0435\u0441\u044c \u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043e\u043d\u0430 \u0441\u0430\u043c\u0430 \u0441 diff = 1             for i, diff in enumerate(differences):                 current_funnel = generate_funnel_log(pop_size, [x * diff for x in funnel_coeffs], rel = True)                              # \u043d\u043e\u043c\u0435\u0440 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043a \u043d\u0435\u0439 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f                 current_funnel['funnel_num'] = funnel_num                 current_funnel['funnel_diff_num'] = i                  # \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u043e\u0440\u043e\u043d\u043a\u0438                 current_funnel['first_step_prob'] = first_step_prob                 current_funnel['second_step_prob'] = second_step_prob                 current_funnel['diff'] = diff                  result = result.append(current_funnel)              funnel_num += 1              # \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u043e\u0440\u043e\u043d\u043a\u0443 \u0432 \u0444\u0430\u0439\u043b     if file_name is not None:         result.to_csv(file_name)              return result  # \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u0440\u043e\u043d\u043e\u043a log = generate_funnel_set(steps = 25, pop_size = 10000, differences = [], file_name = 'sample_log.csv')  display(log.query('funnel_num == 10')[['first_step_prob', 'second_step_prob']].drop_duplicates())  report = log.query('funnel_num == 10').groupby('step').agg({'user_id': 'nunique'}) report['perc'] = report['user_id'] \/ report.loc[0, 'user_id'] display(report)<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dba\/6fd\/81a\/dba6fd81a979ad9eceffabb6e6a35c2f.png\" width=\"257\" height=\"191\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dba\/6fd\/81a\/dba6fd81a979ad9eceffabb6e6a35c2f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430 \u043a\u0430\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c:<\/p>\n<pre><code class=\"python\"># \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c 5 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a sample_funnels = log['funnel_num'].drop_duplicates().sample(5, random_state = 1234567)  # \u0441\u0442\u0440\u043e\u0438\u043c \u0438\u0445 report = log.query('funnel_num in @sample_funnels') report['funnel_name'] = report.apply(lambda x: f\"\u2116{x['funnel_num']}. \u041e\u0442\u043d. \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u044f {x['first_step_prob']:.2%} -> {x['second_step_prob']:.2%}\", axis = 1) report = report.pivot_table(index = 'step', columns = 'funnel_name', values = 'user_id', aggfunc = 'nunique') report = report.div(report.loc[0], axis = 1)  # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0438 ax = report.plot(figsize = (15, 7), grid = True) ax.yaxis.set_major_formatter(mtick.PercentFormatter(1)) ax.set_xticks(report.index) plt.xlabel('\u0428\u0430\u0433 \u0432\u043e\u0440\u043e\u043d\u043a\u0438'), plt.ylabel('\u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438'), plt.legend(title = '\u0412\u043e\u0440\u043e\u043d\u043a\u0438') plt.title('\u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a');<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c1b\/e2f\/310\/c1be2f31067a0d81427e956a50b48851.png\" width=\"841\" height=\"399\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c1b\/e2f\/310\/c1be2f31067a0d81427e956a50b48851.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u043e\u0440\u043e\u043d\u043a\u0438, \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 \u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<ul>\n<li>\n<p>\u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0441 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u2014 \u0442\u0435, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c 50% \u043e\u0442 \u043d\u0443\u043b\u0435\u0432\u043e\u0433\u043e. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u044f \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433 \u043d\u0435 \u0432\u0430\u0436\u043d\u0430. \u041d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u043a \u044d\u0442\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u2116211 \u0438 \u2116214;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0443\u0433\u0430\u0441\u0430\u043d\u0438\u0435\u043c \u2014 \u0442\u0435, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0448\u0430\u0433\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 50% \u043e\u0442 \u043d\u0443\u043b\u0435\u0432\u043e\u0433\u043e, \u0430 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0448\u0430\u0433\u0435 \u2014 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c 50% \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u0438\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e\u0440\u043e\u043d\u043a\u0430 \u2116377;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0441 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0443\u0433\u0430\u0441\u0430\u043d\u0438\u0435\u043c \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0448\u0430\u0433\u0435. \u041d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u044d\u0442\u043e \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u2116491 \u0438 \u2116532.<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e \u043e\u0441\u0438 X \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0438\u0437 \u0448\u0430\u0433\u0430 0 \u0432 \u0448\u0430\u0433 1, \u0430 \u043f\u043e \u043e\u0441\u0438 Y \u2014 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0438\u0437 \u0448\u0430\u0433\u0430 1 \u0432 \u0448\u0430\u0433 2, \u0442\u043e \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0430\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u043c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">report = log.query('funnel_num in @sample_funnels') plot_data = report[['funnel_num', 'first_step_prob', 'second_step_prob']].drop_duplicates() x, y, t = plot_data['first_step_prob'].values, plot_data['second_step_prob'].values, plot_data['funnel_num'].values  ax = plt.axes() plt.scatter(x, y) plt.xlim((0, 1)), plt.ylim((0, 1))  # \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0442\u0438\u043f\u043e\u0432 \u0432\u043e\u0440\u043e\u043d\u043e\u043a ax.axvline(0.5, linestyle = '-.', color = 'red') ax.hlines(y = 0.5, xmin = 0.5, xmax = 1, linestyle = '-.', color = 'red') ax.text(0.07, 0.9, '\u0411\u044b\u0441\u0442\u0440\u043e\u0435', fontsize = 15, color = 'red') ax.text(0.55, 0.9, '\u0423\u043c\u0435\u0440\u0435\u043d\u043d\u043e\u0435', fontsize = 15, color = 'red') ax.text(0.55, 0.3, '\u0411\u044b\u0441\u0442\u0440\u043e\u0435\\n2-\u0439 \u0448\u0430\u0433', fontsize = 15, color = 'red');  for i, txt in enumerate(t):     ax.annotate(txt, (x[i] + 0.03, y[i]))      plt.xlabel('\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433'), plt.ylabel('\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433');<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b68\/09b\/e8d\/b6809be8d51f6ddad144c299f4bb8897.png\" width=\"366\" height=\"245\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b68\/09b\/e8d\/b6809be8d51f6ddad144c299f4bb8897.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0441\u0435\u0440\u0438\u044e \u0442\u0435\u0441\u0442\u043e\u0432, \u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0448\u0430\u043d\u0441 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cb7\/a5a\/c3f\/cb7a5ac3f58855bb1bab810256f80c75.png\" width=\"313\" height=\"355\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cb7\/a5a\/c3f\/cb7a5ac3f58855bb1bab810256f80c75.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0434\u0435\u0441\u044c \u0437\u0435\u043b\u0435\u043d\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0430 \u043e\u0442\u0442\u0435\u043d\u043a\u0438 \u043a\u0440\u0430\u0441\u043d\u043e\u0433\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438:<\/p>\n<pre><code class=\"python\"># \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0432\u043e\u0440\u043e\u043d\u043a\u0438, \u043d\u043e \u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043e\u0442 \u043d\u0438\u0445 \u043d\u0430 75%, 50% \u0438 25% funnel_log = generate_funnel_set(steps = 25, pop_size = 2000, differences = [0.9, 0.8, 0.7], file_name = 'funnel_log.csv')  display(funnel_log.query('funnel_num == 10')[['diff', 'first_step_prob', 'second_step_prob']].drop_duplicates())<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6e1\/846\/4fa\/6e18464fa6dc31dca0a78f6f0399b724.png\" width=\"274\" height=\"137\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6e1\/846\/4fa\/6e18464fa6dc31dca0a78f6f0399b724.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>run_experiment<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0438\u0437 \u043d\u0438\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u043f\u043e \u043d\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u044b;<\/p>\n<\/li>\n<li>\n<p><code>run_error_experiments<\/code> \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u043d\u0430\u0431\u043e\u0440\u044b \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>run_experiment<\/code>. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, <code>run_error_experiments<\/code> \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\"># \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u0441\u0435\u0440\u0438\u044e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432  # funnel_log \u2014 \u043b\u043e\u0433 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043e\u0440\u043e\u043d\u043e\u043a # sample_size \u2014 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043e\u043a, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 # number_of_experiments \u2014 \u0447\u0438\u0441\u043b\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0432\u043e\u0440\u043e\u043d\u043e\u043a # alpha \u2014 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 # test_func \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 # result_column_names \u2014 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e-\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 # compare_func \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0441\u043b\u0443\u0436\u0430\u0449\u0430\u044f \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f p-value \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 def run_experiment(funnel_log, sample_size, number_of_experiments, alpha, test_func, compare_func):          result = []     errors = 0          # \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b     for i in range(number_of_experiments):                  # \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438\u0437 \u0432\u0441\u0435\u0445 \u0433\u0440\u0443\u043f\u043f         funnel = pd.DataFrame()         for j, group in enumerate(funnel_log['group'].unique()):             test_users = funnel_log.query('group == @group')['user_id'].drop_duplicates().sample(sample_size, random_state = i + j)             current_funnel = funnel_log.query('group == @group and user_id in @test_users')             funnel = funnel.append(current_funnel)                  # \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u043e\u0440\u043e\u043d\u043e\u043a         funnel = funnel.pivot_table(index = 'step', columns = 'group', values = 'user_id', aggfunc = 'nunique').fillna(0)                  # \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0438\u0437-\u0437\u0430 \u043c\u0430\u043b\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0432\u043e\u0440\u043e\u043d\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0448\u0430\u0433\u0430         if funnel.shape[0] == 1:              errors += 1             continue                      # \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438         for col in funnel.columns:             funnel[f'cont_{col}'] = funnel[col] - funnel[col].shift(-1)                      # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0440\u044f\u0434\u0443 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u043c\u0438\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438         funnel_cols = [x for x in funnel.columns if 'cont' not in str(x)]         cont_cols = [x for x in funnel.columns if 'cont' in str(x)]         funnel.loc[funnel.index.max(), cont_cols] =  funnel.loc[funnel.index.max(),  funnel_cols].values                  # \u0435\u0441\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0443\u043b\u0438, \u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438          if (funnel[cont_cols] == 0).max().max():             errors += 1             continue                             # \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u0441\u0442\u044b         result += [test_func(funnel)]              result = pd.DataFrame(result)     result = result.apply(compare_func, args = [alpha], axis = 1)     return list(result.mean().values), errors  # funnel_log \u2014 \u043b\u043e\u0433 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043e\u0440\u043e\u043d\u043e\u043a # diffs \u2014 \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 diff = [0.7], \u0442\u043e c \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0439 \u0432\u043e\u0440\u043e\u043d\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0430, \u0438\u043c\u0435\u044e\u0449\u0430\u044f 30% \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0439 # sample_size \u2014 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043e\u043a, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 # number_of_experiments \u2014 \u0447\u0438\u0441\u043b\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0432\u043e\u0440\u043e\u043d\u043e\u043a # alpha \u2014 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 # test_func \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 # result_column_names \u2014 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e-\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 # compare_func \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0441\u043b\u0443\u0436\u0430\u0449\u0430\u044f \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f p-value \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 # levels \u2014 \u043b\u0438\u043d\u0438\u0438 \u0443\u0440\u043e\u0432\u043d\u044f \u043d\u0430 \u043a\u0430\u0440\u0442\u0435 \u043e\u0448\u0438\u0431\u043e\u043a # color_map \u2014 \u0446\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a # filename_template \u2014 \u0448\u0430\u0431\u043b\u043e\u043d \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 def run_error_experiments(funnel_log, diffs, sample_size, number_of_experiments, alpha, test_func, result_column_names, compare_func, levels, color_map, suptitle, filename_template):          # \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u0438\u0445 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432     existing_result_files = [f for f in os.listdir('.') if re.match(filename_template, f)]     if len(existing_result_files) > 0:          # \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u0438\u0445 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u043d\u0430\u0439\u0434\u0435\u043d\u044b, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0445         result = pd.read_csv(filename_template + '_result.csv')         errors = pd.read_csv(filename_template + '_errors.csv')     else:         # \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u043d\u043e\u0432\u043e          result = []         errors = []          for funnel_num in funnel_log['funnel_num'].unique():                          # A-\u0432\u043e\u0440\u043e\u043d\u043a\u0430             current_funnel_log = funnel_log.query('funnel_num == @funnel_num and diff == 1')             current_funnel_log['group'] = 0              # \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c B-\u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439             for i, diff in enumerate(diffs):                  current_funnel_log_another = funnel_log.query('funnel_num == @funnel_num and diff == @diff')                 current_funnel_log_another['group'] = i + 1                 current_funnel_log = current_funnel_log.append(current_funnel_log_another)              # \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442             current_exp_results, current_exp_errors = run_experiment(current_funnel_log,                                                                      sample_size = sample_size,                                                                       number_of_experiments = number_of_experiments,                                                                       alpha = alpha,                                                                      test_func = test_func,                                                                       compare_func = compare_func                                                                     )              # \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432             result += [[funnel_num, current_funnel_log['first_step_prob'].max(), current_funnel_log['second_step_prob'].max()] + current_exp_results]             errors += [[funnel_num, current_funnel_log['first_step_prob'].max(), current_funnel_log['second_step_prob'].max(), current_exp_errors]]          result = pd.DataFrame(result, columns = ['funnel_num', 'first_step_prob', 'second_step_prob'] + list(result_column_names.keys()))         errors = pd.DataFrame(errors, columns = ['funnel_num', 'first_step_prob', 'second_step_prob', 'errors'])                  # \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u0432 \u0444\u0430\u0439\u043b\u044b         result.to_csv(filename_template + '_result.csv', index = False)         errors.to_csv(filename_template + '_errors.csv', index = False)      # \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f         plt.figure(figsize = (30, 7))      def show_contour(data, x_col, y_col, z_col, levels, ax, title):         z = data.pivot_table(index = y_col, columns = x_col, values = z_col, aggfunc = 'max')         x, y = z.columns, z.index.values          # \u0437\u0430\u043a\u0440\u0430\u0441\u043a\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439         ax.contourf(x, y, z, levels = levels, cmap = color_map, alpha = 0.3, norm = matplotlib.colors.BoundaryNorm(levels,len(levels)))         line_colors = ['black' for l in levels]          # \u043b\u0438\u043d\u0438\u0438 \u0443\u0440\u043e\u0432\u043d\u044f         cp = ax.contour(x, y, z, levels = levels, colors = 'black')          ax.clabel(cp, fontsize = 8, colors = line_colors)                  # \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0442\u0438\u043f\u043e\u0432 \u0432\u043e\u0440\u043e\u043d\u043e\u043a         ax.axvline(0.5, linestyle = '-.', color = 'red')         ax.hlines(y = 0.5, xmin = 0.5, xmax = z.columns.values[-1], linestyle = '-.', color = 'red')         ax.text(0.07, 0.9, '\u0411\u044b\u0441\u0442\u0440\u043e\u0435', fontsize = 15, color = 'red')         ax.text(0.55, 0.9, '\u0423\u043c\u0435\u0440\u0435\u043d\u043d\u043e\u0435', fontsize = 15, color = 'red')         ax.text(0.55, 0.41, '\u0411\u044b\u0441\u0442\u0440\u043e\u0435\\n2-\u0439 \u0448\u0430\u0433', fontsize = 15, color = 'red')          # \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u043e\u0441\u0435\u0439 \u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438         plt.xlabel('\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433'), plt.ylabel('\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433')         plt.title(title)      for i, col in enumerate(result_column_names.keys()):         show_contour(result, 'first_step_prob', 'second_step_prob', col, levels, ax = plt.subplot(1, len(result_column_names), i + 1), title = result_column_names[col])     plt.suptitle(suptitle)     plt.show()          return result, errors<\/code><\/pre>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043d\u0430\u0431\u043e\u0440\u044b \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"python\"># \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f number_of_experiments = 100 alpha = 0.05  # \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a two_funnel_test_function = lambda funnel: [chisquare(funnel[1], funnel[0]).pvalue,                                                             # \u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a                                              chisquare(funnel['cont_1'], funnel['cont_0']).pvalue,                                               # \u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438                                              chi2_contingency(funnel[[0, 1]])[1],                                                                # \u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a                                              chi2_contingency(funnel[['cont_0', 'cont_1']])[1],                                                  # \u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0442\u044c\u0441 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438                                            proportions_ztest(funnel.loc[funnel.shape[0] - 1, [0, 1]].values, funnel.loc[0, [0, 1]].values)[1]  # z-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433 \u0432\u043e\u0440\u043e\u043d\u043a\u0438                                           ] two_funnel_result_column_names = {'chisquare_funnel': '$\\chi^2$-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a',                                    'chisquare_cont': '$\\chi^2$-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438',                                    'chi2_contingency_funnel': '$\\chi^2$-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a',                                    'cchi2_contingency_cont': '$\\chi^2$-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438',                                   'z_test': 'z-\u0442\u0435\u0441\u0442 \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0432\u043e\u0440\u043e\u043d\u043e\u043a'}  # \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u043e\u0432\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f 3 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a mult_funnel_test_function = lambda funnel: [chi2_contingency(funnel[[x for x in funnel.columns if 'cont' not in str(x)]])[1],                          # \u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a                                             chi2_contingency(funnel[[x for x in funnel.columns if 'cont' in str(x)]])[1]                               # \u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438                                            ] mult_funnel_result_column_names = {'chi2_contingency_funnel': '$\\chi^2$-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a',                                     'cchi2_contingency_cont': '$\\chi^2$-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438'}<\/code><\/pre>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u0440\u0442 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<pre><code class=\"python\"># \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b  # \u0443\u0440\u043e\u0432\u043d\u0438 \u0438 \u0446\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 type_1_error_levels = [0, 0.01, 0.05, 0.1, 0.2, 0.3, 1] type_1_error_color_map = matplotlib.colors.ListedColormap(['forestgreen',                                                            'palegreen',                                                             'lightcoral',                                                             'indianred',                                                            'maroon',                                                            'red'])  # \u0443\u0440\u043e\u0432\u043d\u0438 \u0438 \u0446\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 type_2_error_levels = [0, 0.1, 0.5, 0.7, 0.9, 0.95, 0.98, 1] type_2_error_color_map = matplotlib.colors.ListedColormap(['forestgreen',                                                            'lightcoral',                                                             'indianred',                                                            'brown',                                                            'firebrick',                                                            'maroon',                                                            'red'])  # \u0443\u0440\u043e\u0432\u043d\u0438 \u0438 \u0446\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 error_levels = [0, 0.1, 0.25, 0.5, 0.75, 0.9, 1] error_color_map = matplotlib.colors.ListedColormap(['palegreen',                                                      'honeydew',                                                      'floralwhite',                                                      'bisque',                                                      'navajowhite' ,                                                      'red'])<\/code><\/pre>\n<h4>5.1.1 \u041e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a<\/h4>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 (\u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435, \u043d\u043e \u0442\u0435\u0441\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435) \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [1] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = two_funnel_test_function,                                      result_column_names = two_funnel_result_column_names,                                      compare_func = lambda x, alpha: x &lt; alpha,                                       levels = type_1_error_levels,                                       color_map = type_1_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_type1err_ss{ss}_diff{str(diffs[0]).replace(\".\", \"\")}_numexp{number_of_experiments}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f07\/e75\/3fb\/f07e753fb00dacfcfe44c3def7c28673.png\" width=\"1571\" height=\"431\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f07\/e75\/3fb\/f07e753fb00dacfcfe44c3def7c28673.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5ff\/f18\/9dc\/5fff189dc148d9bd9c71bb9eebadf93e.png\" width=\"1562\" height=\"425\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5ff\/f18\/9dc\/5fff189dc148d9bd9c71bb9eebadf93e.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/041\/cea\/461\/041cea46102ee07c0cecf69a6a13899c.png\" width=\"1560\" height=\"423\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/041\/cea\/461\/041cea46102ee07c0cecf69a6a13899c.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/08a\/da3\/278\/08ada3278a3ea96f6bd777f693a2513f.png\" width=\"1561\" height=\"424\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/08a\/da3\/278\/08ada3278a3ea96f6bd777f693a2513f.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5fd\/aad\/993\/5fdaad99390c3cdfe79fecbbb9b5e2c1.png\" width=\"1565\" height=\"433\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5fd\/aad\/993\/5fdaad99390c3cdfe79fecbbb9b5e2c1.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0432\u043e\u0434\u044b \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0435\u0431\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u2014 \u043e\u043d \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0438\u0437\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u043f\u043b\u043e\u0445\u0438\u0435 \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0442\u0430\u043c, \u0433\u0434\u0435 \u0438\u0445 \u043d\u0435\u0442, \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0432\u044b\u0431\u043e\u0440\u043e\u043a. \u0414\u043e\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e 30%;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 <em>z<\/em>-\u0442\u0435\u0441\u0442 \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u0423\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e, \u043f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u0441\u044b\u0440\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043a\u0430\u0445 \u0434\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0435\u0441\u043b\u0438 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c\u0438 \u044f\u0447\u0435\u0439\u043a\u0430\u043c\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043e\u0448\u0438\u0431\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c.<\/p>\n<pre><code class=\"python\"># \u0430\u043d\u0430\u043b\u0438\u0437 \u043e\u0448\u0438\u0431\u043e\u043a # data \u2014 \u0444\u0440\u0435\u0439\u043c \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 # num_exp \u2014 \u0447\u0438\u0441\u043b\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0432\u043e\u0440\u043e\u043d\u043e\u043a # levels \u2014 \u043b\u0438\u043d\u0438\u0438 \u0443\u0440\u043e\u0432\u043d\u044f \u043d\u0430 \u043a\u0430\u0440\u0442\u0435 \u043e\u0448\u0438\u0431\u043e\u043a # color_map \u2014 \u0446\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u043e\u0448\u0438\u0431\u043e\u043a # title \u2014 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 def viz_errors(data, num_exp, levels, color_map, title = '\u0427\u0438\u0441\u043b\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438'):     plt.figure(figsize = (30, 5))      for i, ss in enumerate(data.keys()):          z = data[ss].pivot_table(index = 'second_step_prob', columns = 'first_step_prob', values = 'errors', aggfunc = 'max')         z = z \/ num_exp         x, y = z.index.values, z.columns          # \u0437\u0430\u043a\u0440\u0430\u0441\u043a\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439         ax = plt.subplot(1, len(errors.keys()), i + 1)         ax.contourf(x, y, z, levels = levels, cmap = color_map, alpha = 0.3, norm = matplotlib.colors.BoundaryNorm(levels,len(levels)))         line_colors = ['black' for l in levels]          # \u043b\u0438\u043d\u0438\u0438 \u0443\u0440\u043e\u0432\u043d\u044f         cp = ax.contour(x, y, z, levels = levels, colors = 'black')          ax.clabel(cp, fontsize = 8, colors = line_colors)          plt.xlabel('\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433'), plt.ylabel('\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433')         plt.title(f'\u0420\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438: {ss}')      plt.suptitle(title)  # \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0447\u0438\u0441\u043b\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a viz_errors(errors, number_of_experiments, levels = error_levels, color_map = error_color_map) <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2d7\/61a\/fca\/2d761afcae19f5a70e6717fb2218193c.png\" width=\"1554\" height=\"319\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2d7\/61a\/fca\/2d761afcae19f5a70e6717fb2218193c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u0432\u044b\u0448\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0431\u043e\u043b\u044c\u0448\u0435 100 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0414\u043b\u044f \u043c\u0435\u043d\u044c\u0448\u0438\u0445 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b\u043c\u0438 \u0441 \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u2014 \u0442\u0443\u0442 \u0434\u043e\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0434\u043e 90%.<\/p>\n<h4>5.1.2 \u041e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a<\/h4>\n<p>\u041f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 (\u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0435\u0441\u0442\u044c, \u043d\u043e \u043e\u043d\u0438 \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u043e\u043c). \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 10%:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [0.9] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = two_funnel_test_function,                                      result_column_names = two_funnel_result_column_names,                                      compare_func = lambda x, alpha: x > alpha,                                       levels = type_2_error_levels,                                       color_map = type_2_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 {1-diffs[0]:.0%}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_type2err_ss{ss}_diff{str(diffs[0]).replace(\".\", \"\")}_numexp{number_of_experiments}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bda\/5c2\/0a2\/bda5c20a2e87562909a4f72d84c37a9b.png\" width=\"1570\" height=\"425\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bda\/5c2\/0a2\/bda5c20a2e87562909a4f72d84c37a9b.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8a5\/463\/85c\/8a546385c191e313ea15905e78253a26.png\" width=\"1569\" height=\"426\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8a5\/463\/85c\/8a546385c191e313ea15905e78253a26.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/338\/17c\/a6e\/33817ca6eaec44b02860da3d8d45872f.png\" width=\"1552\" height=\"431\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/338\/17c\/a6e\/33817ca6eaec44b02860da3d8d45872f.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8af\/16d\/d40\/8af16dd40248e716b9b1215573fa7d0d.png\" width=\"1565\" height=\"429\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8af\/16d\/d40\/8af16dd40248e716b9b1215573fa7d0d.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/938\/541\/701\/9385417015ee0b951a0ce571ce7e7824.png\" width=\"1553\" height=\"428\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/938\/541\/701\/9385417015ee0b951a0ce571ce7e7824.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0432\u043e\u0434\u044b \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0445\u0443\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0435\u0431\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u2014 \u0434\u0430\u0436\u0435 \u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u044d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0442\u0430\u043c, \u0433\u0434\u0435 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 <em>z<\/em>-\u0442\u0435\u0441\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043e\u043d\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0434\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0435\u0431\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0421 \u0440\u043e\u0441\u0442\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u043e\u043d\u0438 \u0432\u0441\u0435 \u043b\u0443\u0447\u0448\u0435 \u0438 \u043b\u0443\u0447\u0448\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0440\u0435\u0437\u043a\u0438\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0448\u0430\u0433\u0435 \u0438 \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u044b \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 <em>z<\/em>-\u0442\u0435\u0441\u0442 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c\u044e, \u0447\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 20%:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [0.8] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = two_funnel_test_function,                                      result_column_names = two_funnel_result_column_names,                                      compare_func = lambda x, alpha: x > alpha,                                       levels = type_2_error_levels,                                       color_map = type_2_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 {1-diffs[0]:.0%}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_type2err_ss{ss}_diff{str(diffs[0]).replace(\".\", \"\")}_numexp{number_of_experiments}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b99\/3b4\/080\/b993b40802f591c23d91a26c9474403a.png\" width=\"1562\" height=\"427\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b99\/3b4\/080\/b993b40802f591c23d91a26c9474403a.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/eb8\/7b1\/6d2\/eb87b16d2ba73d867e278f88db68ce79.png\" width=\"1563\" height=\"431\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb8\/7b1\/6d2\/eb87b16d2ba73d867e278f88db68ce79.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/666\/aa9\/a95\/666aa9a9525898fce482cfe588f076fc.png\" width=\"1565\" height=\"423\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/666\/aa9\/a95\/666aa9a9525898fce482cfe588f076fc.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7ae\/2e2\/fbd\/7ae2e2fbd29acd9d3300897c0e38cb2f.png\" width=\"1558\" height=\"435\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ae\/2e2\/fbd\/7ae2e2fbd29acd9d3300897c0e38cb2f.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c38\/53d\/f7a\/c3853df7af3c06cf1f479539c5ee7052.png\" width=\"1556\" height=\"435\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c38\/53d\/f7a\/c3853df7af3c06cf1f479539c5ee7052.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u0440\u0442\u0438\u043d\u0430 \u0432 \u0446\u0435\u043b\u043e\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443:<\/p>\n<ul>\n<li>\n<p>\u0445\u0443\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0441\u0430\u043c\u044b\u0435 \u043f\u043b\u043e\u0445\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p>\u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0435\u0431\u044f \u043f\u0440\u043e\u044f\u0432\u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0435 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p><em>z<\/em>-\u0442\u0435\u0441\u0442, \u043f\u043e\u0445\u043e\u0436\u0435, \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 30%:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [0.7] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = two_funnel_test_function,                                      result_column_names = two_funnel_result_column_names,                                      compare_func = lambda x, alpha: x > alpha,                                       levels = type_2_error_levels,                                       color_map = type_2_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, \u0432\u043e\u0440\u043e\u043d\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 {1-diffs[0]:.0%}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_type2err_ss{ss}_diff{str(diffs[0]).replace(\".\", \"\")}_numexp{number_of_experiments}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/36f\/4d1\/f80\/36f4d1f80d8d2b9ee905a51aabb21235.png\" width=\"1555\" height=\"429\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/36f\/4d1\/f80\/36f4d1f80d8d2b9ee905a51aabb21235.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3c5\/c19\/8f2\/3c5c198f2d2da562b924c49734b70a0d.png\" width=\"1555\" height=\"424\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3c5\/c19\/8f2\/3c5c198f2d2da562b924c49734b70a0d.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d91\/211\/27e\/d9121127e9ec3869e1cd210edf3ff3ad.png\" width=\"1553\" height=\"428\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d91\/211\/27e\/d9121127e9ec3869e1cd210edf3ff3ad.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2c1\/058\/477\/2c10584778ffae30564cdd3f572f2e26.png\" width=\"1559\" height=\"429\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2c1\/058\/477\/2c10584778ffae30564cdd3f572f2e26.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/728\/717\/c03\/728717c03796062debc0e55e5ea61f2a.png\" width=\"1551\" height=\"429\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/728\/717\/c03\/728717c03796062debc0e55e5ea61f2a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0430 <em>z<\/em>-\u0442\u0435\u0441\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043b\u043e\u0445\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a.<\/p>\n<p>\u041e\u0431\u0449\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u044b \u0434\u043b\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441 \u0434\u0432\u0443\u043c\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0441\u0430\u043c\u0443\u044e \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u2014 \u043e\u043d\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432 \u0432\u043e\u0440\u043e\u043d\u043a\u0430\u0445 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u0445, \u0435\u0441\u043b\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0435\u043b\u0438\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u043d\u0438 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0441\u0430\u043c\u044b\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u2014 \u0447\u0430\u0449\u0435 \u0437\u0430\u0441\u0435\u043a\u0430\u044e\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0435\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p><em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041e\u043d\u0438 \u043a\u043e\u043d\u0441\u0435\u0440\u0432\u0430\u0442\u0438\u0432\u043d\u044b, \u0440\u0435\u0436\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430, \u043d\u043e \u0447\u0430\u0449\u0435 \u2014 \u0432\u0442\u043e\u0440\u043e\u0433\u043e;<\/p>\n<\/li>\n<li>\n<p><em>z<\/em>-\u0442\u0435\u0441\u0442 \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u0445\u043e\u0440\u043e\u0448\u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430\u043c\u0438. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, <em>z<\/em>-\u0442\u0435\u0441\u0442 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0440\u0435\u0433\u0438\u043e\u043d\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043b\u044e\u0431\u044b\u043c <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u2014 \u044d\u0442\u043e \u0440\u0435\u0433\u0438\u043e\u043d \u0432\u044b\u0441\u043e\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 \u0432\u0441\u0435\u0445 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u2014 \u043e\u043d \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0438 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c\u044e;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0435 \u043b\u0438 \u0432\u044b <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a.<\/p>\n<\/li>\n<\/ul>\n<h3>5.2 \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u043e\u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u0440\u0435\u0445 \u0438 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u0439. \u042d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0434\u0430\u0441\u0442 \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441, \u043a\u0430\u043a \u043f\u043e\u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0442\u0435\u0441\u0442\u044b \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u043d\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [1, 1] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = mult_funnel_test_function,                                      result_column_names = mult_funnel_result_column_names,                                      compare_func = lambda x, alpha: x &lt; alpha,                                       levels = type_1_error_levels,                                       color_map = type_1_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_contingency_multiple_type1err_ss{ss}_numexp{number_of_experiments}_diffs{len(diffs)}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b98\/158\/829\/b9815882940977ed6882779658565480.png\" width=\"1578\" height=\"432\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b98\/158\/829\/b9815882940977ed6882779658565480.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d02\/c3a\/7f5\/d02c3a7f5f6108f979919a39184d09b2.png\" width=\"1574\" height=\"435\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d02\/c3a\/7f5\/d02c3a7f5f6108f979919a39184d09b2.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9af\/736\/3b5\/9af7363b56f5eadd93d167c77ffb55e6.png\" width=\"1561\" height=\"424\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9af\/736\/3b5\/9af7363b56f5eadd93d167c77ffb55e6.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a77\/3b0\/94d\/a773b094dacf5baefdb9a290c2c9c864.png\" width=\"1564\" height=\"426\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a77\/3b0\/94d\/a773b094dacf5baefdb9a290c2c9c864.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6d0\/b75\/ccd\/6d0b75ccd7237b6a3d569c990d7c020f.png\" width=\"1565\" height=\"431\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6d0\/b75\/ccd\/6d0b75ccd7237b6a3d569c990d7c020f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [1, 1, 1] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = mult_funnel_test_function,                                      result_column_names = mult_funnel_result_column_names,                                      compare_func = lambda x, alpha: x &lt; alpha,                                       levels = type_1_error_levels,                                       color_map = type_1_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_contingency_multiple_type1err_ss{ss}_numexp{number_of_experiments}_diffs{len(diffs)}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e44\/39e\/759\/e4439e759b1297b6f8064969cc4e9385.png\" width=\"1568\" height=\"430\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e44\/39e\/759\/e4439e759b1297b6f8064969cc4e9385.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4f4\/86a\/64e\/4f486a64e206ccf414a2b0f811299679.png\" width=\"1587\" height=\"423\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4f4\/86a\/64e\/4f486a64e206ccf414a2b0f811299679.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/048\/7ea\/6f2\/0487ea6f242313fdf80a48082c3a56cd.png\" width=\"1562\" height=\"423\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/048\/7ea\/6f2\/0487ea6f242313fdf80a48082c3a56cd.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e73\/8ac\/395\/e738ac395c5a610c9e04213fae5edeb2.png\" width=\"1556\" height=\"429\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e73\/8ac\/395\/e738ac395c5a610c9e04213fae5edeb2.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c00\/79b\/c41\/c0079bc412454225e542bba2e11cda5e.png\" width=\"1574\" height=\"435\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c00\/79b\/c41\/c0079bc412454225e542bba2e11cda5e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0446\u0435\u043d\u0438\u043c \u0434\u043e\u043b\u0438 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<pre><code class=\"python\"># \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0447\u0438\u0441\u043b\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a viz_errors(errors, number_of_experiments, levels = error_levels, color_map = error_color_map)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3c6\/939\/0a4\/3c69390a4be558a1274f3503cf7bc117.png\" width=\"1567\" height=\"321\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3c6\/939\/0a4\/3c69390a4be558a1274f3503cf7bc117.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0432\u043e\u0434\u044b \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0434\u0432\u0443\u043c\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0430\u043c, \u0442\u0435\u0441\u0442\u044b, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043c\u0435\u043d\u044c\u0448\u0443\u044e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043e\u043a. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 100, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0440\u0435\u0437\u043a\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0437\u0430\u0442\u0435\u043c \u0441\u043d\u043e\u0432\u0430 \u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0432\u044b\u0431\u043e\u0440\u043e\u043a. \u041f\u0440\u0438\u0440\u043e\u0434\u0430 \u044d\u0442\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u044f\u0441\u043d\u0430;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0442\u0440\u0435\u0445 \u0438 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u044f \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0435\u043b\u0438\u043a\u0430 \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0440\u0435\u0437\u043a\u0438\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c. \u041d\u043e, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u044b\u0431\u043e\u0440\u043e\u043a, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0442 100 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0438 \u0431\u043e\u043b\u0435\u0435, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043e\u043d\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430. \u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0442\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0434\u043d\u0430 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 10% \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0432\u0443\u0445:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [1, 0.9] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = mult_funnel_test_function,                                      result_column_names = mult_funnel_result_column_names,                                      compare_func = lambda x, alpha: x > alpha,                                       levels = type_2_error_levels,                                       color_map = type_2_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 {1-diffs[1]:.0%}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_contingency_type2err_ss{ss}_diff{str(diffs[0]).replace(\".\", \"\")}_numexp{number_of_experiments}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d4e\/7be\/a69\/d4e7bea69dcb22450148d972149b8963.png\" width=\"1570\" height=\"423\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d4e\/7be\/a69\/d4e7bea69dcb22450148d972149b8963.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/32a\/b76\/cbb\/32ab76cbb1aab58ff33348fc1034e91a.png\" width=\"1568\" height=\"427\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/32a\/b76\/cbb\/32ab76cbb1aab58ff33348fc1034e91a.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dee\/64b\/003\/dee64b003c13682af83646e49625ac1f.png\" width=\"1572\" height=\"422\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dee\/64b\/003\/dee64b003c13682af83646e49625ac1f.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/33b\/7e1\/995\/33b7e199537415449b6f98163361c16c.png\" width=\"1563\" height=\"425\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/33b\/7e1\/995\/33b7e199537415449b6f98163361c16c.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0d7\/9f9\/84b\/0d79f984bb0eee3a5414860852ae937e.png\" width=\"1575\" height=\"428\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0d7\/9f9\/84b\/0d79f984bb0eee3a5414860852ae937e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0442\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438\u043c\u0435\u0435\u0442 10% \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u044d\u0442\u0430\u043b\u043e\u043d\u0430, \u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u2014\u00a030% \u043e\u0442\u043b\u0438\u0447\u0438\u0435:<\/p>\n<pre><code class=\"python\"># \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u0440\u0435\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a diffs = [0.9, 0.7] results, errors = {}, {} for ss in [25, 50, 100, 200, 500]:     res, err = run_error_experiments(funnel_log, diffs = diffs, sample_size = ss, number_of_experiments = number_of_experiments, alpha = alpha,                                       test_func = mult_funnel_test_function,                                      result_column_names = mult_funnel_result_column_names,                                      compare_func = lambda x, alpha: x > alpha,                                       levels = type_2_error_levels,                                       color_map = type_2_error_color_map,                                      suptitle = f'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 $\\chi^2$ \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 {ss}, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 {1-diffs[1]:.0%}, $\\\\alpha$ = {alpha}',                                      filename_template = f'chi2_contingency_type2err_ss{ss}_diff{str(diffs[0]).replace(\".\", \"\")}_numexp{number_of_experiments}')     errors[ss] = err     results[ss] = res<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0f4\/b95\/bf1\/0f4b95bf1f7e88c9639f02cae98018ae.png\" width=\"1577\" height=\"428\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0f4\/b95\/bf1\/0f4b95bf1f7e88c9639f02cae98018ae.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/272\/94a\/05a\/27294a05aedeee40591b10d9fdf565d0.png\" width=\"1578\" height=\"420\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/272\/94a\/05a\/27294a05aedeee40591b10d9fdf565d0.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/315\/a07\/679\/315a076791bca4ed80bd61f3c60cfd87.png\" width=\"1570\" height=\"422\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/315\/a07\/679\/315a076791bca4ed80bd61f3c60cfd87.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e7a\/629\/832\/e7a629832839264273510d1ace7837c7.png\" width=\"1563\" height=\"428\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e7a\/629\/832\/e7a629832839264273510d1ace7837c7.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/349\/d6c\/127\/349d6c12703f1e280088575b8ea718ad.png\" width=\"1562\" height=\"425\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/349\/d6c\/127\/349d6c12703f1e280088575b8ea718ad.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0432\u043e\u0434\u044b \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0432 \u043e\u0431\u043e\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445 \u0442\u0435\u0441\u0442\u044b \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c;<\/p>\n<\/li>\n<li>\n<p>\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0438 \u0440\u043e\u0441\u0442\u043e\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u043d\u043e \u0434\u0430\u0436\u0435 \u0432 \u0441\u0430\u043c\u043e\u043c \u043b\u0443\u0447\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0435\u0441\u0442\u044b \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0440\u043e\u0432\u0435\u0434\u044f \u0441\u0435\u0440\u0438\u044e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>\u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a <em>z<\/em>-\u0442\u0435\u0441\u0442 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u0435\u043d, \u0447\u0435\u043c \u0442\u0435\u0441\u0442 <em>\u03c7<\/em>\u00b2;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438\u0437 \u0432\u0441\u0435\u0445 \u0442\u0435\u0441\u0442\u043e\u0432<em> \u03c7<\/em>\u00b2 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c;<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043e\u043a <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0438 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c\u044b\u0439 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u0441\u0442\u043e\u043c <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u043e\u0440\u043e\u043d\u043e\u043a.<\/p>\n<\/li>\n<\/ul>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u044b <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0438 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0432\u0443\u0445 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0439 <em>z<\/em>-\u0442\u0435\u0441\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0443 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 2 x 2.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0431\u0440\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0430 500 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u0440\u043e\u043d\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u03c7\u00b2-\u0442\u0435\u0441\u0442\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c\u044b\u0439 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0434\u0432\u0443\u0445 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<a href=\"https:\/\/github.com\/vyacheslav-zotov\/articles\/blob\/main\/%D0%A1%D1%82%D0%B0%D1%82%D1%8C%D1%8F_%D0%A2%D0%B5%D1%81%D1%82%20Chi2.ipynb\"> <u>\u0442\u0443\u0442<\/u><\/a> (\u0438\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0441\u0447\u0435\u0442 \u043e\u0448\u0438\u0431\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f).<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/677074\/\"> https:\/\/habr.com\/ru\/articles\/677074\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u044f\u0447\u0435\u0441\u043b\u0430\u0432 \u0417\u043e\u0442\u043e\u0432, \u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a \u0432 \u0441\u0442\u0443\u0434\u0438\u0438 Whalekit. \u0412 \u044d\u0442\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u044b, \u043a\u0430\u043a\u043e\u0432\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u044c <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u043e\u0432 \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0432\u043e\u0440\u043e\u043d\u043e\u043a. \u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043d\u0430 Python.<\/p>\n<p>\u0422\u0435\u0441\u0442 <em>\u03c7<\/em>\u00b2 \u2014 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u043e\u0432 \u043d\u0435\u0434\u043e\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0443. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0435\u043b\u043e\u0435 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432 <em>\u03c7<\/em>\u00b2, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u044b <em>\u03c7<\/em>\u00b2 \u0447\u0430\u0441\u0442\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0445 \u0438 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u0445 \u0432\u043e\u0440\u043e\u043d\u043e\u043a, \u0430 \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>1. \u03c7\u00b2-\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a:<\/p>\n<pre><code class=\"python\">import warnings warnings.filterwarnings('ignore')  import os import math import random import re  import pandas as pd import numpy as np  import scipy.stats as stats  from matplotlib import pyplot as plt import matplotlib.ticker as mtick import seaborn as sns from matplotlib import cm import matplotlib.colors<\/code><\/pre>\n<p>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u0438 \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b:<\/p>\n<pre><code class=\"python\">np.random.seed(1234)  size = 10000 # \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 loc = 0 scale = 1  result = pd.DataFrame([[0] * size], index = ['chi2_1']).T  plt.figure(figsize = (15, 5))  # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b k for k in range(2, 22, 3):          # \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0440\u0435\u0439\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432     current_result = pd.DataFrame([[0] * size], index = [1]).T          # \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0443\u0436\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0443\u043c\u043c\u0443 \u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432     for i in range(1, k + 1): current_result[i] = pd.Series(np.random.normal(loc = loc, scale = scale, size = size))          # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0443\u043c\u043c\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432     current_result['chi2'] = (current_result * current_result).sum(axis = 1)          sns.kdeplot(current_result['chi2'], label = 'k = {}'.format(k))      plt.legend(title = '\u0421\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b'), plt.ylabel('$f_k(x)$'), plt.xlabel('$x$'), plt.title('\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f $\\chi_k^2$') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>2. \u03c7\u00b2-\u0442\u0435\u0441\u0442\u044b<\/h2>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 <em>\u03c7<\/em>\u00b2-\u0442\u0435\u0441\u0442\u0430.<\/p>\n<ol>\n<li>\n<p>\u0422\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c (test of homogeneity, \u043e\u043d \u0436\u0435 goodness of fit) \u2014 \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439, \u043e\u0434\u043d\u043e\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e. \u0412 Python \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>scipy.stats.chisquare<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442 \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c (\u043e\u043d \u0436\u0435 test of independence\/association) \u2014 \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439, \u043e\u0434\u043d\u043e\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438. \u0412 Python \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>scipy.stats.chi2_contingency<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442 \u0434\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f), \u043e\u0434\u043d\u043e\u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u043e\u0433\u0443. \u0412 Python \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0442\u0435\u0441\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u044f \u041f\u0438\u0440\u0441\u043e\u043d\u0430 (\u041a\u0421\u041f), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2. \u0422\u0440\u0435\u0442\u0438\u0439 \u0442\u0435\u0441\u0442 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0432\u0443\u043c \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442, \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2 (\u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0438\u0436\u0435).<\/p>\n<p>\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u044f \u041f\u0438\u0440\u0441\u043e\u043d\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435:<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c:<\/p>\n<ul>\n<li>\n<p><em>O<\/em> \u2014 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435;<\/p>\n<\/li>\n<li>\n<p><em>E <\/em>\u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u041a\u0421\u041f \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u043c \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 (\u043d\u0430\u043c \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0439, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u043a\u0442 \u0438\u0445 \u043d\u0430\u043b\u0438\u0447\u0438\u044f) \u0438 \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0435 \u0440\u043e\u0441\u043b\u0430).<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u044d\u0442\u0430\u043b\u043e\u043d\u043e\u0432, \u0442\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u041a\u0421\u041f \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0430\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<p>\u0412 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 <em>O <\/em>\u0438 <em>E <\/em>\u0438\u043c\u0435\u044e\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u041a\u0421\u041f \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <em>\u03c7<\/em>\u00b2.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0435\u0441\u0442 \u0441 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>H0: \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>H1: \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043d\u0435\u0442, \u0442\u043e \u041a\u0421\u041f \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0443\u043b\u044e. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u0441\u0442\u044b \u0441 \u041a\u0421\u041f, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 (\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u044e\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439) \u0438 \u043e\u0434\u043d\u043e\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 (\u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u2014 \u0432\u043e\u0442<a href=\"https:\/\/stats.stackexchange.com\/questions\/171074\/chi-square-test-why-is-the-chi-squared-test-a-one-tailed-test\"> <u>\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f<\/u><\/a> \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u0441\u0442 \u043d\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0441 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c (\u0431\u0435\u0437 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u043c\u0435\u0449\u0435\u043d\u043d\u044b\u0445 \u043e\u0446\u0435\u043d\u043e\u043a \u043a\u0430\u043a \u0432 <em>z<\/em>&#8212; \u0438 <em>t<\/em>-\u0442\u0435\u0441\u0442\u0430\u0445).<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043d\u044e\u0430\u043d\u0441 \u2014 <em>O<\/em> \u0438 <em>E <\/em>\u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u043c\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f (\u0432\u043e\u0442 <a href=\"https:\/\/www.real-statistics.com\/chi-square-and-f-distributions\/goodness-of-fit\/\"><u>\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435<\/u><\/a> \u043f\u043e \u0442\u0435\u043c\u0435).<\/p>\n<h3>2.1 \u03c7\u00b2-\u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c (homogeneity, goodness of fit)<\/h3>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0432 \u0433\u0440\u0443\u043f\u043f\u0430\u0445 (Observed) \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f (Expected):<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430 goodness of fit \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>H0: <em>O<\/em>\u2081 = <em>O<\/em>\u2082 = <em>O<\/em>\u2083 = &#8230; = <em>O<\/em>\u2099 (\u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u0441 \u0440\u0430\u0432\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u0440\u0443\u043f\u043f);<\/p>\n<\/li>\n<li>\n<p>H1: \u0425\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u0430 \u0438\u0437 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 <em>O<\/em><a href=\"https:\/\/unicode-table.com\/en\/sets\/superscript-and-subscript-letters\/\"><em>\u1d62<\/em><\/a> \u043d\u0435 \u0440\u0430\u0432\u043d\u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0438\u043b\u0438 \u0442\u0430\u043a\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>H0: <em>O<\/em>\u2081 = <em>E<\/em>\u2081, <em>O<\/em>\u2082 = <em>E<\/em>\u2082, <em>O<\/em>\u2083 = <em>E<\/em>\u2083, &#8230;, <em>O<\/em>\u2099 = <em>E<\/em>\u2099 (\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e);<\/p>\n<\/li>\n<li>\n<p>H1: \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <em>O<\/em><a href=\"https:\/\/unicode-table.com\/en\/sets\/superscript-and-subscript-letters\/\"><em>\u1d62<\/em><\/a> \u043d\u0435 \u0440\u0430\u0432\u043d\u0430 <em>E<\/em><a href=\"https:\/\/unicode-table.com\/en\/sets\/superscript-and-subscript-letters\/\"><em>\u1d62<\/em><\/a> (\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 (<a href=\"https:\/\/www.jmp.com\/en_ca\/statistics-knowledge-portal\/chi-square-test\/chi-square-goodness-of-fit-test.html\"><u>\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/u><\/a>):<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c p-value \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <em>\u03c7<\/em>\u00b2 \u043f\u0440\u0438 \u0447\u0438\u0441\u043b\u0435 \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b <em>d <\/em>= (<em>n<\/em>-1) = 4:<\/p>\n<pre><code class=\"python\">1 - stats.chi2.cdf(52.75, 4)<\/code><\/pre>\n<p><code>9.612521889579284e-11<\/code><\/p>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u0432 \u0435\u0433\u043e \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 \u03b1 = 0.05, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0443\u043b\u0435\u0432\u0430\u044f \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430 \u043e\u0442\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u043e\u043d\u0444\u0435\u0442\u044b \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u043e \u0432\u043a\u0443\u0441\u0430\u043c \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e.<\/p>\n<p>\u0415\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0441\u0447\u0435\u0442\u0430:<a href=\"https:\/\/www.sbcc.edu\/mathematics\/mathlab\/docs\/worksheets\/chisquare.pdf\"> <u>\u043e\u0434\u0438\u043d<\/u><\/a> \u0438<a href=\"https:\/\/online.stat.psu.edu\/stat500\/lesson\/8\/8.2\"> <u>\u0432\u0442\u043e\u0440\u043e\u0439<\/u><\/a>.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"python\">def diy_chisquare(observed, expected):     # \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443     k = len(observed)                                                         # \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b      statistic = (((observed - expected)**2)\/expected).sum()                   # \u041a\u0421\u041f          # \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c p-value      p_value = 1 - stats.chi2.cdf(statistic, k - 1)                            # \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435          return k - 1, statistic, p_value<\/code><\/pre>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u043c \u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\"># \u0437\u0430\u0434\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 np.random.seed(1234)  data = np.array([180, 250, 120, 225, 225]) expected = np.array([200, 200, 200, 200, 200])  # \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0430\u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 display(diy_chisquare(data, expected))  # \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 from scipy.stats import chisquare chisquare(data, expected)<\/code><\/pre>\n<p><code>(4, 52.75, 9.612521889579284e-11)  <\/code><\/p>\n<p><code>Power_divergenceResult(statistic=52.75, pvalue=9.612518035368181e-11)  <\/code><\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0430 \u0440\u0430\u0434\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u041a\u0421\u041f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e <em>\u03c7<\/em>\u00b2. \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"python\">def generate_max_likelihood_distro(size, num_samples, sample_size, k_range, ax, ax2, ax3, title):          ks_results = []     for line_i, k in enumerate(k_range): # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f)          data = pd.Series(np.random.choice(k, size, p = [1 \/ k] * k))                    # \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0433\u0440\u0443\u043f\u043f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439          max_likelihood = []         for i in range(num_samples):             observed = data.sample(sample_size, replace = True).value_counts()          # \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439             expected = sample_size\/k                                                    # \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439             max_likelihood += [[i,                                  k - 1,                                  (((observed - expected)**2)\/expected).sum()             # \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u0435                                ]]           max_likelihood = pd.DataFrame(max_likelihood, columns = ['Sample #', 'Degrees of freedom', 'Max likelyhood distribution'])                  # \u0441\u0442\u0440\u043e\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439         sns.kdeplot(max_likelihood['Max likelyhood distribution'], label = 'k = {}'.format(k), ax = ax)         ax.legend(title = '\u0421\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b'), ax.set_ylabel('$f_k(x)$'), ax.set_xlabel('$x$'), ax.set_title(title)                  # \u0441\u0442\u0440\u043e\u0438\u043c qq-\u0433\u0440\u0430\u0444\u0438\u043a\u0438         stats.probplot(max_likelihood['Max likelyhood distribution'],                         dist = stats.chi2, sparams = (k - 1), # chi2 \u0441 \u0447\u0438\u0441\u043b\u043e\u043c \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u044b k-1                        plot = ax2, fit = False)         line_index = (line_i + 1) * 2         (ax2.get_lines()[line_index - 2].set_color(ax.get_lines()[line_i].get_color()),           ax2.get_lines()[line_index - 2].set_label('k = {}'.format(k)),           ax2.get_lines()[line_index - 2].set_markersize(3),           ax2.get_lines()[line_index - 2].set_alpha(0.5)         )         ax2.get_lines()[line_index - 1].set_color('lightgrey'), ax2.get_lines()[line_index - 1].set_linestyle(':')         ax2.set_title('\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e $\\chi^2$'), ax2.legend(title = '\u0421\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b')                  # \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u041a\u0421-\u0442\u0435\u0441\u0442         ks_stat, ks_p = stats.kstest(max_likelihood['Max likelyhood distribution'], 'chi2', args = (k - 1, ))         ks_results.append([k, ks_stat, ks_p])              ks_results = pd.DataFrame(ks_results, columns = ['k', 'statistic', 'p']).set_index('k')     ks_results[['p']].plot(ax = ax3, xticks = ks_results.index, label = '$p$-value')     ax3.axhline(0.05 \/ len(k_range), color = 'red', linestyle = ':', label = 'alpha = {:.2f}'.format(0.05 \/ len(k_range))) # \u0441 \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u0435\u0439 \u0411\u043e\u043d\u0444\u0435\u0440\u0440\u043e\u043d\u0438     ax3.set_ylabel('$p$-value'), ax3.set_xlabel('$k$ (\u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u044b)'), ax3.set_title('\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u041a\u0421-\u0442\u0435\u0441\u0442\u0430'), ax3.legend()<\/code><\/pre>\n<p>\u0418\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e <em>\u03c7<\/em>\u00b2:<\/p>\n<pre><code class=\"python\">np.random.seed(12345)  size = 100000             # \u0440\u0430\u0437\u043c\u0435\u0440 \u00ab\u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u0438\u00bb \u2014 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 num_samples = 1000 sample_size = 100  plt.figure(figsize = (25, 12)) sample_sizes = [10, 50, 100, 500,<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-416855","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/416855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=416855"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/416855\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=416855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=416855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=416855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}