<t-test> : (통계적 차이 검정)
– 분석 결과의 타당성을 증명하기 위해 통계적으로 차이를 검정하는 과정으로 두 집단간 차이에 대한 검정 방법이다.
– 모집단의 평균 등과 같이 실제 정보를 모를 때 현재의 데이터만으로 두 집단의 차이에 대해 검정할 수 있는 방법
– 검정 대상인 두 집단의 데이터 개수가 비슷하면서 두 데이터가 정규 분포를 보이는 경우에 신뢰도가 높은 검정 방법
1. t-test 귀무가설
‘두집단의 평균이 같다.’
2. africa와 eu간의 맥주 소비량의 차이 검정
africa, eu의 맥주 소비량의 평균을 통해 두 집단의 차이를 검정한다.
[data : africa]
country beer_servings spirit_servings wine_servings total_litres_of_pure_alcohol continent 2 Algeria 25 0 14 0.7 AF 4 Angola 217 57 45 5.9 AF 18 Benin 34 4 13 1.1 AF 22 Botswana 173 35 35 5.4 AF 26 Burkina Faso 25 7 7 4.3 AF 27 Burundi 88 0 0 6.3 AF 28 Cote d'Ivoire 37 1 7 4.0 AF 29 Cabo Verde 144 56 16 4.0 AF 31 Cameroon 147 1 4 5.8 AF 33 Central African Republic 17 2 1 1.8 AF 34 Chad 15 1 1 0.4 AF 38 Comoros 1 3 1 0.1 AF 39 Congo 76 1 9 1.7 AF ......
[data : eu]
country beer_servings spirit_servings wine_servings total_litres_of_pure_alcohol continent 1 Albania 89 132 54 4.9 EU 3 Andorra 245 138 312 12.4 EU 7 Armenia 21 179 11 3.8 EU 9 Austria 279 75 191 9.7 EU 10 Azerbaijan 21 46 5 1.3 EU 15 Belarus 142 373 42 14.4 EU 16 Belgium 295 84 212 10.5 EU 21 Bosnia-Herzegovina 76 173 8 4.6 EU 25 Bulgaria 231 252 94 10.3 EU 42 Croatia 230 87 254 10.2 EU 44 Cyprus 192 154 113 8.2 EU .....
code : t-test
def t_test(self): africa = self.drinks.loc[self.drinks['continent'] == 'AF'] europe = self.drinks.loc[self.drinks['continent'] == 'EU'] tTestResult = stats.ttest_ind(africa['beer_servings'], europe['beer_servings']) tTestResultDiffVar = stats.ttest_ind(africa['beer_servings'], europe['beer_servings'], equal_var=False) print("The t-statistic and p-value assuming equal variances is %.3f and %.3f." % tTestResult) print("The t-statistic and p-value not assuming equal cariances is %.3f and %.3f." % tTestResultDiffVar)
결과 :
The t-statistic and p-value assuming equal variances is -7.268 and 0.000.
The t-statistic and p-value not assuming equal cariances is -7.144 and 0.000
0개의 댓글