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

Statistics/Bayesian Statistics

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:

library(car)
library(rjags)

data('Leinhardt')

Leinhardt$log_infant = log(Leinhardt$infant)
Leinhardt$log_income = log(Leinhardt$income)

data = na.omit(Leinhardt)

###########
# model 1 #
###########

mod1_string = " model {
  for (i in 1:n) {
    y[i] ~ dnorm(mu[i], prec)
    mu[i] = b[1] + b[2]*log_income[i] 
  }
  
  for (i in 1:2) {
    b[i] ~ dnorm(0.0, 1.0/1.0e6)
  }
  
  prec ~ dgamma(5/2.0, 5*10.0/2.0)
  sig2 = 1.0 / prec
  sig = sqrt(sig2)
} "

data1_jags = list(y = data$log_infant, 
                  n = nrow(data), 
                  log_income = data$log_income)

params1 = c('b', 'sig')

inits1 = function() {
  inits = list('b' = rnorm(2, 0.0, 100.0), 'prec' = rgamma(1, 1.0, 1.0))
}

mod1 = jags.model(textConnection(mod1_string), 
                  data = data1_jags, 
                  inits = inits1, 
                  n.chains = 3)

###########
# model 2 #
###########

mod2_string = " model {
    for (i in 1:length(y)) {
        y[i] ~ dnorm(mu[i], prec)
        mu[i] = b[1] + b[2]*log_income[i] + b[3]*is_oil[i]
    }
    
    for (i in 1:3) {
        b[i] ~ dnorm(0.0, 1.0/1.0e6)
    }
    
    prec ~ dgamma(5/2.0, 5*10.0/2.0)
    sig = sqrt( 1.0 / prec )
} "

data2_jags = list(y = data$log_infant, 
                  log_income = data$log_income,
                  is_oil = as.numeric(data$oil == 'yes'))

params2 = c('b', 'sig')

inits2 = function() {
  inits = list('b' = rnorm(3, 0.0, 100.0), 
               'prec' = rgamma(1, 1.0, 1.0))
}

mod2 = jags.model(textConnection(mod2_string), 
                  data = data2_jags, 
                  inits = inits2, 
                  n.chains = 3)
                  
update(mod1, 1e3)
update(mod2, 1e3)

 

Out:

Compiling model graph
   Resolving undeclared variables
   Allocating nodes
Graph information:
   Observed stochastic nodes: 101
   Unobserved stochastic nodes: 3
   Total graph size: 404

Initializing model
Compiling model graph
   Resolving undeclared variables
   Allocating nodes
Graph information:
   Observed stochastic nodes: 101
   Unobserved stochastic nodes: 4
   Total graph size: 507

Initializing model
  |**************************************************| 100%
  |**************************************************| 100%

 

โ–ท ์œ„์˜ ๋‘ ๋ชจ๋ธ์€ ์—ฐ์†ํ˜• ๋ณ€์ˆ˜์ธ infant๋ฅผ ์˜ˆ์ธกํ•˜๊ธฐ ์œ„ํ•œ ์„ ํ˜•ํšŒ๊ท€ ๋ชจ๋ธ์ด๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ชจ๋ธ์€ ์—ฐ์†ํ˜• ๋ณ€์ˆ˜์ธ income๋งŒ์„ ์ด์šฉํ•˜์˜€๊ณ , ๋‘ ๋ฒˆ์งธ ๋ชจ๋ธ์€ income๊ณผ ๋ฒ”์ฃผํ˜• ๋ณ€์ˆ˜์ธ oil์„ ์ด์šฉํ•˜์—ฌ ๋ชจ๋ธ๋งํ•˜์˜€๋‹ค.

 

โ–ท DIC๋ฅผ ๊ตฌํ•˜๊ธฐ ์ „, 1,000ํšŒ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ์„ ํ†ตํ•ด ๋งˆ๋ฅด์ฝ”ํ”„ ์ฒด์ธ์ด ์ˆ˜๋ ดํ•˜๋„๋ก ํ•˜์˜€๋‹ค. ์ˆ˜๋ ด์„ ํ™•์ธํ•˜๋Š” ๊ณผ์ •์€ ์•„๋ž˜์˜ ํฌ์ŠคํŒ…์„ ํ†ตํ•ด์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

