# Hypothesis Test Old

## Student t

* $$
  \eqalign{ & Let;T = {Z \over {\sqrt {V/n} }} \cr & with;Z \sim N(0,1) \cr & V \sim x^2 (n) \cr}
  $$
* n: Degree of Freedom, t 분포의 모양 결정
  * Z와 V는 independent
  * x^2: 카이 제곱 분포

Then

$$
T \sim t\_n
$$

* Properties
* symmetric distribution

  $$
  i.e.; - T \sim t\_n
  $$
* n=1 → Cauchy distribution(평균 존재x)의 일반화
* n≥2 → 평균이 0

  $$
  \eqalign{ & E(T) = E(Z)E({1 \over {\sqrt {V/n} }}) = 0 \cr & E(Z);and;E({1 \over {\sqrt {V/n} }});are;independent \cr & if;n = 1,;E({1 \over {\sqrt {V/n} }});doesn't;exist \cr}
  $$

  1. Heavier-tailed than Normal Distribution: 극단적인 값이 발생할 확률이 높아짐
  2. For n large, t\_n looks very much like N(0,1)

     \= Distribution of t\_n goes to N(0,1) as n →∞

     증명)

     $$
     \eqalign{ & Let;T\_n = {Z \over {\sqrt {V\_n /n} }},;with;Z\_1 ,;Z\_2 ,;... \cr & V\_n = Z\_1 ^2 + Z\_2 ^2 + ... + Z\_n ^2 \cr & Then;{{V\_n } \over n} \to 1;by;LLN;Since;E(Z\_2 ) = 1 \cr & So;T\_n \to Z \cr & So;t\_n ;converges;to;N(0,1);distribution \cr}
     $$

## Binomial Distribution

* 베르누이 시행: 성공/실패로만 나타나는 시행, 각 시행은 독립
* 성공할 확률 p, 실패할 확률 q=1-p → 베르누이 시행을 n번 했을 때의 확률 분포
* 확률질량함수

$$
\eqalign{ & f(x) = \_n C\_x p^x q^{n - x} \cr & where;x = 0,;1,;2,;... \cr & q = 1 - p \cr}
$$

## T-test

* 모집단의 분산을 모를 때 독립된 두 집단의 평균간의 차이를 비교(= 얼마부터 유의한가?)

  ex) 2010년 남자 평균 키 vs 2020년 남자 평균 키 175

  ​ 신약을 먹기 전 간 수치 vs 먹은 후의 간 수치
* Null Hypothesis: 차이가 없다는 가설(= 두 집단의 평균이 같다)

  Alternative Hypothesis: 차이가 있다는 가설(= 두 집단의 평균이 다르다)
* 가정: 독립성, 정규성, 등분산성(H0을 받아들여야 함)
* 단일표본: 모집단 vs 표본집단

  $$
  \eqalign{ & t = {{(\overline X - \mu )} \over {{\sigma \over {\sqrt n }}}} \sim t(n - 1) \cr & where;\overline X = sample;mean \cr & \mu = population;mean \cr & t(n - 1) = t;distribution;with;n - 1;dof \cr}
  $$

  → α 값과 t 값을 비교, 혹은 p 값과 값을 비교
* 표본 2개

  $$
  \eqalign{ & t = {{(\overline {X\_1 } - \overline {X\_2 } ) - (\mu *1 - \mu *2 )} \over {SE*{(\overline {X\_1 } - \overline {X\_2 } )} }} \cr & where;SE*{(\overline {X\_1 } - \overline {X\_2 } )} = s\_p ^2 ({1 \over {n\_1 }} + {1 \over {n\_2 }}):standard;error \cr & s\_p ^2 = {{(n\_1 - 1)s\_1 ^2 + (n\_2 - 1)s\_2 ^2 } \over {(n\_1 - 1) + (n\_2 - 1)}}:; 통합;분산\cr}
  $$

## Multiple Testing

* 여러 개의 표본집단끼리 비교할 때 단순히 Hypothesis test를 여러 번 해서는 안된다: Hypothesis test를 많이 할수록 type 1 error가 적어도 1번 나올 확률이 올라가기 때문
  * n번 test했을 때 error가 한번도 안 나올 확률 P(0):

    $$
    \eqalign{ & P(0) = \alpha ^0 (1 - \alpha )^n \cr & if;n;increases \to P(0);decreases \cr}
    $$

    따라서 Multiple testing을 할 때는 통계적 수정 절차가 필요함
* Bonferroni Correction: 간단하지만 시행 수가 많아질수록 부정확해짐

  $$
  Reject;H\_0 ;if;p\_i \le {\alpha \over n}
  $$

  즉 n번 시행할 때 유의확률은 α/n
* Dunnet test: 정확도가 높고 수정된 t-distribution을 사용함. 대조군이 1개일 때 유용함

  ex) 대조군 A, 실험군 B, C, D일 때

  ​ A-B, A-C, A-D 비교 ok

  ​ A-B, B-C, C-D 비교 no

