wsub: Within-person Simple Substitution

View source: R/substitution-wsub.R

wsubR Documentation

Within-person Simple Substitution

Description

This function is an alias of substitution to estimates the the difference in an outcome when compositional parts are substituted for specific unit(s) at within level using a single reference composition (e.g., compositional mean at sample level). It is recommended that users run substitution model using the substitution function.

Usage

wsub(
  object,
  basesub,
  delta,
  summary = TRUE,
  ref = "grandmean",
  level = "within",
  weight = "equal",
  cores = getOption("mc.cores", 1),
  ...
)

Arguments

object

A fitted brmcoda object.

basesub

A data.frame or data.table of the base possible substitution of compositional parts. This data set can be computed using function basesub. If NULL, all possible pairwise substitution of compositional parts are used.

delta

A integer, numeric value or vector indicating the amount of substituted change between compositional parts.

summary

A logical value. Should the estimate at each level of the reference grid (FALSE) or their average (TRUE) be returned? Default is TRUE. Only applicable for model with covariates in addition to the isometric log-ratio coordinates (i.e., adjusted model).

ref

Either a character value or vector or a dataset. Can be "grandmean" and/or "clustermean", or a data.frame or data.table of user's specified reference grid consisting of combinations of covariates over which predictions are made. User's specified reference grid is only possible for simple substitution. Single level models are default to "grandmean".

level

A character string or vector. Should the estimate of multilevel models focus on the "between" and/or "within" or "combined" variance? Single-level models are default to "combined".

weight

A character value specifying the weight to use in calculation of the reference composition. If "equal", give equal weight to units (e.g., individuals). If "proportional", weights in proportion to the frequencies of units being averaged (e.g., observations across individuals). Default to "equal" for ref = "grandmean" and "proportional" for ref = "clustermean".

cores

Number of cores to use when executing the chains in parallel, which defaults to 1 but we recommend setting the mc.cores option to be as many processors as the hardware and RAM allow (up to the number of compositional parts). For non-Windows OS in non-interactive R sessions, forking is used instead of PSOCK clusters.

...

Additional arguments passed to describe_posterior.

Value

A list containing the results of multilevel compositional substitution model. The first six lists contain the results of the substitution estimation for a compositional part.

Mean

Posterior means.

CI_low and CI_high

95% credible intervals.

Delta

Amount substituted across compositional parts.

From

Compositional part that is substituted from.

To

Compositional parts that is substituted to.

Level

Level where changes in composition takes place.

Reference

Either grandmean, clustermean, or users.

See Also

substitution

Examples


if(requireNamespace("cmdstanr")){

cilr <- complr(data = mcompd, sbp = sbp, 
               parts = c("TST", "WAKE", "MVPA", "LPA", "SB"), idvar = "ID", total = 1440)

# model with compositional predictor at between and within-person levels
m <- brmcoda(complr = cilr, 
             formula = Stress ~ bilr1 + bilr2 + bilr3 + bilr4 + 
                                wilr1 + wilr2 + wilr3 + wilr4 + (1 | ID), 
             chain = 1, iter = 500,
             backend = "cmdstanr")
             
subm <- wsub(object = m, basesub = psub, delta = 600)
}

florale/multilevelcoda documentation built on April 16, 2024, 1:21 a.m.