Including two matrices to describe the covariance structure of the group-level effects with brm()


Please also provide the following information in addition to your question:

  • Operating System: macOS Mojave v 10.14.2
  • brms Version: 2.8.0

Hello all,

I just wanted to ask about including two matrices to describe the covariance structure of the group-level effects using brm(). Essentially I have a model with a binary y variable and several predictors, and I want to account for both phylogenetic and spatial dependence. I used brm(), adding the two matrices in the cov_ranef argument. From what I understand, in the current implementation, the model assumes both these matrices have equal contribution - is this correct(?) or is it possible for the model to return the variance parameters associated with each matrix separately?

I am adapting this from the lmekin() function in coxme(), which unfortunately only deals with continuous response variables. But in there, the variance structure is fitted as V=s1A + s2B, where A and B are two matrices given as input, and the variances s1 and s2 are parameters that lmekin() is optimizing and returning.

Many thanks!

Example dummy code:
inv_logit <- function(x) 1 / (1 + exp(-x))
ability <- rnorm(100)
p <- 0.33 + 0.67 * inv_logit(ability)
answer <- ifelse(runif(100, 0, 1) < p, 1, 0)
dat_ir <- data.frame(ability, answer)

#create two covariance matrices
n <- 100
A <- matrix(runif(n^2)2-1, ncol=n)
Sigma <- t(A) %
% A
rownames(Sigma)<-colnames(Sigma)<- dat_ir$species

n <- 100
A <- matrix(runif(n^2)2-1, ncol=n)
Sigma2 <- t(A) %
% A
rownames(Sigma2)<-colnames(Sigma2)<- dat_ir$species

model <- brm( answer ~ ability + (1|species), data = dat_ir, family = bernoulli(), cov_ranef = list(species = Sigma, species=Sigma2))



Currently, brms does not support two matrices for the same grouping factor. I am not sure what brms does in this case, but I would think it just takes the first one (because I didn’t expect users to ever pass two matrices for the same grouping factor).

What would the behavior be that you hoped for? would it be the lmekin behavior?



Thank you for your reply!

Yes, essentially I was hoping brms would provide an alternative to lmekin(), as lmekin() cannot deal with binomial data. I am not interested really in the values for the two variances s1 and s2, but I would like to be able to account for two sources of dependence.



I see. I will think of a good way to implement this in brms. In the meantime, would you mind opening an issue on github so that I don’t forget about this feature?



Sure, will do. That would be fantastic, thank you!