dmpredict: Predictions for Dirichlet-Multinomial Regression Models

View source: R/dmpredict.R

dmpredictR Documentation

Predictions for Dirichlet-Multinomial Regression Models

Description

Generate predictions for Dirichlet-multinomial regression models.

Usage

dmpredict(X, H, fit, names)

Arguments

X

Numeric predictor matrix. Predictions are made for each record. Each field represents a predictor variable, and the predictor variables must match (in order) those used to fit the dmreg model. Matrix cells contain predictor values. Element names in the returned list are taken from the row names of X.

H

Numeric vector or matrix (optional). If provided, then hierarchical effects are included in the predictions. Vector or matrix elements contain integer identifiers for values of hierarchical variables. If vector, then a single hierarchical variable is included, with each element corresponding to a record in X. If matrix, then each record in H corresponds to a record in X. Each field in H represents a hierarchical variable, and the hierarchical variables must match (in order) those used to fit the dmreg model. If H is omitted, then hierarchical effects are omitted from the predictions (but may still have been used to fit the model).

fit

A stanfit object returned from the dmreg function. The fitted Dirichlet-multinomial regression model.

names

Vector (optional). If provided, then field names in the matrices of the returned list will receive these values. If omitted, then the matrices in the returned list will lack field names.

Details

Generates posterior predictions for Dirichlet-multinomial regression models fit with the dmreg function. Predictions can either include or omit hierarchical effects, depending on whether argument H is provided. Returns a list where each element contains a matrix of posterior predictions for the respective record of X. Field names for the element matrices can optionally be provided with the names argument.

Value

A list whose elements contain numeric matrices of posterior predictions. Within the list, one element is returned for each record of X. Element names are taken from the row names of X.

See Also

dmreg for fitting Dirichlet-multinomial regression models.

dmWAIC for computing widely applicable information criteria for Dirichlet-multinomial regression models.

Examples

# Define example data file path.
path<-system.file("extdata",
                  "example_regression_data.rds",
                  package="LocaTT",
                  mustWork=TRUE)

# Read in example regression data.
data<-readRDS(file=path)

# Predict with fitted Dirichlet-multinomial regression.
out<-dmpredict(X=data$X,fit=data$fit,names=colnames(data$Y))

LocaTT documentation built on June 14, 2026, 1:06 a.m.