Fitting Statistical Models to Data with Python - WEEK 3 - part 3
Multilevel and marginal modeling, a case study with the NHANES data
- ๋ฐ์ดํฐ๋ผ๋ ๊ฒ์, ์ฌ์ค ์ฌ๋ฌ ๊ด๊ณ๋ฅผ ๊ฐ์ง๊ณ ์์ ์ ์์ต๋๋ค. ํ๋์ ์ ํ์ ์ธ ๊ด๊ณ๋ง ๊ฐ์ง๋ ๊ฒ์ด ์๋๋ผ, multi-level๋ก ๊ตฌ์ฑ๋์ด,
a ~ b,b ~ c์ ํํ๋ก ์กด์ฌํ ์ ์๋ค๋ ๊ฒ์ด์ฃ . ์ด๋ฌํ ํํ๋ก ๋ชจ๋ธ๋งํ๋ ๊ฒ์ด ๋ณดํต multi-level modeling์ ๋๋ค. - ๊ทธ๋ฆฌ๊ณ , ๋ณดํต ์ด์ฒ๋ผ ์๋ก ๋ด๋ถ์ ์ธ ๊ด๊ณ๊ฐ ์กด์ฌํ๊ฒ ๋๋ ๊ฒ์ ๊ทธ ๋ฐ์ดํฐ๊ฐ ํน์ ํ class ํน์ cluster์ ํฌํจ๋์ด ์๊ธฐ ๋๋ฌธ์ด์ฃ . ๋ฌผ๋ก , ์ ์ค๊ณ๋ ์คํ์์๋ ํ๊ฒ ๊ทธ๋ฃน์ ๋ํด์ ํผ์คํ์๋ฅผ ๋ฌด์์๋ก ์ ์ ํ์ฌ, ์ ์ ๋ ๋ฐ์ดํฐ๊ฐ ์ฐ๋ฆฌ๊ฐ ์ํ๋ ํ๊ฒ ๊ทธ๋ฃน์ ์ ํํ ๋ํํ ์ ์๋๋ก ์กฐ์ ํ์ง๋ง, ๋๋ถ๋ถ์ ๋ฐ์ดํฐ ์์ง์์๋ ์ด๋ฌํ ๋ถ๋ถ์ด ์ถฉ์คํ๊ฒ ๋ฐ์๋์ด ์๋ค๊ณ ํ๊ธฐ ์ด๋ ต์ต๋๋ค.
- ๋ฐ๋ผ์ ๋ณธ ์ฑํฐ์์๋ NHANES์ ๋ฐ์ดํฐ๋ฅผ ๋์์ผ๋ก ํด๋ฌ์คํฐ๋ฅผ ๋ฐ์ํ์ฌ ๋ชจ๋ธ์ ์๋ฆฝํ๋ค. cluster๋ ๋ณดํต ํผ์คํ์์ ๊ฐ์ธ์ ์ธ ๋ฐ์ดํฐ(๋์ด, ์ฑ๋ณ ๋ฑ)์ ๊ธฐ๋ฐํ์ง๋ง, ์ด๋ฌํ ๋ฐ์ดํฐ๋ค์ ๋ณดํต ๊ฐ์ธ์ ๋ณด์ด๋ฏ๋ก ์จ๊ฒจ์ง๋ค. ๋์ ๋ณธ ๋ฐ์ดํฐ์์๋
MVUs: "masked variance units"๊ฐ ์กด์ฌํ๋ฉฐ, ์ด๊ฒ์ด ์ค์ ๋ก ์กด์ฌํ๋ cluster๊ฐ ๋๋ค.
Intraclass correlation
- ํด๋ฌ์คํฐ ๋ด์ ๊ด์ธก(observation)๋ค๊ฐ์ ์ ์ฌ์ฑ์ ๋ณดํต ICC(IntraClass Correlation)์ด๋ผ๋ ํต๊ณ ๊ฐ์ผ๋ก ์ธก์ ๋๋ค. ๋ณดํต 0๊ณผ 1์ ๊ฐ์ ๊ฐ์ง๋ฉฐ, pearsonโs correlation๊ณผ๋ ๊ตฌ๋ณ๋๋ ํํ๋ค.
- ICC๋ ๋ ๊ฐ์ง์ regression technique๋ฅผ ์ฌ์ฉํ์ฌ ํ๊ฐํ๋๋ฐ, ํ๋๋ GEE๋ฅผ ์ด์ฉํ Marginal regression, ๋๋ฒ์งธ๋ Mixed Linear Model์ ์ฌ์ฉํ Multi-level regression์ด ๋๋ค.
- ๋ค์๊ณผ ๊ฐ์ด, ๋ค์ํ column์ ๋ํด์ class ๋ด ๊ฐ๋ค์ ๊ด๋ จ์ฑ์ ๋์ถํด๋ณธ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ๋ค.
################
# Assess ICC(Intra Class Cluster)
# GEE์ ๊ฐ group์ ๋ฐ๋ผ
print("== Assess ICC(IntraClass Cluster")
for col in ["BPXSY1", "RIDAGEYR", "BMXBMI", "smq", "SDMVSTRA"]:
model = sm.GEE.from_formula(
formula=f"{col} ~ 1",
groups="group",
cov_struct=sm.cov_struct.Exchangeable(),
data=da
)
result = model.fit()
print(f"{col} :: {result.cov_struct.summary()}")
print("=="*20)
- ํนํ,
SDMVSTRA๊ฐ ๋งค์ฐ ๋์ ICC๊ฐ์ ๊ฐ์ง๋ ๊ฒ์ ์ ์ ์๋ค. ๋๋จธ์ง ๊ฐ๋ค๋, 0.03์ด๋ฉด ๋์ ํธ์ด๋ฉฐ, range(-0.002 0.002)์ ๋ฐ์ ์์นํ ๊ฒฝ์ฐ, ์ด๋ ์ ๋ ๊ด๋ จ์ฑ์ด ๋๋ค, ๋ผ๊ณ ํ ์ ์๋ค. ๋ณดํต pearson correlation์์๋ ๊ฐ์ด 0.03 ์ ๋์ ๊ฐ์ด๋ฉด ๋ฌด์ํด๋ ๋๋ค๊ณ ์๊ฐํ์ง๋ง, ICC๋ ์ด์ ๋ ๊ฐ์ด๋ฉด ์์ง๋ง, ๋ฌด์ํ๊ธฐ๋ ์ด๋ ค์ด ๊ฐ์ด๋๋ค.
== Assess ICC(IntraClass Cluster
BPXSY1 :: The correlation between two observations in the same cluster is 0.030
RIDAGEYR :: The correlation between two observations in the same cluster is 0.035
BMXBMI :: The correlation between two observations in the same cluster is 0.039
smq :: The correlation between two observations in the same cluster is 0.026
SDMVSTRA :: The correlation between two observations in the same cluster is 0.959
wrap-up
- ๊ทธ ์ธ๋ก๋ ๋ค์ํ ๋ด์ฉ๋ค์ด ์์๋ค. ํนํ, GLM๊ณผ GEE๋ฅผ ์ฌ์ฉํ ๋์ ์ฐจ์ด์ , GLM์ ๋ช ์์ ์ผ๋ก ๋ฐ์ดํฐ ๋ด์ ์กด์ฌํ๋ dependence structure๋ฅผ ์ ์ธํด์ผ ํ๋ ๋ฐ๋ฉด, GEE๋ ์จ๊ฒจ์ง ๊ตฌ์กฐ๋ฅผ ์ ์ถํด๊ฐ๋ ์์ผ๋ก ์งํํ๋ฏ๋ก, ๊ทธ ๋ฐ์ดํฐ ๋ด์ ์กด์ฌํ๋ ๊ด๊ณ๋ค์ ๋ํด์ ๋ช ํํ์ง ์์๋ ์ฌ์ฉํ๊ธฐ ์ข๋ค๋ ๊ฒ. marginal model์ด GEE, multilevel-model์ด Linear Mixed Model์ด๋ผ๋ ๊ฒ.
- ๊ทธ์ธ๋ก๋ ๋ค์ํ ๋ด์ฉ๋ค์ด ์์์ผ๋, ์ด์ ์ ๋ฐฐ์ ๋ ๋ด์ฉ๋ค๊ณผ ๊ฐ๋ ์ ์ผ๋ก ํฌ๊ฒ ๋ฒ์ด๋์ง ์๋ ๊ฒ ๊ฐ์์ ์ฐ์ ์ ์ธํ์์ต๋๋ค.
GitHub์์ ์ด ๊ธ์ ๋งํฌ๋ค์ด ์๋ณธ ๋ณด๊ธฐ & ์์ ์ ์src/content/posts/2020-01-20-fitting_stat_model_week_3_part3
๐ ์ฐ๊ด ์ง์ ํ๋ธ:๐ python-libs ์นดํ
๊ณ ๋ฆฌ๐ Python ์ปค๋ฆฌํ๋ผ#python#python-libs#coursera
๐กRELATED ARTICLES ยท ํจ๊ป ์ฝ์ผ๋ฉด ์ข์ ์ฐ๊ด ํฌ์คํธ
python-libs
Fitting Statistical Models to Data with Python - WEEK 3 - part 1
์ฝ์ด๋ณด๊ธฐ→
python-libs
Fitting Statistical Models to Data with Python - WEEK 3 - part 2
์ฝ์ด๋ณด๊ธฐ→
python-libs
Fitting Statistical Models to Data with Python - WEEK 1 - Part 1
์ฝ์ด๋ณด๊ธฐ→
python-libs
Fitting Statistical Models to Data with Python - WEEK 1 - Part 2
์ฝ์ด๋ณด๊ธฐ→