比較貝氏與傳統統計方法

使用 rstanarm 的貝葉斯迴歸建模

Jake Thompson

Psychometrician, ATLAS, University of Kansas

參數相同!

tidy(lm_model)
         term   estimate  std.error statistic      p.value
1 (Intercept) 25.7997778 5.91741208  4.359977 1.627847e-05
2      mom_iq  0.6099746 0.05852092 10.423188 7.661950e-23
tidy(stan_model)
        term   estimate  std.error
1 (Intercept) 25.7257965 6.01262625
2      mom_iq  0.6110254 0.05917996
使用 rstanarm 的貝葉斯迴歸建模

傳統統計 vs. 貝氏

  • 傳統統計:參數固定,資料隨機
  • 貝氏:參數隨機,資料固定
  • 什麼是 p 值?
    • 在虛無假設下,檢定統計量的機率
  • 那貝氏要的是什麼?
    • 在觀測到的資料下,參數值的機率
使用 rstanarm 的貝葉斯迴歸建模

評估貝氏參數

  • 信賴區間:某範圍含真值的機率
    • 有 90% 的機率此範圍包含真值
  • 相信區間:真值落在某範圍內的機率
    • 有 90% 的機率真值落在此範圍內
  • 參數值的機率 vs. 區間邊界的機率
使用 rstanarm 的貝葉斯迴歸建模

建立相信區間

posterior_interval(stan_model)
                    5%        95%
(Intercept) 16.1396617 35.6015948
mom_iq       0.5131289  0.7042666
sigma       17.2868651 19.3411104
posterior_interval(stan_model, prob = 0.95)
                  2.5%      97.5%
(Intercept) 14.5472824 37.2505664
mom_iq       0.4963677  0.7215823
sigma       17.1197930 19.5359616
posterior_interval(stan_model, prob = 0.5)
                   25%        75%
(Intercept) 21.7634032 29.6542886
mom_iq       0.5714405  0.6496865
sigma       17.8776965 18.7218373
使用 rstanarm 的貝葉斯迴歸建模

信賴區間 vs. 相信區間

confint(lm_model, parm = "mom_iq", level = 0.95)
           2.5 %    97.5 %
mom_iq 0.4949534 0.7249957
stan_model <- stan_glm(kid_score ~ mom_iq, 
                       data = kidiq)
posterior_interval(stan_model, 
                   pars = "mom_iq", 
                   prob = 0.95)
             2.5%     97.5%
mom_iq 0.4963677  0.7215823
posterior <- spread_draws(stan_model, mom_iq) 
mean(between(posterior_mom_iq, 0.60, 0.65))
0.31475
使用 rstanarm 的貝葉斯迴歸建模

一起來練習吧!

使用 rstanarm 的貝葉斯迴歸建模

Preparing Video For Download...