bml package hexagon logo

bml: Bayesian Multiple-Membership Multilevel Models with Parameterizable Weight Functions

R-CMD-check

bml is an R package for fitting Bayesian Multiple-Membership Multilevel Models with Parameterizable Weight Functions (“extended MMMM”) via JAGS. It supports a range of outcome types—including linear, logit, and survival models—and is designed for settings where researchers want to model how multiple units at a lower level jointly influence outcomes at a higher level.

In most multilevel analyses, the primary focus is on how higher-level contextual units (e.g., neighborhoods, schools, countries) shape outcomes observed at lower levels (e.g., individuals, students, governments), reflecting a macro-to-micro perspective. bml turns this logic around. Through an extended multiple-membership multilevel model, it allows researchers to explicitly model how the combined influence of many lower-level units propagates “upwards” to a higher-level outcome, enabling the study of micro-to-macro relationships.

Traditional approaches to micro-macro questions either:

Both strategies obscure the underlying aggregation process, ignore the statistical dependencies present in the data, and prevent the decomposition of variance across levels. In contrast, the extended MMMM implemented in bml explicitly models aggregation through a weight function that may itself depend on parameters and covariates. This approach provides a theoretically grounded and statistically principled framework for studying micro-macro relationships using regression models.

With the bml package, you can

Where can you use bml?

Multiple-membership structures are common across the social sciences and beyond. The model was developed for coalition government data, but the same structure appears in many other settings, such as:

In all these cases, bml provides tools to model dependence and interdependence: not just correcting standard errors for clustering, but explicitly representing how lower-level units combine to produce higher-level outcomes.

The following command fits an MMMM to coalition government data, modeling each coalition’s outcome as an equal-weighted combination of member parties’ organizational structure and random effects.

bml(
  Y ~ 1 +
    majority +
    mm(
      id = id(pid, gid),
      vars = vars(org_structure),
      fn = fn(w ~ 1 / n, c = TRUE),
      RE = TRUE
    ),
  family = "Gaussian",
  data = coalgov
) |>
  summary()

Parties (pid) can appear in multiple governments (gid), and the party-level covariate org_structure enters the model through the multiple-membership term mm(). The weights are set to w ~ 1 / n (equal weights across the n parties in a coalition), and party-specific random effects are included via RE = TRUE.

Learn more

Rosche, B. (2026). A Multilevel Model for Coalition Governments: Uncovering Party-Level Dependencies Within and Between Governments. Political Analysis, forthcoming. Preprint

Installation

Install the stable version from CRAN:

install.packages("bml")

See the installation vignette for detailed instructions including JAGS setup.

Developers

I welcome contributions to the package! Feel free to submit changes for review or contact me if you have any questions.

Issues or Feature Requests

If you would like to log an issue or submit a feature request, please create a new issue on GitHub Issues.

Changelog

See NEWS.md for the package changelog.

mirror server hosted at Truenetwork, Russian Federation.