{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreibcwet26dq7stwfaq7l5fwbq4h32docszty3stigwicfaamwu6o6a",
"uri": "at://did:plc:wwyqal4cnqhuwyacdj7rqq3n/app.bsky.feed.post/3mj7eitnmchb2"
},
"path": "/t/rms-titanic-binary-logistic-case-study/4801#post_15",
"publishedAt": "2026-04-10T14:09:27.000Z",
"site": "https://discourse.datamethods.org",
"tags": [
"this",
"joshuawiley.com",
"Marginal Effects for Mixed Effects Models",
"marginaleffects"
],
"textContent": "Thanks. I found this thread which is helpful.\n\nI quote Joshua Wiley.\n\n> Averaging over fitted values incorporating random effects does not appropriately integrate over the random effects. Specifically, you do not get an estimate of the average marginal effect (AME) in the population that was sample from. You get an estimate **in the people sampled**.\n>\n> If the goal is an estimator of the AME in the population, the random effects need to be integrated out.\n> Averaging over `fitted()` estimates, whether or not random effects were used in these predictions, is not the same.\n\njoshuawiley.com\n\n### Marginal Effects for Mixed Effects Models\n\nThis implementation seems to use MC integration. I asked ChatGPT which proposed Gauss-Hermit quadrature to approximate this. After some initial testing the results, at least for a logit link with a random intercept only, are nearly identical to MC integration.\n\nThe marginaleffects package also seems to use MC integration, and would thus be suitable for any brms model (?), but very slow.\n\nSide note: If I use a hierarchical model for the analysis of a clinical trial, I would probably not care about this, because RCT (imo) are primarily about inference about the sample, not some hypothetical population.",
"title": "RMS Titanic Binary Logistic Case Study"
}