Dear Stan community,
I am using the weight option in the brm
function to account for different variances in field sites in a negative binomial generalized linear mixed effect model. Using weights this way is to my understanding approximating the idea of the weighting function varIdent()
from the R package nlme
(as a reference may serve Galecki & Burzykowski 2013, pages 129-130, paragraph 7.3.2, page 135, paragraph 7.4.3). After considering the Stan code from the brm
model, I am still trying to make up my mind, how weights are used for the posteriors. The brm
code for weights in R looks as following:
b.mod <- brm(y|weights(w) ~ ...)
On the one hand, the Stan code from the brm
model shows that the posteriors are simply multiplied with weights:
vector[N] weights; \\ model weights
target += weights[n] * neg_binommial_2_log_lpmf(Y[n] | mu[n], shape);
On the other hand, other R packages seem to implement weights sometimes differently. For example, the gls()
function from the nlme
package appears to use internally multiplicative inverse of weights, while taking as an input and showing also in the summary output ârawâ weights. Again, the function lm()
also differs in the implementation of weights when compared to gls()
. So, the way of implementing weights in models can differ from R package to R package, which confused me as to how weights are implemented in the package brms
(better to say in Stan as brm
relies on Stan).
Does anybody know how brm()
uses weights? Does it use internally the multiplicative inverse, which would imply that the user needs to use the ârawâ form of weights (like the weight function in gls()
)? Or does the weights are not âtransformedâ, which is why the user should implement the multiplicative inverse a priori coding the model? Many thanks for time and response.
- Operating System: ArchLinux, Linux Kernel 4.16.8-1
- brms Version: 2.3.0