Learn R Programming

multilevelcoda

Overview

This package provides functions to model compositional data in a multilevel framework using full Bayesian inference. It integrates the principes of Compositional Data Analysis (CoDA) and Multilevel Modelling and supports both compositional data as an outcome and predictors in a wide range of generalized (non-)linear multivariate multilevel models.

Installation

To install the latest release version from CRAN, run

install.packages("multilevelcoda")

The current developmental version can be downloaded from github via

if (!requireNamespace("remotes")) {
  install.packages("remotes")
}
remotes::install_github("florale/multilevelcoda")

Because multilevelcoda is built on brms, which is based on Stan, a C++ compiler is required. The program Rtools (available on https://cran.r-project.org/bin/windows/Rtools/) comes with a C++ compiler for Windows. On Mac, Xcode is required. For further instructions on how to get the compilers running, see the prerequisites section on https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started.

Resources

You can learn about the package from these vignettes:

Citing multilevelcoda and related software

When using multilevelcoda, please cite one or more of the following publications:

  • Le, F., Stanford, T. E., Dumuid, D., & Wiley, J. F. (2025). Bayesian multilevel compositional data analysis: introduction, evaluation, and application. Psychological Methods. https://doi.org/10.1037/met0000750
  • Le F., Dumuid D., Stanford T. E., Wiley J. F. (2025). Bayesian multilevel compositional data analysis with the R package multilevelcoda. Multivariate Behavioral Research. https://doi.org/10.1080/00273171.2025.2565598

As multilevelcoda depends on brms and Stan, please also consider citing:

  • Bürkner P. C. (2017). brms: An R Package for Bayesian Multilevel Models using Stan. Journal of Statistical Software. 80(1), 1-28. doi.org/10.18637/jss.v080.i01
  • Bürkner P. C. (2018). Advanced Bayesian Multilevel Modeling with the R Package brms. The R Journal. 10(1), 395-411. doi.org/10.32614/RJ-2018-017
  • Bürkner P. C. (2021). Bayesian Item Response Modeling in R with brms and Stan. Journal of Statistical Software, 100(5), 1-54. doi.org/10.18637/jss.v100.i05
  • Stan Development Team. YEAR. Stan Modeling Language Users Guide and Reference Manual, VERSION. https://mc-stan.org
  • Carpenter B., Gelman A., Hoffman M. D., Lee D., Goodrich B., Betancourt M., Brubaker M., Guo J., Li P., and Riddell A. (2017). Stan: A probabilistic programming language. Journal of Statistical Software. 76(1). doi.org/10.18637/jss.v076.i01

Copy Link

Version

Install

install.packages('multilevelcoda')

Monthly Downloads

364

Version

1.3.3

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Flora Le

Last Published

November 11th, 2025

Functions in multilevelcoda (1.3.3)

multilevelcoda_sim

multilevelcoda Simulation Study Results
mcmc_plot.brmcoda

MCMC Plots Implemented in bayesplot
mcompd

Multilevel Compositional Data
nobs.brmcoda

Extract Number of Observations from brmcoda object
is.substitution

Checks if argument is a substitution object
predict.brmcoda

Draws from the Posterior Predictive Distribution
model.frame.brmcoda

Extracting the Model Frame from a Formula or Fit from brmcoda object
pp_check.brmcoda

Posterior Predictive Checks for brmcoda Objects
pivot_coord

Estimate pivot balance coordinates
pivot_coord_refit

Estimate pivot balance coordinates by refitting model.
print.brmcoda

Print a Summary for a fitted brmsfit model in a brmcoda object
plot.substitution

Substitution Plot
plot.brmcoda

Trace and Density Plots for MCMC Draws plot
print.complr

Print a Summary for a complr object
pairs.brmcoda

Create a matrix of output plots from a brmcoda's brmsfit object
loo.brmcoda

Efficient approximate leave-one-out cross-validation (LOO)
pivot_coord_rotate

Estimate pivot balance coordinates by rotating sequential binary partition.
submargin

Average Substitution
substitution

Multilevel Compositional Substitution Analysis
sim

multilevelcoda Simulation Study results
sub

Simple Substitution
ranef.brmcoda

Group-Level Estimates
prior_summary.brmcoda

Extract Priors of a brmsfit from a brmcoda object
residuals.brmcoda

Posterior Draws of Residuals/Predictive Errors
print.substitution

Print a Summary for a substitution object
psub

Possible Pairwise Substitutions
sbp

Sequential Binary Partition
var.complr

Variance of compositions presented in a complr object.
summary.complr

Create a Summary of a complr object
update.brmcoda

Update brmcoda models
wsub

Within-person Simple Substitution
summary.pivot_coord

Create a Summary of a fitted brmsfit model from a pivot_coord object
wsubmargin

Within-person Average Substitution
summary.brmcoda

Create a Summary of a fitted brmsfit model in a brmcoda object
summary.substitution

Create a Summary of a Substitution Model represented by a substitution object
vcov.brmcoda

Covariance and Correlation Matrix of Population-Level Effects
VarCorr.brmcoda

Extract Variance and Correlation Components
coef.brmcoda

Model Coefficients
as.data.frame.complr

Extract amounts and compositions in conventional formats as data.frames, matrices, or arrays.
bsub

Between-person Simple Substitution
build.sbp

Build Sequential Binary Partition
build.rg

Reference Grid for substitution model.
build.base

Build Base Pairwise Substitution
bayes_factor.brmcoda

Bayes Factors from Marginal Likelihoods
brmcoda

Fit Bayesian generalised (non-)linear multilevel compositional model via full Bayesian inference
bsubmargin

Between-person Average Substitution
fixef.brmcoda

Population-Level Estimates
is.brmcoda

Checks if argument is a brmcoda object
fitted.brmcoda

Expected Values of the Posterior Predictive Distribution
get-substitution

Substitution analysis helper functions
get_sbp

Extract Sequential Binary Partition from a complr object.
compilr

Indices from a (dataset of) Multilevel Composition(s) (deprecated.)
get_variables

Extract variable names from an object
diagnostic-quantities-brmcoda

Extract Diagnostic Quantities from brmsfit Models in brmcoda
complr

Indices from a (dataset of) Multilevel Composition(s)
draws-index-brmcoda

Index brmcoda objects
is.complr

Checks if argument is a complr object
mean.complr

Mean amounts and mean compositions presented in a complr object.
launch_shinystan.brmcoda

Interface to shinystan