Chi Square : Independence Test (Analysis of Contingency Table)

2022. 4. 25. 23:42·.../Math
728x90
728x90

2개의 categorical variable이 독립인지를 chi square test로 확인.
독립이라는 null hypothesis가 참일 경우의 관측치에 해당하는 chi square 가 나올 확률을 구해 검정.


Walsh et al.(2006)이 수행한 실험은 다음과 같음.

  • anorexia(거식증)의 경우, 치료를 받아서 정상체중으로 돌아왔더라도 1년 안에 재발하여 다시 병원으로 오는 경우가 많음.
  • 이에 대한 유력한 원인으로 depression(우울증)이 지목됨.


Walsh et al.이 수행한 실험은 거식증이 완치가 된 93명의 환자들을 대상으로

  • 49명에게는 항우울증 약인 Prozac을 1년간 처방하여 복용시키고,
  • 다른 44명에게는 Placebo(가짜약)을 같은 기간동안 복용시킴.

해당 실험은 double-blind로 수행됨.
이 실험의 독립변수는 각 그룹(Prozac and Placebo)에서 1년 이후까지 정상체중이 유지된(=거식증이 재발하지 않은) 환자의 수임.


Contingency Table은 다음과 같음.

Treatment Success Relapse (재발)
Prozac 13 36
Placebo 14 30

 

import numpy as np
import scipy.stats as stats
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import Math, HTML

def report(chi2, p_value, dof, expected, idx=None, col=None):
  display(r'$\chi^2$ :'+ str(chi2))
  print('p-value :', p_value)
  print('dof :', dof)
  display(pd.DataFrame(data=expected, index=idx, columns=col))

outcome = ['success','relapse']
treatment = ['prozac','placebo']

data = np.array([
                 [13,36],
                 [14,30],
])
df = pd.DataFrame(
    data = data,
    index = treatment,
    columns = outcome
)

display(df)

# To reproduce the result on Howell's book,
# correction= False is used. 
report(*stats.chi2_contingency(df,correction=False),treatment,outcome)


결과는 $p$-value가 0.5748로 Prozac 처방여부와 거식증 재발이 독립이라는 null hypothesis을 reject하기 어렵다는 결론으로 이어진다.

  • 나온 testing statistics는 $\chi^2=0.3146$이고 $\text{dof}=1$임.
  • null hypothesis가 참이라는 가정하에 위와 같은 빈도의 contingency table을 얻을 확률이 57.48% 라는 애기임.

여기서는 Howell 교수님의 책의 결과와 같이 나오도록 Yates' correction for continuity를 사용하지 않음.
Scipy의 stats.chi2_contingency()는 기본적으로 dof=1 인 경우, Yates' correction을 수행하기 때문에, correction=False를 추가해줌.

Contingency table:

A two-dimensional table in which each observation is classified on the basis of two variables simultaneously.

Reference

Fundamental Statistics for the Behavioral Sciences 8th Edition, Ch19.2

'... > Math' 카테고리의 다른 글

Normal Equation : Vector derivative 를 이용한 유도  (0) 2022.04.28
One sample t-test : The Moon Illusion  (0) 2022.04.27
Chi Square Test : Goodness of fit test  (0) 2022.04.25
Chi Square for Large Contingency Table  (0) 2022.04.25
[Math] The Law of Large Numbers (or The weak law of large numbers)  (0) 2022.04.21
'.../Math' 카테고리의 다른 글
  • Normal Equation : Vector derivative 를 이용한 유도
  • One sample t-test : The Moon Illusion
  • Chi Square Test : Goodness of fit test
  • Chi Square for Large Contingency Table
dsaint31x
dsaint31x
    반응형
    250x250
  • dsaint31x
    Dsaint31's blog
    dsaint31x
  • 전체
    오늘
    어제
    • 분류 전체보기 (739)
      • Private Life (13)
      • Programming (56)
        • DIP (104)
        • ML (26)
      • Computer (119)
        • CE (53)
        • ETC (33)
        • CUDA (3)
        • Blog, Markdown, Latex (4)
        • Linux (9)
      • ... (350)
        • Signals and Systems (103)
        • Math (171)
        • Linear Algebra (33)
        • Physics (42)
        • 인성세미나 (1)
      • 정리필요. (54)
        • 의료기기의 이해 (6)
        • PET, MRI and so on. (1)
        • PET Study 2009 (1)
        • 방사선 장해방호 (4)
        • 방사선 생물학 (3)
        • 방사선 계측 (9)
        • 기타 방사능관련 (3)
        • 고시 (9)
        • 정리 (18)
      • RI (0)
      • 원자력,방사능 관련법 (2)
  • 블로그 메뉴

    • Math
    • Programming
    • SS
    • DIP
  • 링크

    • Convex Optimization For All
  • 공지사항

    • Test
    • PET Study 2009
    • 기타 방사능관련.
  • 인기 글

  • 태그

    opencv
    signal_and_system
    random
    Probability
    linear algebra
    math
    function
    signals_and_systems
    Term
    Vector
    인허가제도
    SIGNAL
    Python
    fourier transform
    검사
    Optimization
    Programming
    numpy
    SS
    Convolution
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
dsaint31x
Chi Square : Independence Test (Analysis of Contingency Table)
상단으로

티스토리툴바