Suppose $X$ is a continuous predictor that can vary between studies
and outcomes
in a 3-level linear mixed model like:
y ~ X + (1 | studies/outcomes)
How can I fit a model to distinguish between $X$'s between and within contributions across studies
and outcomes
?
PS:
In 2-level models (e.g., y ~ X + (1 | studies)
), we can do this by creating 2 variables out of $X$ within each level of studies
:
data %>% group_by(studies) %>% mutate(X_between = mean(X), X_within = X-X_between)
And use them as fixed effects:
y ~ X_between + X_within + (1 | studies)
X_ave_study
) and mean of X across outcomes ignoring studies (X_ave_outcome
). Option 2: Create mean of X across studies and mean of X across outcomes within studies (X_ave_outcome
). For both options, then, I will fit:y ~ X + X_ave_study + X_ave_outcome + (1 | studies/outcomes)
. . . $\endgroup$#-- Option 1: data %>% group_by(studies) %>% mutate(X_ave_study = mean(X)) %>% group_by(outcomes) %>% mutate(X_ave_outcome = mean(X)) #-- Option 2: data %>% group_by(studies) %>% mutate(X_ave_study = mean(X)) %>% group_by(outcomes, .add = TRUE) %>% mutate(X_ave_outcome = mean(X))
$\endgroup$