Chi Square Test : Goodness of fit test

2022. 4. 25. 22:56·.../Math
728x90
728x90

하나의 categorical variable이 주어진 경우로, null hypothesis가 참인 경우에 관측치로 부터 구한 chi square값이 나올 확률을 구해 검증.

Goodness-of-fit test: A test for comparing observed frequencies with theoretically predicted frequencies.

Example 1

100명의 참가자들에게 매우 모호한 신문 사설을 읽게 하고, 해당 사설이 특정 사안에 찬성하는 논조인지 반대하는 논조인지를 분류하도록 함.

  • 찬성 아니면
  • 반대 만 선택 가능함.

관측된 결과는 다음과 같음.

Table
In Favor Opposed
58 42

해당 관측치로부터 유의미(significantly)하게 보다 많은 참가자들이 찬성을 택한 것인지, 아니면 원래 찬성과 반대가 같은데(=이상적으로 50명의 찬성이 나와야하는데) 우연히 58명의 찬성자가 나온 것인지를 확인하기 위해 Goodness-of-fit test를 함.

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

editorial_view_seen_As = ['In Favor','Opposes']

data = [58,42]

df = pd.DataFrame(
    data = data,
    index=editorial_view_seen_As,
    columns=['observed']
)

chi2, p_value = stats.chisquare(f_obs=df['observed'])

print(f'chi2(p_value)={np.round(chi2,4)}({np.round(p_value,4)})')

결과는 $\chi^2(p_\text{value})=2.56(0.1096)$로, 50:50인 경우가 참일 때 이같은 $\chi^2=2.56$이 나올 확률은 10.96%라는 의미임.

10.96%는 일반적으로 사용되는 $\alpha=0.05$나 보다 엄격한 $\alpha=0.01$보다 작지 않으므로 null hypothesis를 기각하기 어렵기 때문에 유의미하게 찬성이 많다고 볼 수 없다는 결론으로 이어진다.

  • null hypothesis가 채택됨.
  • 참고로 DoF(자유도, Degree of Freedom)은 1임. (# of categoroies -1)

Example 2

가위,바위,보 게임에서 관측치가 다음과 같음.

Rock Paper Scissors
30 21 24

가위, 바위, 보가 균일하게 나와었야 하는데 이같은 관측치가 우연히 나온 확률을 chi square test로 구하여 확인.

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

classes = ['rock','paper', 'scissors']

data = [30,21, 24]

df = pd.DataFrame(
    data = data,
    index=classes,
    columns=['observed']
)

chi2, p_value = stats.chisquare(f_obs=df['observed'])

print(f'chi2(p_value)={np.round(chi2,4)}({np.round(p_value,4)})')

결과는 $\chi^2(p_\text{value})=1.68(0.4317)$로, 25:25:25인 경우가 참일 때 이같은 $\chi^2=1.68$이 나올 확률은 43.17%라는 의미임.

43.17%는 일반적으로 사용되는 $\alpha=0.05$나 보다 엄격한 $\alpha=0.01$보다 작지 않으므로 null hypothesis를 기각하기 어렵기 때문에 균일한 분포를 따른다고 볼 수 있다.

  • null hypothesis를 채택.
  • DoF = 2

References

Fundamental Statistics for the Behavioral Sciences 8th Edition, Ch19

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

One sample t-test : The Moon Illusion  (0) 2022.04.27
Chi Square : Independence Test (Analysis of Contingency Table)  (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] Definition of Vector Space and Sub-Space  (0) 2022.04.05
'.../Math' 카테고리의 다른 글
  • One sample t-test : The Moon Illusion
  • Chi Square : Independence Test (Analysis of Contingency Table)
  • Chi Square for Large Contingency Table
  • [Math] The Law of Large Numbers (or The weak law of large numbers)
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
    • 기타 방사능관련.
  • 인기 글

  • 태그

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

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
dsaint31x
Chi Square Test : Goodness of fit test
상단으로

티스토리툴바