Home t-test 정리
Post
Cancel

t-test 정리

  • 한개의 집단을 대상으로 전/후를 비교할때 Paired T-Test
  • 두개의 독립된 집단을 대상으로 비교할때 Unpaired T-Test

Paired T-Test

1
2
3
4
5
6
7
8
9
10
11
12
13
import numpy as np
from scipy import status

np.random.seed(1) # 항상 consistent 결과를 얻기 위해서

# before treatment: mean 60, std 5
before_weights = [int(60 + np.random.normal(0, 5)) for _ in range(20)]
# after treatment: mean 0,99-fold decrease, std 0.02
after_weights = [float(w * np.rnadom.normal(0.99, 0.02)) for w in before_weights]

# t-test
ttest_result = stats.ttest_rel(before_weights, after_weights)
print('the t-statistic and p-value assuming equal varainces is %.4f and %.3f' % ttest_result)

Unpaired T-Test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import numpy as np
from scipy import status

np.random.seed(1) # 항상 consistent 결과를 얻기 위해서
# mean 170, std: 5
group1_heights = [int(170 + np.random.normal(0,5)) for _ in range(20)]
# mean 175, std: 10
group2_heights = [int(175 + np.random.normal(0,10)) for _ in range(20)]

# assuming equal varainces
ttest_result = stats.ttest_ind(group1_heights, group2_heights)

# assuming not equal varinaces
ttest_result_diff_var = stats.ttest_ind(group1_heights, group2_heights, equal_var=False)

print('the t-statistic and p-value assuming equal varainces is %.4f and %.3f' % ttest_result)
print('the t-statistic and p-value assuming not equal varainces is %.4f and %.3f' % ttest_result_diff_var)
This post is licensed under CC BY 4.0 by the author.

Spark 테이블을 Hive 테이블로 생성

Snippets in Visual Studio Code