> For the complete documentation index, see [llms.txt](https://ykkim.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ykkim.gitbook.io/wiki/machine-learning/probability-and-statistics-for-machine-learning/null-hypothesis-significance-testing.md).

# Null Hypothesis Significance Testing

**Review: setting up and running a significance test**

Notes.

1. significance level을 사용하지 않고 rejection 영역을 사용해도 됨.
2. null hypothesis는 'cautious hypothesis'가 될 수도 있음. significance level이 낮을수록 가설을 reject하기 위해 더 많은 evidence가 필요하기 때문.
3. key point of confusion:

   significance level = 0.05의 의미가 test에서 실수가 일어날 확률이 5%라는 의미 X

   H0이 참일 때 H0을 reject할 확률이라는 의미 O

   !! power of the test = HA가 참일 때 H0를 reject할 확률

   -> HA가 참일 때 H0을 reject하지 못할 확률 = 1 - power

Errors ![](/files/T0InbxBQ0Z9XN4OYspYS)

#### T-test

* 많은 significance test는 데이터가 정규 분포에서 추출되었다고 가정하기 때문에 정규성 가정이 합리적인지 확인해야 함
* z-test와 마찬가지로 one sample과 two sample t-test는 정규성을 가정함

**Z-test**

Review

![](/files/xC8IYncLzJmzJl5MYtEJ)

Example)

데이터가

$$
data \sim N(\mu ,4^2 )
$$

를 따를 때

$$
\eqalign{ & H\_0 :\mu = 0 \cr & H\_A :\mu > 0 \cr}
$$

으로 가정함. 우리가 수집한 데이터가 1, 2, 3, 6, -1이라고 가정한다면 significance level이 0.05일때 H0를 reject해야 하는가?

Answer)

$$
\eqalign{ & \overline x = 2.2 \cr & z = {{\overline x - \mu \_0 } \over {\sigma /\sqrt n }} = {{2.2 - 0} \over {2/\sqrt 5 }} = 2.460 \cr & p = P(Z > z) = P(Z > 2.460) = 0.007 \cr}
$$

p<0.05이기 때문에 H0를 reject해야한다

![](/files/q9IVKPrYa6ggRMqi2UlX)

**The Student t distribution**

* 위키피디아 참고
* normal distribution처럼 대칭적이고 종 모양임
* 파라미터 df(degrees of freedom)에 따라 모양이 변함(df가 작을수록 꼬리가 두껍고 df가 클수록 ND에 가까워짐)
* t-distribution의 모양을 볼 수 있는 곳:<http://mathlets.org/mathlets/t-distribution/>

**One sample t-test**

* z-test는 분산을 안다고 가정하지만 실제로는 알 수 없는 경우가 많기 때문에 데이터에서 추정해야 함
  * 이런 경우에 one sample t-test를 사용함

![](/files/yobIhqgN7wpig2N4y7cq)

![](/files/vasgtXiH6jLQbEsHMd91)

example)

이전 예제에서 variance를 모른다고 가정함. 우리가 수집한 데이터는 1, 2, 3, 6, -1이고

$$
\eqalign{ & H\_0 :\mu = 0 \cr & H\_A :\mu > 0 \cr}
$$

이라고 가정함. significance level이 0.05일 때 H0을 reject해야 하는가?

![](/files/nqy8bLQDh6Nz8JayA0hR)

**Two-sample t-test with equal variance**

* Data: Normal distribution을 따르는 두 가지 데이터셋

  $$
  \eqalign{ & x\_1 ,x\_2 ,...,x\_n \sim N(\mu \_1 ,\sigma ^2 ) \cr & y\_1 ,y\_2 ,...,y\_m \sim N(\mu \_2 ,\sigma ^2 ) \cr}
  $$

  mean과 variance 둘 다 모르는 값이지만 같다고 추정
* Null Hypothesis:

  $$
  \mu \_1 = \mu \_2
  $$
* Test statistic:

  $$
  \eqalign{ & t = {{\overline x - \overline y } \over {s\_p }} \cr & s\_p ^2 = {{(n - 1)s\_x ^2 + (m - 1)s\_y ^2 } \over {n + m - 2}}\left( {{1 \over n} + {1 \over m}} \right) \cr & where,s\_p ^2 ,is,the,pooled,variance \cr}
  $$
* Null distribution:

  $$
  f\left( {t|H\_0 } \right),is,the,pdf,of,T\sim t\left( {n + m - 2} \right).
  $$
* $$
  \eqalign{ & One - sided,p - value,\left( {right,side} \right):,,p = P\left( {T > t|H\_0 } \right) \cr & One - sided,p - value,\left( {left,side} \right):,,p = P\left( {T < t|H\_0 } \right) \cr & Two - sided,p - value:,,p = P\left( {|T| > |t|} \right) \cr}
  $$

Note

1. pooled variance를 다음과 같이 정의하는 저자도 있음

   <img src="/files/GucII7WKJLxF0E3xjgbu" alt="" data-size="original">

   이 수업에선 그것을 estimated variance of x-y라고 부름

   <img src="/files/JjilWQQIfaXJiFi80BGW" alt="" data-size="original">
2. 그룹간의 분산이 다른 two-sample test도 있음. 조금 더 복잡함

Example

산부인과에 온 여성 1408명의 임신 기간

* 검진 목적:

  $$
  775,observation,with,\overline x \_M = 39.08,and,s\_M ^2 = 7.77
  $$
* 응급:

  $$
  633,observation,with,\overline x \_E = 39.6,and,s\_E ^2 = 4.95
  $$

두 그룹의 평균이 다른지 two-sample t-test를 통해 조사하라

![](/files/yU5Qcsisqzyr0qirVZVw)

t, z test 등등 테이블로 정리(언제 어떤 거 사용해야하는지)

one sample vs two
