3

我对如何为以下模型的多个预测变量设置先验有点困惑:

require(rstanarm)

wi_prior <- normal(0, sd(train$attendance))
SEED     <- 101

fmla <- attendance ~ (1 + W + W1 + W2 + W3 + DivWin1 + DivWin2 + DivWin3 + 
                      WSWin1 | franchID)

baylm <- stan_glmer(fmla, 
                    data = train, 
                    family = "gaussian", 
                    algorithm = "sampling",
                    adapt_delta = .95,
                    prior_intercept = wi_prior, seed = SEED)

根据请求,这是火车中的第一次观察。

train <- structure(list(franchID = structure(25L, .Label = c("ANA", "ARI", 
                                                             "ATL", "BAL", "BOS", "CHC", "CHW", "CIN", "CLE", "COL", "DET", 
                                                             "FLA", "HOU", "KCR", "LAD", "MIL", "MIN", "NYM", "NYY", "OAK", 
                                                             "PHI", "PIT", "SDP", "SEA", "SFG", "STL", "TBD", "TEX", "TOR", 
                                                             "WSN"), class = "factor"), yearID = 1999L, name = "San Francisco Giants", 
                        park = "3Com Park", attendance = 2078399L, W = 86L, W1 = 89L, 
                        W2 = 90L, W3 = 68L, WCWin1 = FALSE, WCWin2 = FALSE, WCWin3 = FALSE, 
                        DivWin1 = FALSE, DivWin2 = TRUE, DivWin3 = FALSE, LgWin1 = FALSE, 
                        LgWin2 = FALSE, LgWin3 = FALSE, WSWin1 = FALSE, WSWin2 = FALSE, 
                        WSWin3 = FALSE), .Names = c("franchID", "yearID", "name", 
                                                    "park", "attendance", "W", "W1", "W2", "W3", "WCWin1", "WCWin2", 
                                                    "WCWin3", "DivWin1", "DivWin2", "DivWin3", "LgWin1", "LgWin2", 
                                                    "LgWin3", "WSWin1", "WSWin2", "WSWin3"), row.names = c(NA, -1L
                                                    ), class = "data.frame")
4

1 回答 1

2

您可以通过将长度为 K 的向量传递给支持的先验分布之一,为 K 个预测变量上的系数指定先验。例如,如果 K = 4 你可以做

wi_prior2 <- normal(location = c(0, 1, -2, 5))

您还可以传递比例向量和/或与normal. 然后,你会打电话stan_glmerprior = wi_prior2。如果你这样做

wi_prior2 <- normal(location = 0)

那么相同的先验将用于所有 K 个公共系数。

但是,在您的情况下,我怀疑这fmla是错误的。您通常还希望在 lme4 样式的括号表达式之外包含大多数(如果不是全部)这些预测变量,以允许在所有级别的franchID. 因此,fmla将成为

fmla <- attendance ~ W + W1 + W2 + W3 + DivWin1 + DivWin2 + DivWin3 + 
        WSWin1 + (1 + W + W1 + W2 + W3 + DivWin1 + DivWin2 + DivWin3 + 
                  WSWin1 | franchID)

如果您只包括括号中的部分,那么您假设这些变量的系数在总体中完全为零,并且仅在由 的水平定义的子总体中偏离零franchID。因此,没有机会将先验分布放在它们的系数上。

与公共系数的分组偏差的先验是条件多元正态,平均向量为零,协方差结构有些复杂但未知。这在 中进行了更详细的解释help(priors, package = "rstanarm")

于 2016-11-02T14:04:34.453 回答