When a multilevel model includes either a non-linear transformation (such as the log-transformation) of the response variable, or of the expectations via a GLM link-function, then the interpretation of the results will be different compared to a standard Gaussian multilevel model; specifically, the estimates will be on a transformed scale and not in the original units, and the effects will no longer refer to the average effect in the population, instead they are conditional/cluster-specific. In this post, I will deal with linear mixed-effects models (LMM) that use a log-transformed outcome variable. This will be the first part of a three-part tutorial on some of the finer details of (G)LMMs, and how Bayes can make your (frequentist) life easier. In each post I will focus on:
log-transformation of the dependent variable in a multilevel model
Calculating both multiplicative effects (% change) and differences on the untransformed scale.
Subject-specific/cluster-specific versus population-average effects (conditional versus marginal effects).
Intraclass correlations on the transformed/link/latent scale or on the response/data/original scale.
In part 2 I will cover a GLMM with a binary outcome, and part 3 will focus on semicontinuous (hurdle/two-part) models when the outcome is a skewed continuous variable that include zeros.
The aim of this post is also to show:
How simulation-based approaches like MCMC make it much easier to make inferences about transformed parameters.
How the estimates from a multilevel model can be transformed to answer the same questions as population-average models or fixed effects models. Data-generating model: a lognormal LMM
As an example, we will use a simple hierarchical design with clusters nested within either a treatment or a control condition. This is a classic 2-level multilevel model.
$$ \text{log}(y_{ij} \mid u_i) \sim \mathcal{N}(\beta_0 + \beta_1 TX_{i} + u_i, \sigma_e^2) $$
$$ u_i \sim \mathcal{N}(0, \sigma^2_u) $$
In this model, the natural logarithm of \(y\) is normally distributed conditional on the cluster-specific effect \(u_i\). Let's assume \(y\) is the average money (in USD) lost gambling per week (since I do research on gambling disorder). Gambling expenditure is sometimes quite well described by a lognormal distribution, or a (generalized) Gamma distribution. Importantly, the methods in this post can quite easily be tweaked to work with other response distributions. Each treatment arm has \(n_2\) clusters, and each cluster has \(n_1\) observations. In this example clusters refer to e.g. schools, centers, groups, and the first level are subjects. However, it would be easy to use the contents of this post for a longitudinal model where clusters refer to subjects, and the subjects have repeated observations.
Simulate data
Let's create a simple function that generates data from this model
#' Generate lognormal data with a random intercept
#'
#' @param n1 patients per cluster
#' @param n2 clusters per treatment
#' @param B0 log intercept
#' @param B1 log treatment effect
#' @param sd_log log sd
#' @param u0 SD of log intercepts (random intercept)
#'
#' @return a data.frame
gen_data % select(-B0, -B1, -u0, -sigma)
tab % gather(key, val) %__% mutate(key = factor(key, levels = unique(key))) %__% group_by(key) %__% do( data.frame(posterior_median = median(.$val), l_95_CI = quantile(.$val, 0.025), u_95_CI = quantile(.$val, 0.975),
stringsAsFactors = FALSE)) %__% ungroup() %__% mutate(key = c(&quot;$\\text{E}(Y_{ij} \\mid u_i = 0, \\text{TX} = 0)$&quot;,
&quot;$\\text{E}(Y_{ij} \\mid u_i = 0, \\text{TX} = 1)$&quot;,
&quot;$\\text{E}(Y_{ij} \\mid \\text{TX} = 0)$&quot;,
&quot;$\\text{E}(Y_{ij} \\mid \\text{TX} = 1)$&quot;,
&quot;$\\text{E}(Y_{ij} \\mid u_i = 0, \\text{TX} = 1) - \\\\ \\text{E}(Y_{ij} \\mid u_i = 0, \\text{TX} = 0)$&quot;,
&quot;$\\text{E}(Y_{ij} \\mid \\text{TX} = 1) - \\\\ \\text{E}(Y_{ij} \\mid \\text{TX} = 0)$&quot;,
&quot;$\\frac{\\text{E}(Y_{ij} \\mid u_i = 0, \\text{TX} = 1)}{\\text{E}(Y_{ij} \\mid u_i = 0, \\text{TX} = 0)}$&quot;,
&quot;$\\frac{\\text{E}(Y_{ij} \\mid \\text{TX} = 1)}{\\text{E}(Y_{ij} \\mid \\text{TX} = 0)}$&quot;,
&quot;$\\text{exp}(\\beta_1)$&quot;),
Effect = c(&quot;Average outcome for a median cluster in the control group&quot;,
&quot;Average outcome for a median cluster in the treatment group&quot;,
&quot;Average outcome in the control group&quot;,
&quot;Average outcome in the treatment group&quot;,
&quot;Difference between the average outcome in a median cluster in the treatment versus control group&quot;,
&quot;Difference between the average outcome in the treatment versus control group&quot;,
&quot;Ratio of the average outcome in a median cluster in the treatment and the control group&quot;,
&quot;Ratio of the average outcome in the treatment and the control group&quot;,
&quot;Ratio of the average outcome in the treatment and the control group&quot;)) %__% select(Effect, Formula = key, posterior_median, l_95_CI, u_95_CI)
Effect
Formula
posterior_median
l_95_CI
u_95_CI
Average outcome for a median cluster in the control group
\(\text{E}(Y_{ij} \mid u_i = 0, \text{TX} = 0)\)
570.5
374.5
847.9
Average outcome for a median cluster in the treatment group
\(\text{E}(Y_{ij} \mid u_i = 0, \text{TX} = 1)\)
281.8
186.7
435.2
Average outcome in the control group
\(\text{E}(Y_{ij} \mid \text{TX} = 0)\)
697.9
454.5
1123.4
Average outcome in the treatment group
\(\text{E}(Y_{ij} \mid \text{TX} = 1)\)
342.7
231.3
575.5
Difference between the average outcome in a median cluster in the treatment versus control group
\(\text{E}(Y_{ij} \mid u_i = 0, \text{TX} = 1) - \\ \text{E}(Y_{ij} \mid u_i = 0, \text{TX} = 0)\)
-286.1
-580.2
-37.9
Difference between the average outcome in the treatment versus control group
\(\text{E}(Y_{ij} \mid \text{TX} = 1) - \\ \text{E}(Y_{ij} \mid \text{TX} = 0)\)
-349.0
-747.5
-47.4
Ratio of the average outcome in a median cluster in the treatment and the control group
\(\frac{\text{E}(Y_{ij} \mid u_i = 0, \text{TX} = 1)}{\text{E}(Y_{ij} \mid u_i = 0, \text{TX} = 0)}\)
0.5
0.3
0.9
Ratio of the average outcome in the treatment and the control group
\(\frac{\text{E}(Y_{ij} \mid \text{TX} = 1)}{\text{E}(Y_{ij} \mid \text{TX} = 0)}\)
0.5
0.3
0.9
Ratio of the average outcome in the treatment and the control group
\(\text{exp}(\beta_1)\)
0.5
0.3
0.9
Using brms::fitted
Let's compare our results to predicted means we get with brms::fitted and brms::marginal_effects
## Estimate Est.Error Q2.5 Q97.5
## [1,] 570.5069 114.8815 374.4601 847.8781
## TX y cluster cond__ estimate__ se__ lower__ upper__
## 1 0 481.4254 NA 1 570.5069 114.8815 374.4601 847.8781
We see that this is exactly the same as the median outcome (cluster-specific outcome) in the control group. I've seen some people confused about this since the function is called marginal_effects. Limiting inference to only the included clusters
We can also use fitted to average over the included clusters, this is very similar to fitting the clusters as &quot;fixed effects&quot;. So let's compare averaging over the included clusters in the multilevel model to fitting a fixed effects (no pooling) model. fit_fixed