The MAIHDA package provides tools for conducting Multilevel Analysis of Individual Heterogeneity and Discriminatory Accuracy (MAIHDA). This approach is particularly useful for examining intersectional inequalities in health and other outcomes by considering the joint effects of multiple social categories.
You can install the development version of MAIHDA from GitHub:
C:4rvUQ42d4754972d4.R
The typical MAIHDA workflow consists of the following steps:
First, we create intersectional strata from multiple social categories:
library(MAIHDA)
# Example dataset
data <- data.frame(
gender = sample(c("Male", "Female"), 1000, replace = TRUE),
race = sample(c("White", "Black", "Hispanic"), 1000, replace = TRUE),
age = rnorm(1000, 50, 10),
health_outcome = rnorm(1000, 100, 15)
)
# Create strata
strata_result <- make_strata(data, vars = c("gender", "race"))
# View stratum information
print(strata_result)C:4rvUQ42d4754972d4.R
Next, we fit a multilevel model using the created strata:
# Fit model with lme4 (default)
model <- fit_maihda(
health_outcome ~ age + (1 | stratum),
data = strata_result$data,
engine = "lme4"
)
# View model
print(model)C:4rvUQ42d4754972d4.R
The summary provides variance partition coefficients and stratum-specific estimates:
# Basic summary
summary_result <- summary_maihda(model)
print(summary_result)
# Summary with bootstrap confidence intervals
summary_boot <- summary_maihda(model, bootstrap = TRUE, n_boot = 500)
print(summary_boot)C:4rvUQ42d4754972d4.R
You can make predictions at both individual and stratum levels:
# Individual-level predictions
pred_ind <- predict_maihda(model, type = "individual")
# Stratum-level predictions
pred_strata <- predict_maihda(model, type = "strata")
head(pred_strata)C:4rvUQ42d4754972d4.R
The package provides several visualization options:
# Caterpillar plot of stratum random effects
plot_maihda(model, type = "caterpillar")
# Variance partition visualization
plot_maihda(model, type = "vpc")
# Observed vs. shrunken estimates
plot_maihda(model, type = "obs_vs_shrunken")C:4rvUQ42d4754972d4.R
You can compare multiple models with bootstrap confidence intervals:
# Fit multiple models
model1 <- fit_maihda(health_outcome ~ age + (1 | stratum),
data = strata_result$data)
model2 <- fit_maihda(health_outcome ~ age + gender + (1 | stratum),
data = strata_result$data)
# Compare models
comparison <- compare_maihda(
model1, model2,
model_names = c("Base Model", "With Gender"),
bootstrap = TRUE,
n_boot = 500
)
print(comparison)
# Plot comparison
plot_comparison(comparison)C:4rvUQ42d4754972d4.R
For Bayesian inference, you can use the brms engine (requires brms package):
# Fit model with brms
model_brms <- fit_maihda(
health_outcome ~ age + (1 | stratum),
data = strata_result$data,
engine = "brms",
chains = 2,
iter = 2000
)
# Summary works the same way
summary_brms <- summary_maihda(model_brms)C:4rvUQ42d4754972d4.R
The VPC indicates the proportion of variance in the outcome that is attributable to differences between strata (intersectional categories). A higher VPC suggests greater heterogeneity between strata.
The random effects represent deviations from the overall mean for each stratum, after adjusting for fixed effects. Positive values indicate higher outcomes in that stratum; negative values indicate lower outcomes.
Evans, C. R., Williams, D. R., Onnela, J. P., & Subramanian, S. V. (2018). A multilevel approach to modeling health inequalities at the intersection of multiple social identities. Social Science & Medicine, 203, 64-73.
Merlo, J. (2018). Multilevel analysis of individual heterogeneity and discriminatory accuracy (MAIHDA) within an intersectional framework. Social Science & Medicine, 203, 74-80.