Suppose I have a data set with three variables: $y$, an outcome I want to understand, $x$, a variable which covaries with $x$ but we can assume to be measured perfectly, and $g$, a grouping variable that indentifies one of several clusters (e.g. subjects) a measurement is from. I fit the data with a multilevel (hierarchical) regression model of the form $$y_i = (\beta_0 + b_{0,g[i]}) + (\beta_1 + b_{1, g[i]})x_i + \varepsilon_i$$ where $i = 1, \ldots, n$ indexes observations in my dataset and $g[i]$ is the value of the variable $g$ for observation $i$.
In lme4 notation this model would be y ~ 1 + x + (1 + x | g), allowing every cluster to have its own slope and intercept, while also computing an overall slope and intercept.
The question I want to answer with this model is which is more important for explaining the outcome variable: the effect of $x$ or the between-cluster variability?
I think a practical way to answer this question might be to partition the variance (it is ok to assume the error distribution is Normal if that matters), but I don't really know how to do this. I know that if I fit a non-hierarchical model, i.e., y ~ 1 + x, the variance can be partitioned into what is explained by the regression and what isn't.
I also know that when I fit the model y ~ 1 + x + (1 + x | g), I estimate a variance component explained by the random effects grouped by g. From this model, is it possible to decompose the variance into the portion explained by the fixed effects, the portion explained by the random effects, and the residual variability? If so, how do I do that?
Is there a better way to answer this question? I think partitioning the explained variance is an intuitive way to say one variable is "more important" than another, but if there's a better metric for this, that is also ok.
For a concrete example, I simulated a dataset in R that follows this model, and all of the model parameters are estimable.
set.seed(101) n_subjects <- 20 x_values_per_subject <- c(0.1, 0.25, 0.5, 0.75) x <- rep(x_values_per_subject, times = n_subjects) g <- rep(1:n_subjects, each = length(x_values_per_subject)) global_b0 <- 5 individual_b0 <- rnorm(n_subjects, global_b0, 5) global_b1 <- -2 individual_b1 <- rnorm(n_subjects, global_b1, 3) residual_variance <- 1 mu <- global_b0 + individual_b0[g] + (global_b1 + individual_b1[g]) * x error_variate <- rnorm(length(mu), 0, residual_variance) y <- mu + error_variate observed_data <- data.frame(x, g, y) Additionally, here's some simple code to visualize the group-level trajectories.
plot( NULL, NULL, xlim = range(x_values_per_subject), ylim = range(observed_data$y), xlab = "x", ylab = "y" ) for (i in unique(observed_data$g)) { this_g <- subset(observed_data, g == i) lines(this_g$x, this_g$y, type = "b") } And fitting both models is easy.
library(lme4) simple_model <- lm(y ~ 1 + x, data = observed_data) multilevel_model <- lme4::lmer(y ~ 1 + x + (1 + x | g), data = observed_data, REML = FALSE) When I compared the models, I saw that both models estimate the same values for point estimates of the fixed effects, although the standard error of the fixed effect of x is much smaller now that we've accounted for the extra variation by clusters. If we use ANOVA or AIC to compare the models, the multilevel model is clearly much better.
summary(simple_model) summary(multilevel_model) anova(multilevel_model, simple_model) So given these two models, how do I determine if the fixed effect of x is more important than the between-cluster variability?
gas a fixed effect because I want to generalize the results to new clusters. Comparing the models with and without random effects has a few problems but should work. The main problem is that I was really hoping for a quantitative measure, and the p-value for such a test is A) conservative and B) scales with sample size, so doesn't really provide useful quantitative information. I've found some approaches based on prediction variance and variance decomposition and I plan to answer my own question when I have time. $\endgroup$REMLnotMLand thatgls()is better thanlm()in this case. $\endgroup$