[TIL] #1.2.2 Hypothesis Test 2

Bella·2021년 3월 15일
0

TIL

목록 보기
6/11

t-test

t-test 조건

  1. 독립성 : 두 그룹이 연결되어 있는 쌍인지

  2. 등분산성 : 두 그룹이 어느정도 유사한 수준의 분산 값을 가지는지

  3. 정규성 : 데이터가 정규성을 나타내는지

비모수적 방법(nonparametic method)

모집단 분포에 대한 가정 없이 접근하는 통계적 방법

장점

  • 최소한의 가정만을 사용하므로, 모수적 가정이 잘못되어 생기는 오류의 가능성이 적다.
  • 범주형 자료와 같은 순위척도 데이터에 적용할 수 있다.
  • 적합도 검정과 같이 모수적 가정에 대한 검정 방법을 제공한다.
  • 순위(rank)나 부호(sign)에 기초한 방법 위주이기 때문에, 이상치(outlier)의 영향을 덜 받는다.


x2x^2 테스트

관찰된 빈도가 기대되는 빈도와 의미있게 다른지 여부를 검정하기 위해 사용되는 검정방법

예측값 계산

expectedi,j=(rowitotal)(columnjtotal)(total observations)expected_{i,j} = \cfrac{(row_{i} \text{total})(column_{j} \text{total}) }{(\text{total observations})}

x2x^2 통계치 계산

x2=(observediexpectedi)2expectedix^2 = \cfrac{\sum(observed_i - expected_i)^2}{expected_i}

one sample chi-squre test

Numpy

from numpy as np
obs = np.array([56, 783, 1624, 1454])

total_obs = sum(obs)

exp = total_obs / 4

squared = np.power(obs - exp, 2)

x2 = np.sum(squared / exp)

Scipy

from scipy import chisqure

obs1 = np.array([18, 22, 20, 15, 23, 22])
chi1 = chisqure(obs1)

obs2 = np.array([5, 23, 26, 19, 24, 23])
chi2 = chisqure(obs2)

print(chi1, chi2)
Power_divergenceResult(statistic=2.3000000000000003, pvalue=0.8062668698851285)
Power_divergenceResult(statistic=14.8, pvalue=0.011251979028327346)

p-value를 보면 obs1는 연관이 있고 obs2는 연관이 없다고 볼 수 있다.

two sample chi-squre test

Numpy

obs = np.array([9, 2], [13, 3])

total_obs = np.sum(obs) #obs 값의 합 저장

exp = np.array([[(9+2)*(9+13), (9+2)*(2+3)], [(13+3)*(9+13), (13+3)*(2+3)]])

exp = exp / total_obs

Scipy

from scipy.stats import chi2_contingency

x2 =  chi2_contingency(df)

결과 해석

  1. x2x^2 statistic
  2. p-value
  3. degree of freedom
  4. expected value for Observed
profile
Here Today, Gone Tomorrow

0개의 댓글