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
#Analtyical solution to compute sample size | |
from statsmodels.stats.power import tt_ind_solve_power | |
treat_mean=control_mean*(1+delta) | |
mean_diff=treat_mean-control_mean | |
cohen_d=mean_diff/np.sqrt((control_sd**2+control_sd**2)/2) | |
n = tt_ind_solve_power(effect_size=cohen_d, alpha=alpha, power=0.8, ratio=1, alternative='two-sided') | |
print('Minimum sample size required to reach significance: {:.0f}'.format(round(n))) |
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
#increment sample size till required power is reached | |
sample_size=1000 | |
np.random.seed(123) | |
while True: | |
control_time_spent, treatment_time_spent=simulate_data(control_mean,control_sd,sample_size,n_sim) | |
t_stat, p_value = st.ttest_ind(control_time_spent, treatment_time_spent) | |
power=(p_value<alpha).sum()/n_sim | |
if power>.80: | |
print("Minimum sample size required to reach significance {}".format(sample_size)) | |
break |
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 scipy.stats as st | |
# Initialize delta(minimum lift the product manager expect), control_mean, control_sd | |
delta=0.05 | |
control_mean=2 | |
control_sd=1 | |
sample_size=1000 | |
alpha=0.05#significance of the experiment | |
n_sim=1000#Total number of samples to simulate |
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
# sql.export.gbm(): save a GBM model as SQL | |
# v0.11 | |
# Copyright (c) 2013-2014 Shane Butler <shane dot butler at gmail dot com> | |
# | |
# sql.export.gbm is free software: you can redistribute it and/or modify it | |
# under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# sql.export.gbm is distributed in the hope that it will be useful, but |
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
# sql.export.rf(): save a randomForest model as SQL | |
# v0.04 | |
# Copyright (c) 2013-2014 Shane Butler <shane dot butler at gmail dot com> | |
# | |
# sql.export.rf is free software: you can redistribute it and/or modify it | |
# under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# sql.export.rf is distributed in the hope that it will be useful, but |