import numpy as np
import statsmodels.api as sm
np.random.seed(0)
print("=="*20)
# sample1은 고정하고,
sample1 = np.random.normal(0, 1, 100)
for m in [0.1*i for i in range(0, 5)]:
# sample2의 평균을 증가하면서, p_value의 변화를 예측함.
print(f"mean: {m:.2f}")
sample2 = np.random.normal(m, 1, 100)
t_p_d= sm.stats.ttest_ind(
x1=sample1,
x2=sample2,
alternative='two-sided',
usevar='pooled' # same variance
)
tstat, p_value, degree_of_freedom = t_p_d
print(f"tstat : {tstat:.6f}")
print(f"p_value : {p_value:.6f}")
print(f"degree_of_freedom: {degree_of_freedom}")
print("--"*20)
print("=="*20)
========================================
mean: 0.00
tstat : -0.152958
p_value : 0.878587
degree_of_freedom: 198.0
----------------------------------------
mean: 0.10
tstat : 0.136647
p_value : 0.891449
degree_of_freedom: 198.0
----------------------------------------
mean: 0.20
tstat : 0.410815
p_value : 0.681653
degree_of_freedom: 198.0
----------------------------------------
mean: 0.30
tstat : -1.566059
p_value : 0.118932
degree_of_freedom: 198.0
----------------------------------------
mean: 0.40
tstat : -0.953851
p_value : 0.341322
degree_of_freedom: 198.0
----------------------------------------
========================================
댓글남기기