Hey all,
I have a simple question about the formula notation for brms with random intercepts.
In the paper at http://138.232.16.156/article/view/v080i01 it is stated that “By default,
group-level coefficients within a grouping factor are assumed to be correlated. Correlations
can be set to zero by using the (coefs || group) syntax”.
The way I understand this is that correlation is being estimated between the random effects pertaining to the same factor. However, I see no difference when running the following R code, which fits a one-way random effects model with both the | and || notation, furthermore when I investigate the first model (correlated random effects), I cannot find the estimated correlations anywhere. Am I interpreting the quote above incorrectly? If not, is there a way to obtain the estimated correlation between the random effects?
rm(list = ls()) #remove all vars
library(brms)
library(pracma)
library(Matrix)
#---------------------------sample data------------------------------
set.seed(1234567)
nvec = 10 # number of independent vectors Y
m = 10
sigma2 = 1
tau = 2
# Y_ij = theta_i + epsilon_ij, theta_i ~ N(0,tau), epsilon_ij ~ N(0, sigma2)
Y = as.matrix(bdiag(lapply(seq(nvec), function(i){ones(m,1)}))%*%rnorm(nvec, 0, sqrt(tau)) + rnorm(nvec*m, 0, sqrt(sigma2)))
data = as.data.frame(cbind(Y, Reduce(rbind, lapply(seq(nvec), function(i){i*ones(m,1)}))))
colnames(data) = c("outcomes", "factor")
#----------------------------------fit brms --------------------------------------------
burnin = 5e3
M = 1e4
seed_brms = 123
fit_cor = brm(formula = 'outcomes ~ 0 + (1 | factor)',
data = data,
warmup = burnin,
iter = M,
chains = 1,
control = list(adapt_delta = 0.999),
seed = seed_brms)
summary(fit_cor)
fit_uncor = brm(formula = 'outcomes ~ 0 + (1 || factor)',
data = data,
warmup = burnin,
iter = M,
chains = 1,
control = list(adapt_delta = 0.999),
seed = seed_brms)
summary(fit_uncor)