Hi,
I’ve fit an intercept-only mixed effects model in rstanarm. Big thanks to @tjmahr for his example here:
The model is basically the same, except it’s intercept only.
library(lme4)
library(dplyr)
library(tibble)
sleepstudy <- sleepstudy %>%
as_tibble() %>%
mutate(Subject = as.character(Subject))
df_sleep <- bind_rows(
sleepstudy,
tibble(Reaction = c(286, 288), Days = 0:1, Subject = "374"),
tibble(Reaction = 245, Days = 0, Subject = "373"))
sleepb <- stan_glmer(
Reaction ~ 1 + (1 | Subject),
family = gaussian(),
data = df_sleep,
prior = normal(0, 2, autoscale = TRUE),
prior_intercept = normal(0, 5, autoscale = TRUE),
prior_covariance = decov(regularization = 2),
prior_aux = cauchy(0, 1, autoscale = TRUE),
# reproducible blogging
seed = 20211116
)
Output standard deviations with varcorr:
VarCorr(sleepb)
Groups Name Std.Dev.
Subject (Intercept) 36.793
Residual 44.350
But I want to dive into greater details using the posterior draws. In particular, I want to identify the contribution to the variance in each group from members.
sleepdraws <- as.matrix(sleepb)
apply(sleepdraws,2,sd)
But obviously, applying sd to each column from the posterior draws doesn’t get me there. What am I missing? How do I pull the information from the posterior draws to capture the variance in each group?
@betanalpha ?
@bgoodri ? your answers in this thread look along the same lines: