๐ฝ ์ ๋ฒ ์๊ฐ์ parametric vs. non-parametric ์ฐจ์ด์ ๋ํด์ ๋ฐฐ์ ๋ค.
๐ฝ ์ด๋ฒ ํฌ์คํ ์๋ non-parametric test๋ฅผ ์ฒ์์ผ๋ก ๋ฐฐ์๋ณด๋ ค ํจ! ์นด์ด์ ๊ณฑ ๊ฒ์ ์ฒซ๋ฒ์งธ test - ์ ํฉ๋ ๊ฒ์ ์ ๋ํด์ ์์๋ณดZA! ๐คฉ
(๋ ๋ฆฝ์ฑ ๊ฒ์ ์ ๋ค์ ์๊ฐ์)
๐คฒ ๋ฒ์ฃผํ ๋ณ์๋ฅผ statistical test์ ํ์ฉํ๋ ๊ฒฝ์ฐ ์นด์ด์ ๊ณฑ๊ฒ์ ์ด ๋ง์ด ์ฌ์ฉ๋๋ค!
๐คฒ ์นด์ด์ ๊ณฑ์ ํฌ๊ฒ ๋ ๊ฐ์ง๋ก ๋๋๋ค.
โ ์ ํฉ๋ ๊ฒ์ - Goodness of Fit Test = 'ํ๋์ ๋ฒ์ฃผํ ๋ณ์์ ๋ํด ๊ฐ ๋ฒ์ฃผ๋ณ ํ๋ฅ ์ ๊ดํ ๊ฒ์ '
<One-Sample>
→ compare multiple observed proportions to expected probabilities
→ ์) ์ด๋ ์ง์ญ์ ์ฃผ๊ฑฐ ํํ๊ฐ ์ํํธ, ์คํผ์คํ , ์ฃผํ ์ด๋ ๊ฒ ์ธ ์ข ๋ฅ๊ฐ ์๋ค๊ณ ํ๋ค๋ฉด ๊ฐ๊ฐ ์ด๋ ์ ๋์ ๋น์ค์ ์ฐจ์งํ๋ ๊ฐ? ๊ฐ์ค๋ก ๊ฐ๊ฐ์ ๋น์ค์ ์ธ์ฐ๊ณ ์ ํฉํ ์ง, ๋ฒ์ฃผ๋ณ ์๋์ ๋น๋๋ฅผ ์ด์ฉํด ์ธ์ด ๊ฒ์ด ์ ์ ํ ์ง?
โก ๋ ๋ฆฝ์ฑ ๊ฒ์ - Test of Independence = '์๋ก ๋ค๋ฅธ ๋ ๋ฒ์ฃผํ ๋ณ์ ๊ฐ์ ์ฐ๊ด์ฑ์ด ์๋ ์ง' (์ ํฉ๋๋ณด๋ค ๋ ๋ง์ด ์ฐ์!)
(๋ค์ ํฌ์คํ )
<Two-Samples (Independent)>
→ evaluate the association btw two categorical variables
→ ์) ๋ฒ์ฃผํ ๋ณ์๊ฐ 2๊ฐ ์ฃผ์ด์ง๊ณ ์๋ก ๊ฐ์ ์ฐ๊ด์ฑ์ ๋ฐ์ง๋ค - ์๋ก ์ํ๊ณผ๋ชฉ์ ํ์ ๊ณผ ํต๊ณ๊ณผ๋ชฉ์ ํ์ ์ด ์๋ก ์ฐ๊ด์ฑ์ด ์๋ ์ง ๊ฒ์
* ๐2 distribution
๐ถ ๋จผ์ ์นด์ด์ ๊ณฑ๋ถํฌ๋ฅผ ์์๋ณด์
โ ํ์ค์ ๊ท๋ถํฌ(Z1, Z2, Z3, ... Zk)๋ฅผ ๋ฐ๋ฅด๋ ์ฌ๋ฌ ๊ฐ์ k๊ฐ์ Z๊ฐ ์์ ๋, ๊ฐ ๋ถํฌ๋ ์๋ก ๋ ๋ฆฝ์ด๊ณ ๋๋คํ๊ฒ ๊ฐ ๋ถํฌ๋ณ๋ก ํ๋์ฉ ์์์ Z๋ฅผ ๋ฝ๊ณ ๊ฐ๊ฐ ์ ๊ณฑํด์ ์๋ก ๋ํ๋ค - ์ ๊ณฑํฉ
โก ๋ ๊ฐ ํ์ค์ ๊ท๋ถํฌ์์ ๋๋คํ๊ฒ ๋ค๋ฅด๊ฒ ๋ฝ์ ์ ๊ณฑํฉ์ ๋ ๊ตฌํ๋ค
โข ์ โก๋ฅผ ๋ฌด์ํ ๋ฐ๋ณตํด, ์ ๊ณฑํฉ๋ค์ ๋ถํฌ๋ฅผ '์นด์ด์ ๊ณฑ๋ถํฌ'๋ผ๊ณ ๋ถ๋ฅธ๋ค
๐ถ ์นด์ด์ ๊ณฑ๋ถํฌ์์ ํ์ํ ๋ชจ์๋ k (์์ ๋; ํ์ค์ ๊ท๋ถํฌ ๋ฐ๋ฅด๋ ๋ณ์๊ฐ ๋ช ๊ฐ๊ฐ ์ ๊ณฑํด์ ๋ํด์ก๋ ์ง์ ์์น)
โซ ์ฆ k๋ง ์๋ฉด x์ ๋ํ ๋ถํฌํจ์๋ก ์ ์ํ ์ ์๋ค.
๐ถ ๋์ฒด์ ์ผ๋ก ์นด์ด์ ๊ณฑ ๋ถํฌ๋ ์ค๋ฅธ๊ผฌ๋ฆฌ๊ฐ ๊ธด ํํ๋ฅผ ๊ฐ์ง
- ์นด์ด์ ๊ณฑ๋ถํฌ ์ & ๊ฐํ(์์ ๋ 3) -
๐ถ ํ๊ท ์ ์์ ๋ k, ๋ถ์ฐ์ 2k (์์ ๋๋ฅผ ๋ ๋ฐฐ ๊ณฑํจ)
๐ถ ์์ ๋๊ฐ ์ฆ๊ฐํ๋ฉด?
→ ์์ ๋๊ฐ ์ฆ๊ฐํ๋ค๋ ๊ฑด, ์ ๊ณฑํฉ์ ๊ตฌํ๋ ๋ฐ ์์ด์ ํ์ค์ ๊ท๋ถํฌ์ ์๋ฅผ ๋๋ฆฐ๋ค๋ ๊ฒ๊ณผ ๊ฐ์ ๋ง์ด๋ค. ์ด ๋ ํ๊ท & ๋ถ์ฐ ์์ ์ํด ์ค๋ฅธ์ชฝ์ผ๋ก ์ด๋ํ๋ฉด์ ๋ณ๋์ฑ์ด ๋ ๋์ด์ง๋ ๊ทธ๋ํ ๊ฐํ์ผ๋ก ๋ฐ๋๊ฒ ๋๋ค
๐ถ ์ฆ! ๋ค์ ์ ๋ฆฌํ๋ฉด, ์นด์ด์ ๊ณฑ๋ถํฌํ๋ฅ ๋ฐ๋ํจ์ ๊ฐํ์ ์ค๋ฅธ๊ผฌ๋ฆฌ๊ฐ ๊ธธ๊ฒ ๋์ด์ง ๋น๋์นญ ํํ์ด๋ฉฐ, ๋ถํฌ ์๊ฐ ๋์ด๋ ์๋ก ์ ์ ๋์นญ์ ๊ฐ๊น์ด ํํ๋ฅผ ๋ณด์ธ๋ค
๐ถ ๋ถ์์) α๋ผ๊ณ ํ ๋ ์ค๋ฅธ๊ผฌ๋ฆฌ ๊ฐํ์ด๋ฏ๋ก P[X>c] = α๋ฅผ ๋ง์กฑํ๋ X์ (1-α) ๋ถ์์ c๋ฅผ ๐2 α,k(์นด์ด์ ๊ณฑ ๊ฒ์ ํต๊ณ๋)๋ผ๊ณ ํ๊ธฐํ๋ค
(์นด์ด์ ๊ณฑ๋ถํฌ๋ ๋์นญ์ด ์๋๋ฏ๋ก 0์ ๊ธฐ์ค์ผ๋ก ๋ถํธ๊ฐ ๋ค๋ฅด๊ณ ๊ฐ์ ๊ฐ์ ๊ฐ์ง๋ ๊ฒฝ์ฐ๊ฐ ์๋ค. ๋ฐ๋ผ์ ํ๋ ์ํํธ์จ์ด๋ฅผ ํตํด ๋ฐ๋ก ์ฐพ์์ผ ํจ)
- ์์ ๋์ ๋ฐ๋ฅธ ์นด์ด์ ๊ณฑ๊ทธ๋ํ ๊ฐํ & ๋ถ์์ -
1> Goodness of Fit (One Sample ๐2 test)
1> ๊ฐ์ค๊ฒ์
→ H0) ์ฃผ์ด์ง data์ ๋ถํฌ๊ฐ ์์๋๋ ๋ถํฌ(expected frequencies)์ ๋์ผํ ๋ถํฌ๋ฅผ ๋ํ๋ธ๋ค
→ Ha) ์ฃผ์ด์ง data์ ๋ถํฌ๊ฐ ์์๋๋ ๋ถํฌ์ ๋์ผํ์ง ์๋ค (์ฆ, ๋น๋ชจ์์ ๋ฐฉ๋ฒ์ด๊ธฐ์ ์ ๊ท๋ถํฌ ๊ฐ์ ์ ๋ํ ๋ถํฌ ๊ฐ์ ์ด ์ธ๊ธ x. ๋งค์ฐ ๋ค์ํ ๋ถํฌ์ data์ ๋ํด ๋ชจ๋ ๊ท ๋ฑ ๋ถํฌ์ ๊ดํ ์ ํฉ์ฑ ํ์ ์ ๋ด๋ฆด ์ ์๋ ๊ฒ์ด๋ค.)
(*์์๋๋ ๋ถํฌ๋ ์ ์ฒด data์ ํ๊ท ์ผ๋ก ๊ตฌ์ฑ๋ ๋ถํฌ๋ฅผ ๋ง์ด ์ฌ์ฉ)
2> ์นด์ด์ ๊ณฑ๋ถํฌ - CV ๊ตฌํ๊ธฐ
→ ์ ๋ถ์์ ์ฌ์ง์์ α๋ก ์น ํ ๋ถ๋ถ์ critical region(๋์ด๊ฐ α)์ด๋ผ ๋ถ๋ฅด๋ฉฐ rejectํ๋ ๊ณณ์ด๋ค
→ df(n-1 ์์ ๋)์ ์ฃผ์ด์ง α(area to the Right of the CV)๋ฅผ ์ด์ฉํด CV ๊ตฌํ๊ธฐ (์นด์ด์ ๊ณฑ ๊ฒ์ ํต๊ณ๋)
* ์์ >
- α(0.1)์ ์์ ๋๋ฅผ ์ด์ฉํด ์นด์ด์ ๊ณฑ ๊ฒ์ ํต๊ณ๋ ๊ฐ์ด 9.236์ธ ๊ฑธ ์์๋ -
- ๊ทธ๋ฆฌ๊ณ ์ด ๊ฐ๋ณด๋ค ์ ์ ๊ฐ์ด ๋์ค๋ฉด reject region์ด ์๋๋ฏ๋ก H0์ ์ฑํ! -
(์๋ ๊ทธ๋ฆผ์์๋ ์นด์ด์ ๊ณฑ ๊ฐ์ด 5.6์ด ๋์์ผ๋ฏ๋ก H0 ์ฑํ)
3> ์นด์ด์ ๊ณฑ statistics ๊ตฌํ๊ธฐ
→ ์ด์ ์ฃผ์ด์ง CV๋ณด๋ค ์นด์ด์ ๊ณฑ statistics๊ฐ ํฐ ์ง ์์ ์ง ํ์ธํด์ผ ํ๋ค
(โป ์ฌ๊ธฐ์ ์นด์ด์ ๊ณฑ statistics๋ ์์น์ ๋ฐ๋ผ ๋ณํ๋ ๊ฐ์ด๋ค. ์ฆ, ์์น๊ฐ ์ ์ฒด์ ์ผ๋ก 10๋ฐฐ๋ง ์ปค์ ธ๋ ๊ฒ์ ํต๊ณ๋ ์์น ์์ฒด๊ฐ ์ปค์ง๋ค. ๋ฐ๋ผ์ ์ฐ๋ฆฌ๋ ๋์ ๋น๊ต(p-value)๋ฅผ ํตํด ๊ฐ์ค ๊ฒ์ ์ฌ๋ถ๋ฅผ ๋ฐ์ง ์ ์๋ค)
- ์๋ ์์ผ๋ก ์นด์ด์ ๊ณฑ ํต๊ณ๋์ ๊ตฌํ๋ค -
4> ๊ฒ์ ๊ฒฐ๊ณผ ๋ด๋ฆฌ๊ธฐ
โ ์นด์ด์ ๊ณฑ statistics >= CV์ด๋ฉด? - H0 rejected - Ha ์ฑํ - ์ฃผ์ด์ง data์ ๋ถํฌ๊ฐ ์์๋๋ data์ ๋ถํฌ์ ์ผ์นํ์ง ์๋ค
โก ์นด์ด์ ๊ณฑ statistics < CV์ด๋ฉด? - Ho ์ฑํ - ์ฃผ์ด์ง data์ ๋ถํฌ๊ฐ ์์๋๋ data์ ๋ถํฌ์ ์ผ์นํ๋ค
w/code
โ scipy.stats.chisquare docu() โ
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisquare.html
scipy.stats.chisquare(f_obs, f_exp=None, ddof=0, axis=0)
'Calculate a one-way chi-square test. The chi-square test tests the null hypothesis that the categorical data has the given frequencies.'
→ f_obs๋ ์ธก์ ํ๊ณ ์ถ์ frequency๋ค์ list๋ฅผ ์ง์ด๋ฃ์ผ๋ฉด ๋๋ค
→ f_exp๋ ์ธก์ ์ ์ฌ์ฉํ ๊ธฐ๋๊ฐ frequency๋ค์ list๋ฅผ ์ง์ด๋ฃ๋๋ค (default๋ ๋ชจ๋ ๊ด์ธก์น๊ฐ ๋๊ฐ์ ๊ฐ์ผ๋ก ๊ณ ๋ฅด๊ฒ ๋ถ๋ฐฐ๋๋ ํ๊ท ๊ฐ list)
→ ddof๋ delta degrees of freedom์ผ๋ก default๋ 0, ์ฆ ์์ ๋ ๊ณ์ฐ ์ (k-1)๋ก ๊ณ์ฐ๋จ. ์ฌ๊ธฐ์ p-value๋ฅผ ์ํด ์ถ๊ฐ๋ก ddof๋ก ์กฐ์ ํด์ค ์ ์๋ ๋ฐ dof = k - 1 -ddof๋ก ๊ณ์ฐ๋๋ค
โ returns (1) ์นด์ด์ ๊ณฑ ํต๊ณ๋ + (2) p-value โ
โ ์ฃผ์! โ
'This test is invalid when the observed or expected frequencies in each category are too small. A typical rule is that all of the observed and expected frequencies should be at least 5. According to (Pearson, Karl. “On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling”, Philosophical Magazine. Series 5. 50 (1900), pp. 157-175.), the total number of samples is recommended to be greater than 13, otherwise exact tests (such as Barnard’s Exact test) should be used because they do not overreject.'
→ ์ ์ด๋ 13๊ฐ ๋ณด๋ค๋ ๋ง๊ฒ sample๋ค์ด ์์ด์ผ ํต๊ณ์ ์ผ๋ก ์๋ฏธ ์๋ ๊ฒฐ๊ณผ๊ฐ ๋์จ๋ค๊ณ ํจ!
์์>
Q. ์ด 15๊ฐ์ ์ซ์๋ก ๋์ด๋์ด ์๋ ๋ ๊ฐ์ list๊ฐ ์๋ค๊ณ ํ์. ๊ฐ list๋ณ ํด๋น 15๊ฐ์ ์ซ์๋ก ๋ง๋ค์ด์ง ๋ถํฌ๋ ํด๋น ์ซ์๋ค์ ํ๊ท ์ผ๋ก ๋ง๋ค์ด์ง ๊ธฐ๋๊ฐ ๋ถํฌ์ ์ผ์นํ๋ค๊ณ ๋งํ ์ ์๋ ์ง(์ฆ ๊ท ๋ฑํ ๋ถํฌ๋ฅผ ๋๊ณ ์๋ ์ง) ์นด์ด์ ๊ณฑ๊ฒ์ ์ ์ด์ฉํด ๊ฐ๊ฐ ์ ํฉ์ฑ์ ๊ฒ์ ํด ๋ณด์
A1)
import numpy as np
from scipy.stats import chisquare
s_obs = np.array([20, 13, 25, 22, 20, 16, 19, 21, 23, 17, 19, 22, 20, 20, 19, 26, 24, 19, 17, 21])
chisquare(s_obs, axis=None)
#Power_divergenceResult(statistic=9.05955334987593, pvalue=0.9724771417573945)
* ๊ฒฐ๊ณผ> ์ฒซ๋ฒ์งธ list๋ pvalue๊ฐ 0.05๋ณด๋ค ํฌ๊ฒ ์ธก์ ๋๋ฏ๋ก H0์ ๊ธฐ๊ฐ๋์ด์๋ ์๋๋ค. ๋ฐ๋ผ์ s_obs list์ ์ซ์๋ก ๋ง๋ค์ด์ง ๋ถํฌ๋ ํ๊ท ์ ๋ฐ๋ฅด๋ ๊ธฐ๋๊ฐ ๋ถํฌ์ ์ผ์นํ๋ค(๊ท ๋ฑํ ๋ถํฌ๋ฅผ ๋ฐ๋ฅธ๋ค)๊ณ ํต๊ณ์ ์ ์์ฑ ๋ฒ์ ๋ด์์ ์ค๋ช ํ ์ ์๋ค.
A2)
s_obs = np.array([3, 2, 1, 5, 9, 2, 5, 5, 8, 2, 85, 76, 82, 82, 80, 79, 83, 81, 80, 78])
chisquare(s_obs)
#Power_divergenceResult(statistic=691.2924528301887, pvalue=2.513563617019893e-134)
* ๊ฒฐ๊ณผ> ๋๋ฒ์งธ lists๋ 0.05๋ณด๋ค ๋งค์ฐ ์๊ฒ ์ธก์ ๋๋ฏ๋ก H0์ ๊ธฐ๊ฐ, ์ฆ ๋ ๋ฒ์งธ list๋ ํ๊ท ๊ฐ์ผ๋ก ๋ง๋ค์ด์ง ๋ถํฌ์ ๋งค์ฐ ๋ค๋ฅด๋ค๊ณ ๋งํ ์ ์๋ค. ์ค์ ์ก์์ผ๋ก๋ง ๋ณด๋๋ผ๋ ๋งค์ฐ ๊ฐ์ด ์ ์ ์ซ์๋ค๊ณผ ํฐ ์ซ์๋ค์ด ๊ทน๋จ์ ์ผ๋ก ์์ธก์ ๋ถํฌํด ํ๊ท ๊ฐ์ ๋ชฐ๋ฆฐ ๋ถํฌ์ ํ์ฐํ ๋ค๋ฅด๋ค(๊ท ๋ฑํ ๋ถํฌ๋ฅผ ๋ฐ๋ฅด๊ณ ์์ง ์๋ค)๊ณ ํ๋จ ๊ฐ๋ฅ!
๐ฉ๐ one-sample chisquare test ์๋ฃ! ๐ฉ๐
* ์ธ๋ค์ผ ์ถ์ฒ) https://educationalresearchtechniques.com/2014/08/29/chi-square-goodness-of-fit-test/
* ๋ด์ฉ ์ผ๋ถ ์ถ์ฒ) ProDS(์ด๊ธ+์ค๊ธ)1
'Statistics > Concepts(+codes)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
f distribution (0) | 2022.05.04 |
---|---|
Two-Samples ๐2 test (0) | 2022.05.03 |
Parametric vs. Non-Parametric Tests (0) | 2022.05.02 |
Types of Errors in Hypothesis Testing (0) | 2022.04.27 |
ANOVA & (One-Way ANOVA + w/code) (1) | 2022.04.25 |
๋๊ธ