MCMC(Markov Chain Monte-Carlo)์˜ ์ˆ˜๋ ด(Convergence)

MCMC(Markov Chain Monte-Carlo)๋ฅผ ํ†ตํ•ด ์ƒ์„ฑํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋งˆ๋ฅด์ฝ”ํ”„ ์ฒด์ธ(Markov Chain)์ด ์ •์ƒ์ƒํƒœ(Stationary)์— ์ˆ˜๋ ด(Convergence)ํ•ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผ ํ™•์ธํ•˜๊ณ  ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค...

rooney-song.tistory.com

 

In:

dic.samples(mod1, n.iter = 1e3)
dic.samples(mod2, n.iter = 1e3)

 

Out:

  |**************************************************| 100%
Mean deviance:  231.4 
penalty 2.945 
Penalized deviance: 234.3 
  |**************************************************| 100%
Mean deviance:  225.5 
penalty 3.999 
Penalized deviance: 229.5 

 

โ–ท dic.samples()๋Š” ์‚ฌํ›„๋ถ„ํฌ๋กœ๋ถ€ํ„ฐ n.iter๋งŒํผ ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ด ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ถ”์ •์น˜๋ฅผ ๊ตฌํ•˜๊ณ  DIC๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.

 

โ–ท Mean deviance๋Š” ์ถ”์ •์น˜์˜ ๋กœ๊ทธ ๊ฐ€๋Šฅ๋„์— -2๋ฅผ ๊ณฑํ•œ ๊ฒƒ์œผ๋กœ, ๋‚ฎ์„์ˆ˜๋ก ๋ชจ๋ธ์ด ๋ฐ์ดํ„ฐ์— ์ž˜ ์ ํ•ฉํ•œ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ๋ฐ˜๋ฉด, penalty๋Š” ์‹ค์งˆ์ ์ธ ๋ชจ์ˆ˜์˜ ๊ฐฏ์ˆ˜๋กœ, ์ฒซ ๋ฒˆ์งธ ๋ชจ๋ธ์˜ ๊ฒฐ๊ณผ๋Š” 2.945์ธ ๊ฒƒ์œผ๋กœ ๋‚˜ํƒ€๋‚ฌ๋‹ค. ๋ชจ๋ธ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ b[1], b[2], prec๋•Œ๋ฌธ์— ์•ฝ 3๊ฐœ๋กœ ๋‚˜ํƒ€๋‚œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‘ ๋ฒˆ์งธ ๋ชจ๋ธ์€ oil์— ๋Œ€ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์œผ๋ฏ€๋กœ, ์•ฝ 4๊ฐœ์ธ ๊ฒƒ์œผ๋กœ ๋‚˜ํƒ€๋‚œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

โ–ถ Penalized deviance๋Š” Mean deviance์™€ penalty์˜ ํ•ฉ์œผ๋กœ DIC๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

 

โ–ท ๋ชจ๋ธ ์„ ํƒ์‹œ, DIC๊ฐ€ ๋‚ฎ์„์ˆ˜๋ก ๋” ์ ํ•ฉํ•œ ๋ชจ๋ธ์ž„์„ ์˜๋ฏธํ•œ๋‹ค. ๋”ฐ๋ผ์„œ DIC๊ฐ€ 229.5๋กœ ๋” ๋‚ฎ์€ ๋‘ ๋ฒˆ์งธ ๋ชจ๋ธ์„ ์ตœ์ข… ๋ชจ๋ธ๋กœ ์„ ์ •ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค.

 


Reference:

"Bayesian Statistics: From Concept to Data AnalysisTechniques and Models," Coursera, https://www.coursera.org/learn/bayesian-statistics/.

"DIC์™€ WAIC: ๋ฒ ์ด์ง€์•ˆ ๋ชจํ˜•์„ ํƒ์„ ์œ„ํ•œ ์ •๋ณด ๊ธฐ์ค€๋“ค," ๋ฐ•์ค€์„, https://bayestour.github.io/blog/2019/07/12/DIC_WAIC.html.