predict.brmcoda {multilevelcoda}R Documentation

Draws from the Posterior Predictive Distribution

Description

Compute posterior draws of the posterior predictive distribution of a brmsfit model in the brmcoda object. Can be performed for the data used to fit the model (posterior predictive checks) or for new data. By definition, these draws have higher variance than draws of the expected value of the posterior predictive distribution computed by fitted.brmcoda. This is because the residual error is incorporated in posterior_predict. However, the estimated means of both methods averaged across draws should be very similar.

Usage

## S3 method for class 'brmcoda'
predict(object, scale = c("linear", "response"), summary = TRUE, ...)

Arguments

object

An object of class brmcoda.

scale

Specifically for models with compositional responses, either "response" or "linear". If "linear", results are returned on the log-ratio scale. If "response", results are returned on the compositional scale of the response variable.

summary

Should summary statistics be returned instead of the raw values? Default is TRUE.

...

Further arguments passed to predict.brmsfit that control additional aspects of prediction.

Value

An array of predicted response values. If summary = FALSE the output resembles those of posterior_predict.brmsfit.

If summary = TRUE the output depends on the family: For categorical and ordinal families, the output is an N x C matrix, where N is the number of observations, C is the number of categories, and the values are predicted category probabilities. For all other families, the output is a N x E matrix where E = 2 + length(probs) is the number of summary statistics: The Estimate column contains point estimates (either mean or median depending on argument robust), while the Est.Error column contains uncertainty estimates (either standard deviation or median absolute deviation depending on argument robust). The remaining columns starting with Q contain quantile estimates as specified via argument probs.

See Also

predict.brmsfit

Examples


if(requireNamespace("cmdstanr")){
  ## fit a model
  cilr <- complr(data = mcompd, sbp = sbp,
                 parts = c("TST", "WAKE", "MVPA", "LPA", "SB"),
                 idvar = "ID", total = 1440)
  
  m1 <- brmcoda(complr = cilr,
                formula = Stress ~ bilr1 + bilr2 + bilr3 + bilr4 +
                  wilr1 + wilr2 + wilr3 + wilr4 + (1 | ID),
                chain = 1, iter = 500,
                backend = "cmdstanr")
  
  ## predicted responses
  pred <- predict(m1)
  head(pred)
  
  ## fit a model with compositional outcome
  m2 <- brmcoda(complr = cilr,
                formula = mvbind(ilr1, ilr2, ilr3, ilr4) ~ Stress + Female + (1 | ID),
                chain = 1, iter = 500,
                backend = "cmdstanr")
  
  ## predicted responses on compositional scale
  predcomp <- predict(m2, scale = "linear")
  head(predcomp)
}

[Package multilevelcoda version 1.3.0.2 Index]