Learn R Programming

multilevelcoda (version 1.3.1)

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

Description

Fit a brm model with multilevel ILR coordinates

Usage

brmcoda(complr, formula, ...)

Value

A brmcoda with two elements

complr

An object of class complr used in the brm model.

model

An object of class brmsfit, which contains the posterior draws along with many other useful information about the model.

Arguments

complr

A complr object containing data of composition, ILR coordinates, and other variables used in the model.

formula

A object of class formula, brmsformula: A symbolic description of the model to be fitted. Details of the model specification can be found in brmsformula.

...

Further arguments passed to brm.

Examples

Run this code
# \donttest{
if(requireNamespace("cmdstanr")){
  cilr <- complr(data = mcompd, sbp = sbp,
                 parts = c("TST", "WAKE", "MVPA", "LPA", "SB"), idvar = "ID")
  
  # inspects ILRs before passing to brmcoda
  names(cilr$between_logratio)
  names(cilr$within_logratio)
  names(cilr$logratio)
  
  # model with compositional predictor at between and within-person levels
  m1 <- brmcoda(complr = cilr,
                formula = Stress ~ bilr1 + bilr2 + bilr3 + bilr4 +
                                   wilr1 + wilr2 + wilr3 + wilr4 + (1 | ID),
                chain = 1, iter = 500,
                backend = "cmdstanr")
  
  # model with compositional outcome
  m2 <- brmcoda(complr = cilr,
                formula = mvbind(ilr1, ilr2, ilr3, ilr4) ~ Stress + Female + (1 | ID),
                chain = 1, iter = 500,
                backend = "cmdstanr")
  }# }

Run the code above in your browser using DataLab