I use a mixed model to separate the variance of some measurement into between- and within group variance. The model looks like this:
library(lme4)
k <- 100
i <- 5
group_mean <- rnorm(k, 0, 1)
y <- rnorm(k*i, rep(group_mean, each = i), 0.5)
df <- data.frame(y, group = rep(1:k, each = i))
m <- lmer(y ~ (1|group), data = df)
I can extract between- and within group SD and confidence intervals:
VarCorr(m)
#> Groups Name Std.Dev.
#> group (Intercept) 0.99958
#> Residual 0.50327
confint(m, oldNames = FALSE)
#> Computing profile confidence intervals ...
#> 2.5 % 97.5 %
#> sd_(Intercept)|group 0.8640826 1.15724604
#> sigma 0.4703110 0.54026452
#> (Intercept) -0.3782316 0.02526364
How can I get confidence intervals for the sum of the variances (sd_(Intercept)|group^2 + sigma^2
)? I.e. the estimated variance in y
with only one observation per group
.