-
-
Save aboutisya/ce27cf7bf045e9f78d8704812443a42f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import pandas as pd | |
| from scipy.stats import binom, ttest_ind | |
| # Сгенерированные данные. Представим, что моделируем экономику A/B в подписочном SaaS | |
| pricing = np.array([0.99, 4.99, 9.99]) # цены в подписочной модели продукта | |
| # Доля покупок по каждой цене. Представим гипотезу, в которой мы хотим увеличить долю | |
| # платящих клиентов по самой дорогой цене, немного снизив долю по низкой | |
| proportions_control = np.array([0.5, 0.4, 0.1]) | |
| proportions_test = np.array([0.49, 0.4, 0.11]) | |
| N = 10000 | |
| sizes = np.arange(1000, 10001, 1000) | |
| simulations = 1000 | |
| sim_res = pd.DataFrame() | |
| np.random.seed(1) | |
| control_pop = np.random.choice(pricing, N, p=proportions_control) | |
| test_pop = np.random.choice(pricing, N, p=proportions_test) | |
| for n in sizes: | |
| control = control_pop[0:n] | |
| test = test_pop[0:n] | |
| for _ in range(0, simulations): | |
| # Рандомное присвоение групп A/B | |
| is_control = binom.rvs(1, 0.5, size=n) | |
| # Считаем p-value | |
| _, p = ttest_ind(control[is_control == True], test[is_control == False]) | |
| # Кладем результат | |
| sim_res = sim_res.append({"n": n, "pvalue": p}, ignore_index=True) | |
| res = sim_res.groupby(["n"]).apply(lambda x: sum(x['pvalue'] < 0.05) / simulations) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment