mlWAIC: WAIC for Multivariate Logistic Regression Models

View source: R/mlWAIC.R

mlWAICR Documentation

WAIC for Multivariate Logistic Regression Models

Description

Computes the widely applicable information criterion (WAIC) for multivariate logistic regression models. Serves as a wrapper for mlreg, mlpredict, djsdm, and waic for convenient WAIC calculations. Installation of the rstan package is required to use this function.

Usage

mlWAIC(
  Y,
  X,
  multivariate = TRUE,
  method = 2,
  priors = c(B.mu = 0, B.sd = 1, lkj = 1),
  iter = 20000,
  thin = 20,
  control = list(adapt_delta = 0.99, max_treedepth = 20, stepsize = 0.01),
  ...
)

Arguments

Y

Numeric response matrix. Each record represents an observation, and each field represents a response dimension. Matrix cells contain binary values (i.e., 0 or 1).

X

Numeric predictor matrix. Each record represents an observation, and each field represents a predictor variable. Matrix cells contain predictor values.

multivariate

Logical scalar. If TRUE (the default), then fits a multivariate logistic regression. If FALSE, then fits stacked univariate logistic regressions.

method

Numeric scalar. Options are 1 or 2, representing the alternative WAIC bias correction formulas (pWAIC1 and pWAIC2, respectively) described in Gelman et al. (2014). As recommended by Gelman et al. (2014), the default method (2) uses the pWAIC2 bias correction formula.

priors

Named numeric vector. Elements represent the prior values of their respective named parameters. When predictors are centered and scaled, the defaults generally represent weakly informative priors. Regression coefficients (B) receive normal priors (with standard normal as the default). The residual correlation matrix (R) receives an LKJ prior (with default shape parameter of 1).

iter

Numeric scalar. Integer value specifying the number of iterations for each chain (including warmup). The default is 20000. Passed to the iter argument of the rstan::sampling function.

thin

Numeric scalar. Integer value specifying the thinning interval. The default is 20. Passed to the thin argument of the rstan::sampling function.

control

Named list of parameters which control the behavior of the Stan sampler. Passed to the control argument of the rstan::sampling function.

...

Additional arguments passed to the rstan::sampling function.

Details

For convenience, wraps the steps involved in WAIC calculations for Bayesian multivariate logistic regression models. Begins by fitting a Bayesian multivariate logistic regression model with the mlreg function, then generates resubstitution posterior predictions using the mlpredict function. The pointwise log-likelihood is calculated with the djsdm function given the response matrix and posterior predictions. WAIC is calculated from the pointwise log-likelihood using the waic function. Because djsdm does not consider residual correlations in density calculations, species interactions do not contribute to WAIC (i.e., response dimensions are independent).

Value

Returns numeric scalar of the widely applicable information criterion.

References

Carpenter B, Gelman A, Hoffman MD, 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-32. DOI: 10.18637/jss.v076.i01

Gelman A, Hwang J, and Vehtari A. 2014. Understanding predictive information criteria for Bayesian models. Statistics and Computing, 24(6): 997-1016. DOI: 10.1007/s11222-013-9416-2

O'Brien SM, and Dunson DB. 2004. Bayesian multivariate logistic regression. Biometrics, 60: 739-746. DOI: 10.1111/j.0006-341X.2004.00224.x

Ovaskainen O, Hottola J, and Siitonen J. 2010. Modeling species co-occurrence by multivariate logistic regression generates new hypotheses on fungal interactions. Ecology, 91(9): 2514-2521. DOI: 10.1890/10-0173.1

Watanabe S. 2010. Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory. Journal of Machine Learning Research, 11(116): 3571-3594.

See Also

mlreg for fitting multivariate logistic regression models.

mlpredict for generating predictions from multivariate logistic regression models.

djsdm for probability mass function of a joint species distribution model.

waic for generic function to compute widely applicable information criterion.

Examples


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

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

# Compute WAIC for multivariate logistic regression.
out<-mlWAIC(Y=data$Y,X=data$X)


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