๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Statistics/Bayesian Statistics

(23)
ํ˜ผํ•ฉ ๋ชจ๋ธ(Mixture model) ๋‹ค์Œ์˜ ๋ฐ์ดํ„ฐ์˜ ํžˆ์Šคํ† ๊ทธ๋žจ์„ ํ™•์ธํ•˜๊ณ , ์ด๋ฅผ ์ ํ•ฉํ•  ๋ถ„ํฌ์— ๋Œ€ํ•˜์—ฌ ์ƒ๊ฐํ•ด ๋ณด์ž. In: data = read.csv('../input/mixture.csv', header = F) y = data$V1 n = length(y) hist(y, breaks = 20) Out: โ–ท ์ผ๋ฐ˜์ ์ธ ๋ถ„ํฌ์™€๋Š” ๋‹ค๋ฅด๊ฒŒ -2์™€ 1 ๊ทผ์ฒ˜์— ๋‘ ๊ฐœ์˜ ๋ด‰์šฐ๋ฆฌ๋ฅผ ํ˜•์„ฑํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์•Œ๊ณ  ์žˆ๋Š” ์ •๊ทœ๋ถ„ํฌ, ์ง€์ˆ˜๋ถ„ํฌ, ๊ฐ๋งˆ๋ถ„ํฌ๋Š” ๋‹จ๋ด‰ํ˜•ํƒœ๋ฅผ ๋„๊ณ  ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด๋ฅผ ์œ„์˜ ๋ฐ์ดํ„ฐ์— ์ ํ•ฉํ•  ๊ฒฝ์šฐ, ๋‘ ๊ฐœ์˜ ๋ด‰์šฐ๋ฆฌ์— ๋Œ€ํ•ด ์ ํ•ฉํ•œ ๋ถ„ํฌ๋ฅผ ์–ป์„ ์ˆ˜ ์—†๋‹ค. โ–ถ ํ˜ผํ•ฉ ๋ชจ๋ธ(Mixture model)์€ ๋‘ ๊ฐœ์ด์ƒ์˜ ๋ถ„ํฌ๋ฅผ ํ•ฉ์ณ์„œ ๋งŒ๋“  ๋ชจ๋ธ๋กœ ๊ธฐ์กด ๋ถ„ํฌ์— ๋น„ํ•˜์—ฌ ์ž์œ ๋„ ๋†’์€ ์ ํ•ฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์žฅ์ ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ๋˜ํ•œ ๋ณต์žกํ•œ ๋ถ„..
์ž„์˜์ ˆํŽธ ๋ชจ๋ธ(Random intercept model) R์˜ car ํŒจํ‚ค์ง€์˜ Leinhardt ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž„์˜์ ˆํŽธ ๋ชจ๋ธ(Random intercept model)์„ ๋ชจ๋ธ์„ ๋งŒ๋“ค์–ด๋ณด์ž. ์ˆ˜ํ–‰๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ๋ฐ์ดํ„ฐ ํ™•์ธ 2. ๋ชจ๋ธ๋ง 3. ๋ชจ๋ธํ™•์ธ 1. ๋ฐ์ดํ„ฐ ํ™•์ธ In: library(car) data('Leinhardt') pairs(Leinhardt) head(Leinhardt) Out: income infant region oil Australia 3426 26.7 Asia no Austria 3350 23.7 Europe no Belgium 3346 17.0 Europe no Canada 4751 16.8 Americas no Denmark 5029 13.5 Europe no Finland 3312 10.1 Europe no โ–ท ์—ฐ์†ํ˜• ..
Bayesian linear model for New York air quality measurements ์บ˜๋ฆฌํฌ๋‹ˆ์•„ ๋Œ€ํ•™๊ต์˜ "Bayesian Statistics: Techniques and Models"์„ ์ด์ˆ˜ํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœ์ ํŠธ ๊ฒฐ๊ณผ๋ฌผ์ด๋‹ค. ########################## # setting & loading data # ########################## set.seed(777) library(dplyr) library(tidyr) library(ggplot2) library(GGally) library(rjags) theme_set(theme_light() + theme(plot.title = element_text(face = 'bold', colour = 'grey10'), plot.subtitle = element_text(colour = 'grey25'), panel...
๊ณ„์ธต์  ๋ชจ๋ธ(Hierarchical model) ๋‹ค์Œ์˜ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ๊ณ„์ธต์  ๋ชจ๋ธ(Hierarchical model)์˜ ํŠน์ง•์„ ์•Œ์•„๋ณด๊ณ , ๋ชจ๋ธ๋ง ๊ฒฐ๊ณผ์— ๋Œ€ํ•ด ๋ถ„์„ํ•ด ๋ณด์ž. ๋ฌธ์ œ) ์น™์ด‰์„ ์ƒ์‚ฐํ•˜๋Š” 5๊ฐœ์˜ ๊ณต์žฅ์ด ์žˆ๋‹ค. ๊ฐ ๊ณต์žฅ์—์„œ ์ƒ์‚ฐ๋œ ์น™์ด‰ ๊ณผ์ž 1๊ฐœ์— ๋ฐ•ํ˜€ ์žˆ๋Š” ์ดˆ์ฝ”์นฉ ๊ฐœ์ˆ˜๊ฐ€ ํฌ์•„์†ก ๋ถ„ํฌ๋ฅผ ๋”ฐ๋ฅด๊ณ , ํฌ์•„์†ก ๋ถ„ํฌ์˜ ๋ชจ์ˆ˜๋Š” ๊ฐ๋งˆ๋ถ„ํฌ๋ฅผ ๋”ฐ๋ฅธ๋‹ค. cookies ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ์น™์ด‰ ๊ณผ์ž๊ฐ€ ์ƒ์‚ฐ๋  ๋•Œ, ๋ฐ•ํ˜€ ์žˆ๋Š” ์ดˆ์ฝ”์นฉ ๊ฐœ์ˆ˜์— ๋Œ€ํ•œ ๋ชจ๋ธ๋ง์„ ์ˆ˜ํ–‰ํ•œ ํ›„, ๋ถ„์„ํ•˜์‹œ์˜ค. ํ’€์ด) โ–ท ์œ„์˜ ๋ฌธ์ œ์— ๋Œ€ํ•ด ํฌ๊ฒŒ 3๊ฐ€์ง€ ๋ชจ๋ธ๋ง ๋ฐฉ๋ฒ•์œผ๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. (1) Fully independent model: ๋ชจ๋“  ๋ฐ์ดํ„ฐ๊ฐ€ ๋…๋ฆฝ์ด๋ผ ๊ฐ€์ •ํ•˜๊ณ , ํ•˜๋‚˜์˜ ํฌ์•„์†ก ๋ชจ๋ธ์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋Š” ๊ฐ ๊ณต์žฅ๋ณ„ ์ฐจ์ด์™€ ๊ฐ™์€ ๊ณต์žฅ์—์„œ ์ƒ์‚ฐ๋œ ์น™์ด‰์˜ ๋น„์Šทํ•œ ํŠน์„ฑ์„ ๊ณ ๋ คํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ํ•œ๊ณ„๊ฐ€ ์žˆ๋‹ค. ..
๋ฒ ์ด์ง€์•ˆ ํฌ์•„์†ก ํšŒ๊ท€(Bayesian poisson regression) ๋‹จ์ˆœ ํฌ์•„์†ก ํšŒ๊ท€(Simple poisson regression) ๋ชจ๋ธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. โ–ท ๊ฐ€๋Šฅ๋„๋Š” ํฌ์•„์†ก ๋ถ„ํฌ๋กœ ์ •ํ•˜๊ณ , ๊ฐ€๋Šฅ๋„ ๋ชจ์ˆ˜์˜ ๋กœ๊ทธ๋ฅผ ์ทจํ•œ ๊ฒƒ์— ๋Œ€ํ•˜์—ฌ ๋…๋ฆฝ๋ณ€์ˆ˜์˜ ์„ ํ˜•๊ฒฐํ•ฉ์œผ๋กœ ์ •์˜ํ•œ๋‹ค. ์ด๋•Œ, ์œ„์˜ ์‹์—์„œ๋Š” ํ•˜๋‚˜์˜ ๋…๋ฆฝ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์„ ํ˜•๊ฒฐํ•ฉ์œผ๋กœ ํ‘œํ˜„ํ•˜์˜€์ง€๋งŒ, ๋…๋ฆฝ๋ณ€์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ์ด๋ฉด ์ด ๋…๋ฆฝ๋ณ€์ˆ˜๋“ค์˜ ์„ ํ˜•๊ฒฐํ•ฉ์„ ํ†ตํ•ด ๊ฐ€๋Šฅ๋„ ๋ชจ์ˆ˜์˜ ๋กœ๊ทธ๋ฅผ ์ทจํ•œ ๊ฐ’์— ๋Œ€ํ•˜์—ฌ ์ •์˜ํ•œ๋‹ค. โ–ท ํฌ์•„์†ก ํšŒ๊ท€ ๋ชจ๋ธ์˜ ์˜ˆ์ธก์€ ๊ฐœ๋ณ„ ๋ฐ์ดํ„ฐ์˜ ๊ฐ€๋Šฅ๋„์˜ ํ‰๊ท , ์ฆ‰, ๊ฐ€๋Šฅ๋„์˜ ๋ชจ์ˆ˜๋ฅผ ํ†ตํ•ด ์ด๋ฃจ์–ด์ง„๋‹ค. โ–ท ๋ฒ ์ด์ง€์•ˆ ํฌ์•„์†ก ํšŒ๊ท€(Bayesian poisson regression)๋Š” ๋…๋ฆฝ๋ณ€์ˆ˜์™€ ์„ ํ˜•๊ฒฐํ•ฉ๋œ ๋ชจ์ˆ˜ beta์˜ ์‚ฌ์ „๋ถ„ํฌ๋ฅผ ์ •์˜ํ•œ๋‹ค๋Š” ์ ์—์„œ ํฌ์•„์†ก ํšŒ๊ท€์™€ ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค. R์˜ COUNT ํŒจํ‚ค์ง€์˜ badhealth ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฒ ์ด์ง€..
๋ฒ ์ด์ง€์•ˆ ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€(Bayesian logistic regression) ๋‹จ์ˆœ ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€(Simple logistic regression) ๋ชจ๋ธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. โ–ท ๊ฐ€๋Šฅ๋„๋Š” ๋ฒ ๋ฅด๋ˆ„์ด ๋ถ„ํฌ๋กœ ์ •ํ•˜๊ณ , ๊ฐ€๋Šฅ๋„ ๋ชจ์ˆ˜์˜ ๋กœ์ง“(Logit)์„ ๋…๋ฆฝ๋ณ€์ˆ˜์˜ ์„ ํ˜•๊ฒฐํ•ฉ์œผ๋กœ ์ •์˜ํ•œ๋‹ค. ์ด๋•Œ, ์œ„์˜ ์‹์—์„œ๋Š” ํ•˜๋‚˜์˜ ๋…๋ฆฝ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์„ ํ˜•๊ฒฐํ•ฉ์œผ๋กœ ํ‘œํ˜„ํ•˜์˜€์ง€๋งŒ, ๋…๋ฆฝ๋ณ€์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ์ด๋ฉด ์ด ๋…๋ฆฝ๋ณ€์ˆ˜๋“ค์˜ ์„ ํ˜•๊ฒฐํ•ฉ์„ ํ†ตํ•ด ๋กœ์ง“์„ ์ •์˜ํ•œ๋‹ค. โ–ท ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€์˜ ์˜ˆ์ธก์€ ๊ฐœ๋ณ„ ๋ฐ์ดํ„ฐ์˜ ๊ฐ€๋Šฅ๋„์˜ ํ‰๊ท , ์ฆ‰ ๊ฐ€๋Šฅ๋„์˜ ๋ชจ์ˆ˜๋ฅผ ํ†ตํ•ด ์ด๋ฃจ์–ด์ง„๋‹ค. โ–ถ ๋ฒ ์ด์ง€์•ˆ ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€(Bayesian logistic regression)๋Š” ๋กœ์ง“์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋…๋ฆฝ๋ณ€์ˆ˜์˜ ์„ ํ˜•๊ฒฐํ•ฉ๋œ ๋ชจ์ˆ˜์˜ ์‚ฌ์ „๋ถ„ํฌ๋ฅผ ์ •์˜ํ•œ๋‹ค๋Š” ์ ์—์„œ ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€์™€ ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค. R์˜ boot ํŒจํ‚ค์ง€์˜ urine ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฒ ์ด์ง€์•ˆ ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€ ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•  ๊ฒƒ..
DIC(Deviance Information Criterion) ๋ฒ ์ด์ง€์•ˆ ๋ชจ๋ธ์—์„œ๋Š” ๋ชจ๋ธ ์„ ํƒ์„ ์œ„ํ•œ ์ •๋ณด์˜ ๊ธฐ์ค€์œผ๋กœ์จ DIC(Deviance Information Criterion)์„ ์ œ์‹œํ•˜๊ณ  ์žˆ๋‹ค. DIC์˜ ๊ณต์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. โ–ท theta hat์€ ๊ฐ ๋ชจ์ˆ˜์˜ ์‚ฌํ›„ํ‰๊ท ์ด๊ณ , ์‚ฌํ›„๋ถ„ํฌ๋กœ๋ถ€ํ„ฐ ์–ป์€ theta hat์˜ ๋กœ๊ทธ ๊ฐ€๋Šฅ๋„์™€ ์‹ค์งˆ์ ์ธ ๋ชจ์ˆ˜์˜ ๊ฐฏ์ˆ˜(Effective number of parameters)๋ฅผ ๊ณ ๋ คํ•˜์—ฌ DIC๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค. โ–ถ ์‹ค์งˆ์ ์ธ ๋ชจ์ˆ˜์˜ ๊ฐฏ์ˆ˜๋Š” ๋ชจ๋ธ์˜ ์ถ”์ •์น˜ ์‚ฌ์ด์— ์ƒ๊ด€(Correlation)์„ ๊ณ ๋ คํ•˜๊ธฐ ์œ„ํ•œ ๊ฒƒ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ชจ๋ธ์˜ ์ถ”์ •์น˜ ์‚ฌ์ด์— 0.99์˜ ์ƒ๊ด€์ด ์กด์žฌํ•œ๋‹ค๋ฉด ์ด๋ฅผ ๋…๋ฆฝ์ ์ธ ๋ชจ์ˆ˜๋กœ ๊ฐ„์ฃผํ•œ๋‹ค๋ฉด ํ•ฉ๋ฆฌ์ ์ด์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค. R์˜ car ํŒจํ‚ค์ง€์˜ Leihardt ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•œ ๋‘ ๋ชจ๋ธ์„ DIC๋ฅผ ํ†ตํ•ด ๋น„๊ตํ•˜์—ฌ๋ณด์ž. In: lib..
๋ฒ ์ด์ง€์•ˆ ์„ ํ˜• ํšŒ๊ท€(Bayesian linear regression) R์˜ car ํŒจํ‚ค์ง€์˜ Leihardt ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฒ ์ด์ง€์•ˆ ์„ ํ˜• ํšŒ๊ท€(Bayesian linear regression) ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•  ๊ฒƒ์ด๋‹ค. ์ˆ˜ํ–‰ ๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ๋ฐ์ดํ„ฐ ํ™•์ธ 2. ๋ชจ๋ธ๋ง 3. ๋ชจ๋ธ ํ™•์ธ 4. ์ž”์ฐจ ๋ถ„์„ 1. ๋ฐ์ดํ„ฐ ํ™•์ธ In: library(car) data('Leinhardt') pairs(Leinhardt) Out: โ–ท Leihardt ๋ฐ์ดํ„ฐ๋Š” ์—ฐ์†ํ˜• ๋ณ€์ˆ˜์ธ income, infant, region๊ณผ ๋ฒ”์ฃผํ˜• ๋ณ€์ˆ˜์ธ oil๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. โ–ท income๊ณผ infant๊ฐ€ ๋น„์„ ํ˜•์ ์ธ ๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋‚ด๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์„ ํ˜•๋ชจ๋ธ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ณ€์ˆ˜๊ฐ„ ์„ ํ˜•๊ด€๊ณ„๋ฅผ ๊ฐ€์ •ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‘ ๋ณ€์ˆ˜์— ๋กœ๊ทธ๋ฅผ ์ทจํ•˜์—ฌ ๋ณ€ํ˜•ํ•  ๊ฒƒ์ด๋‹ค. In: Leinhardt$log_income ..
MCMC(Markov Chain Monte-Carlo)์˜ ์ˆ˜๋ ด(Convergence) MCMC(Markov Chain Monte-Carlo)๋ฅผ ํ†ตํ•ด ์ƒ์„ฑํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋งˆ๋ฅด์ฝ”ํ”„ ์ฒด์ธ(Markov Chain)์ด ์ •์ƒ์ƒํƒœ(Stationary)์— ์ˆ˜๋ ด(Convergence)ํ•ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผ ํ™•์ธํ•˜๊ณ  ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค. 1. Trace plot 2. ์ž๊ธฐ์ƒ๊ด€์„ฑ(Autocorrelation) 3. ์ดˆ๊ธฐ ๋‹จ๊ณ„(Burn-in period) 1. Trace plot MCMC์˜ ์ˆ˜๋ ด์„ ํ™•์ธํ•˜๋Š” ๊ฐ€์žฅ ์ง๊ด€์ ์ธ ๋ฐฉ๋ฒ•์€ ๋ฐ์ดํ„ฐ์˜ ์ƒ์„ฑ ๊ณผ์ •์„ ์ง์ ‘ ๊ทธ๋ฆผ์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์ด๋‹ค. ์‹œํ–‰ํšŸ์ˆ˜์— ๋”ฐ๋ฅธ ์ƒ์„ฑ๋œ ๋ฐ์ดํ„ฐ์˜ ๋ถ„ํฌ๋ฅผ ํ†ตํ•ด ์ด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. In: log_g
๊น์Šค ์ƒ˜ํ”Œ๋ง(Gibbs sampling) ๊น์Šค ์ƒ˜ํ”Œ๋ง(Gibbs sampling)์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ ๊ฒƒ์ด๋‹ค. ๋‹ค๋ฃฐ ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ๊น์Šค ์ƒ˜ํ”Œ๋ง 2. ๊น์Šค ์ƒ˜ํ”Œ๋ง์˜ ์˜ˆ์ œ 1. ๊น์Šค ์ƒ˜ํ”Œ๋ง ๊น์Šค ์ƒ˜ํ”Œ๋ง์€ Metropolis Hastings(์ดํ•˜ MH) ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํŠน๋ณ„ํ•œ ํ˜•ํƒœ๋กœ, ์ œ์•ˆ ๋ถ„ํฌ(Proposal distribution)๋ฅผ ์ž์‹ ์˜ Full conditional distribution๋กœ ๋‘์–ด ์ƒ˜ํ”Œ๋งํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์ด๋ ‡๊ฒŒ ํ•จ์œผ๋กœ์จ, ๊ฐ ์‹œํ–‰์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด Acceptance probability๋Š” 1์ด ๋˜๋Š” ์„ฑ์งˆ์„ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค. ๋‹ค์Œ์˜ ์ฆ๋ช…์„ ํ†ตํ•˜์—ฌ ์ด๋ฅผ ํ™•์ธํ•ด๋ณด์ž. โ–ท ์ œ์•ˆ ๋ถ„ํฌ๋ฅผ Full conditional posterior๋กœ ๋‘ ์œผ๋กœ์จ ๋ฏธ์„ธ ๊ท ํ˜• ์กฐ๊ฑด(Detailed balance condition)์ด ์„ฑ๋ฆฝํ•˜๊ฒŒ ๋œ๋‹ค. ..
JAGS(Just Another Gibbs Sampler) ์‚ฌ์šฉ๋ฒ• R์˜ JAGS(Just Another Gibbs Sampler)์˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ ๊ฒƒ์ด๋‹ค. JAGS๋ฅผ ํ†ตํ•œ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ ๊ณผ์ •์€ 4๋‹จ๊ณ„๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค. 1. Specify the model 2. Set up the model 3. Run the MCMC(Markov Chain Monte Carlo) sampler 4. Post processing ๋‹ค์Œ์˜ ๋ชจ๋ธ์— ์ด๋ฅผ ๋‹จ๊ณ„๋ณ„๋กœ ์ ์šฉํ•˜์—ฌ ์‚ฌํ›„๋ถ„ํฌ๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ณด์ž. 1. Specify the model In: library(rjags) mod_string = " model { for (i in 1:n) { y[i] ~ dnorm(mu, 1.0/sig2) } mu ~ dt(0.0, 1.0/1.0, 1) sig2 = 1.0 } " โ–ท ์œ„์˜ ์ฝ”๋“œ์™€..
๋ฉ”ํŠธ๋กœํด๋ฆฌ์Šค ํ—ค์ด์ŠคํŒ…์Šค ์•Œ๊ณ ๋ฆฌ์ฆ˜(Metropolis-Hastings algorithm) Metropolis-Hastings(์ดํ•˜ MH) ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ ๊ฒƒ์ด๋‹ค. MH ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ MCMC(Markov Chain Monte-Carlo)์˜ ์ผ๋ฐ˜์ ์ธ ํ˜•ํƒœ๋กœ์จ ํŠน์ • ๋ถ„ํฌ๋กœ๋ถ€ํ„ฐ ์ •์ƒ๋ถ„ํฌ๋กœ ๊ฐ–๋Š” ์ฒด์ธ์„ ๋ฐœ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํŠน์ • ๋ถ„ํฌ๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋ฃฐ ๋‚ด์šฉ์œผ๋กœ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. MH ์•Œ๊ณ ๋ฆฌ์ฆ˜ 2. Random walk MH ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„ 1. MH ์•Œ๊ณ ๋ฆฌ์ฆ˜ MH ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. โ–ท q๋Š” ์ œ์•ˆ ๋ถ„ํฌ(Proposal distribution)๋ฅผ ์˜๋ฏธํ•˜๊ณ , g๋Š” ์šฐ๋ฆฌ์˜ ๋ชฉ์  ๋ถ„ํฌ(Target distribution)์—์„œ ์ •๊ทœํ™” ์ƒ์ˆ˜(Normalizing constant)๋ฅผ ์ œ์™ธํ•œ ๋ถ€๋ถ„์ด๋‹ค. ์ฆ‰, ๋ชฉ์  ๋ถ„ํฌ์™€ g(theta)๋Š” ๋น„๋ก€ ๊ด€๊ณ„๊ฐ€ ์„ฑ๋ฆฝํ•œ๋‹ค. โ–ท ์ดˆ๊ธฐ๊ฐ’..