$$
\eqalign{ & t = {{\overline {Y\_i } - \overline {Y\_o } } \over {\sqrt {MS\_W ({1 \over {N\_i }} - {1 \over {N\_o }})} }} \cr & where;\overline {Y\_{^i } } ,;\overline {Y\_o } = Sample;mean;of;each;groups \cr & MS\_W = Mean;square;within = {{SS\_{within} } \over {dof\_{within} }} \cr & SS\_{within} = Sum;of;squares;within;groups:(n - 1)\sigma ^2 \cr & dof\_{within} = Total;dof:Sample;number - Group;number \cr}
$$

## ANOVA(Analysis of Variance)

\[[https://www.youtube.com/watch?v=HlSyvMRLu4w\&ab\_channel=SapientiaaDei](https://www.youtube.com/watch?v=HlSyvMRLu4w\&amp;ab_channel=SapientiaaDei)]:

* T-test는 두 그룹의 평균이 같은지 비교했다면, ANOVA는 여러 그룹의 평균을 비교함
  * Multiple testing은 type 1 error가 발생할 확률이 높아지기 때문에 ANOVA를 사용하는 것
* ANOVA를 하기 전에 알아야 하는 변수들
  * 독립변수: 인과관계에서 원인인 변수
  * 종속변수: 인과관계에서 결과인 변수
  * 통제변수: 기본적으로는 독립변수이나 연구의 관심사가 아닌 변수

    ex) 고객만족도(독립), 다른 원인1(통제), 다른 원인2(통제), .... → 재방문율(종속)
  * 통제변수를 하나도 고려하지 않으면 model misspecification 이 발생함(모델이 잘못되었다는 의미)
* One-way ANOVA: 독립변수가 1개인 ANOVA
  * One-way ANOVA에 사용되는 변수의 특성
    * 종속변수: Continuous 해야함
    * 독립변수: Discrete/Categorical 해야함

      ex) 어린 아이들의 폭력성 실험

      ​ 영상의 종류(독립 변수) - 폭력영화/드라마/공익광고

      ​ → 점수화된 아이들의 폭력적인 행동(종속 변수)

      * ANOVA에서 독립변수는 반드시 1개임(영상의 종류) 절대 3개(폭력영화, 드라마, 공익광고)가 아님!
  * Formula

    $$
    \eqalign{ & Y\_{ij} = \mu + \tau *j + e*{ij} \cr & where;i = 그룹;내의;ID \cr & j = Group(1,;2,;3,;...) \cr & \tau = 독립변수 \cr & e = error(\tau \_j 에;의해;설명되지;않는;오차=random;error) \cr}
    $$

    * 이런 식에서 보통은 우변은 독립변수 좌변은 종속변수
* F-values \~ F-distribution: F-value는 F-distribution을 따른다
  * 다른 test들처럼 F-value를 구해서 F-distribution에서 α값과 비교하면 됨
  * F-value: 두 개의 분산의 비율을 나타냄
  * Between Variance: GM(전체 평균)과 각 그룹간의 분산을 다 합친 값
    * BV가 크면 적어도 한 그룹이 다른 그룹의 평균에서 멀리 떨어져 있음(ANOVA의 목적: 여러 그룹의 평균이 같은가?)
  * Within Variance: 그룹 내의 분산

    → BV가 WV보다 충분히 커야 "BV가 크다"라고 말할 수 있다(WV는 랜덤한 변동값을 의미)
  * F-value

    $$
    \eqalign{ & F - value = {{BV} \over {WV}} = {{MS\_{treatment} } \over {MS\_{error} }} = {{MS\_{between} } \over {MS\_{within} }} \cr & where;MS = Mean;Squared \cr}
    $$
* Hypothesis

  $$
  \eqalign{ & H\_0 :\mu \_0 = \mu \_1 = ... = \mu \_k \cr & H\_1 :\mu *i \ne \mu *k :적어도;한;그룹의;평균은;다르다 \cr & variance:{{\sum {(x - \overline x )^2 } } \over {df}} \cr} \eqalign{ & df*{BV} :group;number \cr & df*{WV} :n - k \cr & where;n:sample;number;of;each;group \cr & k:group;number \cr}
  $$
* Two-way ANOVA: 독립 변수 두개
  * Main effect: 독립변수가 가지는 효과 + interaction effect
  * 독립변수와 종속변수가 linear(직선)이라고 가정
  * f-value
    * 첫 번째 독립변수 main effect를 측정하기 위한 f-value
    * 두 번째 독립변수 main effect를 측정하기 위한 f-value
    * interaction 효과를 측정하기 위한 f-value

      → 3개의 BV와 1개의 WV를 비교
  * Hypothesis는 3개 필요
    * 첫 번째 main effect에 대한 가설

      $$
      H\_{01} :\mu \_{11} = \mu \_{12} = ... = \mu \_{1k}
      $$
  * 두 번째 main effect에 대한 가설

    $$
    H\_{a1} :\mu \_{1i} \ne \mu \_{1k}
    $$

    * interaction effect에 대한 가설

      $$
      \eqalign{ & H\_{03} = interaction;effect;doesn't;exist; \cr & H\_{a3} = interaction;effect;exists \cr}
      $$


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ykkim.gitbook.io/wiki/machine-learning/probability-and-statistics-for-machine-learning/hypothesis-test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
