先驗分配

使用 rstanarm 的貝葉斯迴歸建模

Jake Thompson

Psychometrician, ATLAS, University of Kansas

什麼是先驗分配?

  • 我們帶入模型的先備資訊
  • 似然 + 先驗 = 後驗
使用 rstanarm 的貝葉斯迴歸建模

使用 rstanarm 的貝葉斯迴歸建模

rstanarm 中的先驗分配

stan_model <- stan_glm(kid_score ~ mom_iq, data = kidiq)
prior_summary(stan_model)
Priors for model 'stan_model' 
 ------
Intercept (after predictors centered)
 ~ normal(location = 0, scale = 10)
     **adjusted scale = 204.11
Coefficients
 ~ normal(location = 0, scale = 2.5)
     **adjusted scale = 3.40
Auxiliary (sigma)
 ~ exponential(rate = 1)
     **adjusted scale = 20.41 (adjusted rate = 1/adjusted scale)
 ------
See help('prior_summary.stanreg') for more details
使用 rstanarm 的貝葉斯迴歸建模

計算調整後尺度

  • 截距:10 * sd(y)
  • 迴歸係數:(2.5 / sd(x)) * sd(y)
prior_summary(stan_model)
Priors for model 'stan_model' 
 ------
Intercept (after predictors centered)
 ~ normal(location = 0, scale = 10)
     **adjusted scale = 204.11

Coefficients
 ~ normal(location = 0, scale = 2.5)
     **adjusted scale = 3.40

 

10 * sd(kidiq$kid_score)
204.1069
(2.5 / sd(kidiq$mom_iq)) * sd(kidiq$kid_score)
3.401781
使用 rstanarm 的貝葉斯迴歸建模
no_scale <- stan_glm(kid_score ~ mom_iq, data = kidiq,
  prior_intercept = normal(autoscale = FALSE),
  prior = normal(autoscale = FALSE),
  prior_aux = exponential(autoscale = FALSE))
prior_summary(no_scale)
Priors for model 'no_scale' 
 ------
Intercept (after predictors centered)
 ~ normal(location = 0, scale = 10)

Coefficients
 ~ normal(location = 0, scale = 2.5)

Auxiliary (sigma)
 ~ exponential(rate = 1)
 ------
See help('prior_summary.stanreg') for more details
使用 rstanarm 的貝葉斯迴歸建模

一起來練習吧!

使用 rstanarm 的貝葉斯迴歸建模

Preparing Video For Download...