在混合效应模型(R brms)中定义随机效应和随机效应方差的先验

时间:2018-05-08 17:24:23

标签: r mixed-models random-effects rstan

我想要符合GLMM Poisson模型计数。我有121个科目(-print0),我观察到每个科目有8个泊松计数(find):它们对应于2种类型的事件(-exec sed -i '' ... {} +)x 4个句点(subject )。

count

我想要的是什么:

  • 我希望GLMM采用贝叶斯方法,假设(1)event,(2)period,(3)'data.frame': 968 obs. of 4 variables: $ count : num 4 0 2 3 3 0 1 0 8 14 ... $ subject: num 1 1 1 1 1 1 1 1 2 2 ... $ event : Factor w/ 2 levels "call","visit": 2 2 2 2 2 2 2 2 1 1 ... $ period : Factor w/ 4 levels "period_1","period_2",..: 1 2 3 4 1 2 3 4 1 2 ... 的随机效应。
  • 我想为所有固定效果设置N(0,10 ^ 6),
  • 我想设置N(0, sigma2_a ),N(0, sigma2_b ),N(0, sigma2_c )priors (1)subject,(2)subject:visit,(3)subject:event的随机效应
  • 我想分别为 sigma2_a sigma2_b sigma2_c 设置统一的先验。

我设法得到了什么:

  • 我相信我正在正确设置模型公式,我正在为固定效果参数设置所需的先验:

    subject

我挣扎的是:

  • 如何设置N(0, sigma2_a ),N(0, sigma2_b ),N(0, sigma2_c )先验为随机(1)subject:visit,(2)subject:event,(3)## define some priors prior <- c(prior_string("normal(0,10^3)", class = "b"), prior_string("normal(0,10^3)", class = "b", coef = "eventvisit"), prior_string("normal(0,10^3)", class = "b", coef = "eventvisit:periodperiod_2"), prior_string("normal(0,10^3)", class = "b", coef = "eventvisit:periodperiod_3"), prior_string("normal(0,10^3)", class = "b", coef = "eventvisit:periodperiod_4"), prior_string("normal(0,10^3)", class = "b", coef = "periodperiod_2"), prior_string("normal(0,10^3)", class = "b", coef = "periodperiod_3"), prior_string("normal(0,10^3)", class = "b", coef = "periodperiod_4")) ## fit model fit1 <- brm(count ~ event + period + event:period + (1|subject) + (0 + event|subject) + (0 + period|subject), data = data.long, family = poisson(), prior = prior, warmup = 1000, iter = 4000, chains = 4, cores = 7) 的效果
  • 如何分别为 sigma2_a sigma2_b sigma2_c 设置统一的先验。

1 个答案:

答案 0 :(得分:1)

关于您想要的内容:您能否请subject:visitsubject:event更详细地解释您想要的内容?目前,我无法确定您的模型是否正确指定用于您的目的。

关于先辈:

  1. 如果设置prior_string("normal(0,10^3)", class = "b"),则无需为每个系数再次指定先前的系数。为整个前一课程全局设置就足够了。请注意,给定响应和预测变量的比例,正常(0,1000)是如此之宽,以至于几乎没有影响。你也好好把它留下来。
  2. 为所有随机效果字词自动设置normal(0, sigma_x)个先验。无需担心它们。
  3. 您可以使用class = "sd"在随机效果SD上设置先验。例如prior_string("cauchy(0, 5)", class = "sd")。我明确地鼓励你特别使用统一的先验,因为它们有一个参数的硬上限(标准偏差),它没有理论上限。
相关问题