Hi everyone,

Dr. Andrew Heiss has a very nice blog post on **marginal effects** where he illustrates the concept of an **Average Marginal Effect** in the context of a linear model by showing this diagram:

(The blog post is available here: Marginalia: A guide to figuring out what the heck marginal effects, marginal slopes, average marginal effects, marginal effects at the mean, and all these other marginal things are | Andrew Heiss.

If we assume for simplicity the linear model is really simple:

Y_i = \beta_0 + \beta_1*X_{1i} + \beta_2*X_{2i} + e_i, i = 1, ..., n,

we could envision computing the marginal mean of the response variable Y at a given value of X_{1} (say, X_{1} = 5) in this way:

- Empty the X_{1} column of the data and then fill it in throughout with the value 5;
- Keep the X_{2} column of the data exactly as it is;
- Use the fitted linear model to compute the fitted values Y_i = b_0 + b_1*5 + b_2*X_{2i}, i = 1, ..., n (where the b's are the estimated values of the \beta's);
- Compute the average of the fitted values in item 3.

If we then repeat these 4 steps for X_1 = 5 + h, where h is a very small quantity, compute the difference between the marginal mean of Y when X_1 = 5 + h and the marginal mean of Y when X_1 = 5 and divide the result by h, we obtain the marginal effect of X_1 on (the mean of) Y when X_1 = 5.

Now imagine that we want to expand the concept of a marginal mean and marginal effect to a linear mixed effects model of the form:

Y_{ij} = \beta_0 + \beta_1*X_{1ij} + \beta_2*X_{2ij} + u_i + e_{ij}, i = 1, ..., n; j = 1, ..., m.

My first question is conceptual:

**Q1: How would we compute a marginal mean for the linear mixed effects model above? Could we use either a marginal mean in a “narrow” sense or a marginal mean in a “broad” sense? Or should we always use just a marginal mean in a “broad” sense?** (See below for explanation of “narrow” vs. “broad” terminology.)

I have not seen this articulated explicitly in the statistical literature, but I would guess that we could compute such a marginal mean in either a “narrow” sense or a “broad” sense.

This wording is borrowed from a SAS help file, which talks about “narrow” versus “broad” inference in a mixed effects model setting: SAS Help Center.

However, the SAS help file does not talk about marginal means or marginal effects explicitly.)

By extension, if my guess is correct, we could then compute marginal effects in either a “narrow” or a “broad” sense.

My working definition of what a marginal mean in a “narrow” sense represents in the above linear mixed effects model is that it is a mean response obtained by:

A) Emptying the X_1 column and then filling it with a value of interest (e.g., X_1 = 5);

B) Keeping the X_2 column as is;

C) Adding a third column u for the random intercept and filling it in with the predicted values of the random intercepts u_i included in the model;

D) Averaging across the fitted values b_0 + b_1*5 + b_2*X_{2ij} + u_i.

with the u_i in D) being predicted.

I don’t know if this working definition makes any sense conceptually? (Here, the intent is that we are “integrating out” with respect to the “empirical” distribution of the random effects.)

On the other hand, my working definition of what a marginal mean in a “broad” sense represents in the above linear mixed effects model would involve “integrating out” over the assumed distribution of the random effects (let’s say, a Normal distribution with mean 0 and variance \sigma_u^2).

I am not quite sure exactly what the “broad sense” definition would look like. Would we compute b_0 + b_1*2 + b_2*X2_ij + u for all X2_ij in the data, each time (that is, for every i,j combination) allowing u to be a different random realization from the assumed distribution of the random effects? Then average over all the fitted values we get?

**Q2: How does the brmsmargins package compute a marginal mean for a mixed effects model?**

I think that the **brmsmargins** package will compute a marginal mean in the “broad” sense? Is that correct?

**Q3: How does the marginaleffects package compute a marginal mean for a mixed effects model?**

I think that the **marginaleffects** package will compute a marginal mean in the “narrow” sense? Is that correct?

Maybe the answers are obvious to someone with a lot of experience in using these packages? Any insights would be much appreciated - I cannot find this information stated explicitly anywhere.

Many thanks.

Isabella