Package: bml 0.12.0

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

Implements Bayesian multiple-membership multilevel models with parameterizable weight functions via 'JAGS' to model how lower-level units jointly shape higher-level outcomes (micro-macro link) across a range of outcome types (e.g., linear, logit, and survival models). Supports estimation and comparison of alternative aggregation mechanisms, allows weight matrices to be endogenized through parameters and covariates, and accommodates complex dependence structures that extend beyond traditional multilevel frameworks. For details, see Rosche (2026) "A Multilevel Model for Coalition Governments. Uncovering Party-Level Dependencies Within and Between Governments" <doi:10.31235/osf.io/4bafr_v2>.

Authors:Benjamin Rosche [aut, cre]

bml_0.12.0.tar.gz
bml_0.12.0.zip(r-4.7-any)bml_0.12.0.zip(r-4.6-any)bml_0.12.0.zip(r-4.5-any)
bml_0.12.0.tgz(r-4.6-any)bml_0.12.0.tgz(r-4.5-any)
bml_0.12.0.tar.gz(r-4.7-any)bml_0.12.0.tar.gz(r-4.6-any)
bml_0.12.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html✨
DESCRIPTION |NEWS
card.svg |card.png
bml/json (API)

# Install 'bml' in R:
install.packages('bml', repos = c('https://benrosche.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/benrosche/bml/issues

Pkgdown/docs site:https://benrosche.github.io

Uses libs:
  • jags– Just Another Gibbs Sampler for Bayesian MCMC
  • c++– GNU Standard C++ Library v3
Datasets:
  • coalgov - Coalition Governments in Western Democracies

On CRAN:

Conda:

jagscpp

6.29 score 6 stars 7 scripts 243 downloads 40 exports 61 dependencies

Last updated from:b5ef5d571b. Checks:7 NOTE, 2 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-develNOTE156
source / vignettesOK252
linux-releaseNOTE152
macos-releaseNOTE214
macos-oldrelNOTE189
windows-develNOTE119
windows-releaseNOTE120
windows-oldrelNOTE121
wasm-releaseOK137

Exports:as_drawsas_draws_arrayas_draws_dfas_draws_matrixbernoullibmlbml_deltabml_reallocbml_turnoverbmlComparecoefPlotconditional_effectscoxestfefixfixeffnget_priorglancehmidlog_likloomake_jagscodemake_jagsdatamcmcDiagmmmonetPlotposterior_predictpp_checkpriorranefretidyvarDecompvarswwaicweibull

Dependencies:abindbackportsbitbit64bootcheckmateclicliprcodacpp11crayondistributionaldplyrfarverforcatsgenericsGGallyggmcmcggplot2ggstatsgluegtablehmsisobandlabelinglatticelifecycleloomagrittrMASSmatrixStatsnlmenumDerivpatchworkpillarpkgconfigposteriorprettyunitsprogresspurrrR2jagsR2WinBUGSR6RColorBrewerreadrrjagsrlangS7scalesstringistringrtensorAtibbletidyrtidyselecttzdbutf8vctrsviridisLitevroomwithr

Frequently Asked Questions
1. What's the difference between a multiple-membership model and a conventional multilevel model? | 2. What's the difference between a conventional MMMM and the extended MMMM implemented in bml? | 3. When should I use bml instead of other multilevel modeling packages? | 4. What outcome types and distributions does bml support? | 5. How do I specify the weights, and what are the scale and ar options? | 6. How do I fix parameters to known values? | Main equation and hm() blocks: Using fix() | Weights w(): Omitting parameters | 7. I get "Error in node w.1[...]: Invalid parent values" — what does this mean? | 8. I'm coming from brms — what maps onto what?

Last update: 2026-08-04
Started: 2021-05-02

Installation
1. Install JAGS | 2. Install bml R package | Option A: Install from CRAN | Option B: Install development version from GitHub | Troubleshooting

Last update: 2026-07-29
Started: 2021-05-02

Model Structure
1. Overview | 2. Running Example | 3. Notation and Data Structure | 4. The Extended Multiple-Membership Multilevel Model | 4.1 Full Model Specification | 4.2 Group-Level Effect | 4.3 Hierarchical Nesting-Level Effect | 4.4 Aggregated Member-Level Effect | 5. Parameterizable Weight Functions | 5.1 Conventional MMMM: Fixed Weights | 5.2 Extended MMMM: Parameterizing Weights | 5.3 Testing Alternative Aggregation Mechanisms | 6. Emergent Aggregation Functions | 6.1 User-written reductions: the expression DSL | 6.2 Named blocks and interactions | 7. Generalized Outcomes | 8. Variance Decomposition and Intraclass Correlation | 8.1 Intraclass Correlation Coefficients (ICC) | 9. Extensions | 9.1 Multiple MM Blocks | 9.2 Autoregressive Random Effects | 9.3 Complementary Membership Groups | 10. Comparison with Conventional MMMM | 11. Model Assumptions | 12. Estimation | 13. Further Information

Last update: 2026-07-29
Started: 2021-05-02

Examples
1. All friends, or just your best friend? (network regression) | Model 1: linear-in-means | Model 2: best friend only | Comparing the two models | Cross-validation: which aggregation does the data prefer? | 2. Air quality and home values (spatial regression) | Data and spatial weights | Baseline bml: equal weights | Parameterised weights: similarity across covariates | Do the weights actually vary with similarity? | Benchmark: spatial Durbin error model | Model comparison | 3. Political parties and the survival of coalition governments (micro-macro regression) | The data | Equal-weight baseline | Letting weights vary across parties | Prime minister's party against equal weights | Prime minister against seat share | Comparing the models | MCMC diagnostics | brms-style accessors | 4. Does the average matter, or the spread? (emergent features) | 5. What is the aggregation function? (estimating f itself) | 6. Does context change the aggregate's effect? (cross-level interaction) | 7. Heterogeneous member effects (explained and residual)

Last update: 2026-07-13
Started: 2021-05-02

Getting Started with bml
Introduction | Installation | Basic Example | Understanding the Data Structure | Model 1: Basic Multiple-Membership Model | Model 2: Parameterizing the Weight Function | Model 3: Beyond the sum — emergent features | Visualizing Results | Next Steps | Key Concepts

Last update: 2026-07-13
Started: 2025-10-24

Readme and manuals

Help Manual

Help pageTopics
Extract posterior draws from a bml modelas_draws.bml as_draws_array.bml as_draws_df.bml as_draws_matrix.bml
Bayesian Multilevel Models for Micro-Macro Analysis (Multiple Membership) Using JAGSbml
Temporal composition change: matched decomposition of a feature differencebml_delta
Reallocation of membership weights toward high-attribute membersbml_realloc
Membership turnover between two snapshotsbml_turnover
Model families for bmlbernoulli bml-families cox weibull
Compare fitted bml models in a publication-style tablebmlCompare
Coalition Governments in Western Democracies (1944-2014)coalgov
Extract combined coefficients from a bml modelcoef.bml
Coefficient plot for fitted bml modelscoefPlot
Conditional effects of main-formula predictorsconditional_effects conditional_effects.bml
Mark a shape parameter as estimatedest
Fixed effects: no poolingfe
Posterior expectations of the linear predictorfitted.bml
Fix a coefficient to a known valuefix
Extract fixed coefficients from a bml modelfixef.bml
The aggregation function of an mm() blockfn
List every settable prior of a bml modelget_prior
Glance at a fitted bml modelglance.bml
Define a hierarchical nesting structurehm
Specify identifier variables for multiple-membership and hierarchical structuresid
Pointwise log-likelihood of a bml modellog_lik log_lik.bml
Efficient approximate leave-one-out cross-validation for bml modelsloo.bml
Generate the JAGS model code / data without fittingmake_jagscode make_jagsdata
Summarize MCMC convergence diagnosticsmcmcDiag
Define a multiple-membership block (the micro-to-macro aggregation)mm
Visualize posterior distributions with density and trace plotsmonetPlot
Draws from the posterior predictive distributionposterior_predict posterior_predict.bml
Posterior predictive checks for bml modelspp_check pp_check.bml
Predictions from a bml modelpredict.bml
Structured prior specificationsprior
Extract random effects from a bml modelranef.bml
Random effects: partial poolingre
Summarize a fitted bml modelsummary.bml
Tidy a fitted bml modeltidy.bml
Variance decomposition for fitted bml modelsvarDecomp
Specify member-level attributes for mm() blocksvars
Specify the membership weights of an mm() blockw
Widely applicable information criterion for bml modelswaic.bml