I am not sure if weights can be applied in multivariate models. The weights option works fine when I run univariate multilevel models. Hope you can help. Thank you very much.
My code:
brm.0 <- brm(
mvbind(stflife, happy) ~ 1 + (1|(cntry, weights = “anweight”)),
data = X, chains = 2, cores = 2, control = list(max_treedepth = 15))
Error: unexpected ‘,’ in:
“brm.0 <- brm(
mvbind(stflife, happy) ~ 1 + (1|(cntry,”
data = X, chains = 2, cores = 2, control = list(max_treedepth = 15))
Error: unexpected “,” in " data = X,"
I am not sure I understsand completely what you are trying to achieve - could you also share the univariate code you are trying to use?
My understanding is that weights are given on the left-hand side of the formula, i.e. y | weights ~ ... . Also note that you can always specify the model as a set of univariate formulas, because mvbind(A,B) ~ X is just a shorthand for bf(A ~ X) + bf(B ~ X).
Best of luck with your model!
P.S. Note that you can use triple backticks (```) to format code blocks in posts here on the forums :-)
You asked about the univariate code. I was following the example in the brms vignette. The weights option was on the right of the formula and I don’t know why. Thanks again!
# Multigroup membership
# simulate some data
dat <- data.frame(
y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100),
g1 = sample(1:10, 100, TRUE), g2 = sample(1:10, 100, TRUE)
)
# multi-membership model with two members per group and equal weights
fit4 <- brm(y ~ x1 + (1|mm(g1, g2)), data = dat)
summary(fit4)
# weight the first member two times for than the second member
dat$w1 <- rep(2, 100)
dat$w2 <- rep(1, 100)
fit5 <- brm(y ~ x1 + (1|mm(g1, g2, weights = cbind(w1, w2))), data = dat)
summary(fit5)
Oh I see where the confusion comes from: the weights in a multi-membership model (i.e. a model where a student can have multiple teachers where you want to treat the teacher effects as a varying intercept - the weights would let you express for example the number of classes with each teacher the student had) are a completely separate concept from weights in the likelihood - which basically let you put more importance on some data points. The weights in the multi-membership models are on the right-hand side as an argument to the mm function while weights for the likelihod are on the left-hand side as I suggested.
So not sure if you are trying to build a multi-membership model or using weights for your likelihood.
Thanks for this. I was trying to use weights in the likelihood. It’s the weight for a survey. Some groups need to have more weights than others because of different sample sizes in each group. It works fine now. Thanks again.