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 seaborn as sns | |
| import pandas as pd | |
| from pandas.plotting import scatter_matrix | |
| import matplotlib.pyplot as plt | |
| from scipy import stats | |
| from scipy.stats import norm | |
| from sklearn.datasets import fetch_california_housing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from scipy import stats | |
| X1 = stats.norm.rvs(loc=10, scale=2, size=30, random_state=0) | |
| X2 = stats.norm.rvs(loc=10, scale=2, size=30, random_state=1) | |
| X3 = stats.norm.rvs(loc=14, scale=2, size=30, random_state=2) | |
| print(stats.ttest_ind(X1, X2)) | |
| print(stats.ttest_ind(X1, X3)) |
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
| t_values_array = [] | |
| for i in range(100000): | |
| X1 = stats.norm.rvs(loc=10, scale=2, size=30, random_state=(i+1)) | |
| X2 = stats.norm.rvs(loc=10, scale=2, size=30, random_state=2*(i+1)) | |
| mean_X1 = np.mean(X1) | |
| mean_X2 = np.mean(X2) | |
| std_X1 = np.std(X1) | |
| std_X2 = np.std(X2) |
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
| t_test_function(rvs1, alpha=0.05, no_test=100) | |
| t_test_function(rvs2, alpha=0.05, no_test=100) | |
| bonferroni_correction_function(rvs1, alpha=0.05, no_test=100) | |
| bonferroni_correction_function(rvs2, alpha=0.05, no_test=100) | |
| bonferroni_holm_correction_function(rvs1, alpha=0.05, no_test=100) | |
| bonferroni_holm_correction_function(rvs2, alpha=0.05, no_test=100) | |
| sidak_correction_function(rvs1, alpha=0.05, no_test=100) |
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
| def sidak_correction_function(rvs, alpha, no_test): | |
| FWER = 1-(1-alpha)**(1/no_test) | |
| alpha_sidak = 1-(1-FWER)**(1/no_test) | |
| counter = 0 | |
| for i in range(no_test): | |
| rvs_random = stats.norm.rvs(loc=5, scale=10, size=1000, random_state=i+1) | |
| statistic, pvalue = stats.ttest_ind(rvs, rvs_random, equal_var=False) |
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
| def bonferroni_holm_correction_function(rvs, alpha, no_test): | |
| pvalue_test = [] | |
| for i in range(no_test): | |
| rvs_random = stats.norm.rvs(loc=5, scale=10, size=1000, random_state=i+1) | |
| statistic, pvalue = stats.ttest_ind(rvs, rvs_random, equal_var=False) | |
| pvalue_test.append(pvalue) | |
| pvalue_test_sorted = sorted(pvalue_test, key=float) | |
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
| def bonferroni_correction_function(rvs, alpha, no_test): | |
| alpha_bonferroni = alpha/no_test | |
| counter = 0 | |
| for i in range(no_test): | |
| rvs_random = stats.norm.rvs(loc=5, scale=10, size=1000, random_state=i+1) | |
| statistic, pvalue = stats.ttest_ind(rvs, rvs_random, equal_var=False) | |
| if pvalue <= alpha_bonferroni: |
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
| def t_test_function(rvs, alpha, no_test): | |
| counter = 0 | |
| for i in range(no_test): | |
| rvs_random = stats.norm.rvs(loc=5, scale=10, size=1000, random_state=i+1) | |
| statistic, pvalue = stats.ttest_ind(rvs, rvs_random, equal_var=False) | |
| if pvalue <= alpha: | |
| counter = counter + 1 |
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
| rvs1 = stats.norm.rvs(loc=5, scale=10, size=1000, random_state=0) | |
| rvs2 = stats.norm.rvs(loc=6.5, scale=8, size=1000, random_state=0) |
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 matplotlib.pyplot as plt | |
| from scipy import stats |