brms:如何在分类变量上设置优先级? [英] brms: how do I set prior on categorical variable?

查看:58
本文介绍了brms:如何在分类变量上设置优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用2个分类变量构建二项式回归模型.这来自《统计重新思考》一书中的一个例子.在这本书中,使用重新思考软件包时,我们可以为每个分类变量设置先验,如下所示

I am building a binomial regression model using 2 categorical variables. This is from an example in the book, Statistical rethinking. In the book, while using the rethinking package, we can set priors on each categorical variable as shown below

m11.5 <- ulam(
 alist(
   pulled_left ~ dbinom( 1 , p ) ,
   logit(p) <- a[actor] + b[treatment] ,
   a[actor] ~ dnorm( 0 , 1.5 ),
   b[treatment] ~ dnorm( 0 , 0.5 )
) ,
data=d , chains=4 , log_lik=TRUE )

我正试图在brms中做同样的事情.

I am trying to do the same in brms.


priors <- c(prior(normal(0, 1.5), class = b, coef = "actor"),
            prior(normal(0, 0.5), class = b, coef = "treatment"))

m11.5 <- brm(data = d, family = binomial,
          formula = pulled_left | trials(1) ~ 1 + actor + treatment,
          sample_prior = T, prior = priors,
          cores = 4, chains = 4)

我想为一次提到的所有演员级别和治疗级别设置先验.但是,上面的代码不会出现以下错误消息,

I would like to set priors for all of the actor levels and the treatment levels mentioned once. However the above code doesn't go through with the following error message,

使用get_prior时,我看到以下内容(暗示这些级别是在内部拆分的)

Upon using get_prior, I see the following (implying that the levels are internally split)

我不想为分类变量的每个级别指定先验.我该怎么做?请指教.

I donot want to specify the prior for the each level of the categorical variables. How do I do it? Please advice.

推荐答案

您可以粘贴并设置多个系数:

You can just paste and set multiple coefficients:

priors <- c(prior_string("normal(0, 1.5)", class = "b", coef = paste("actor", 2:7, sep="")),
            prior_string("normal(0, 0.5)", class = "b", coef = paste("treatment", 2:4, sep="")))

这篇关于brms:如何在分类变量上设置优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