R/extractDIC.R

Defines functions extractDIC extractAIC.rglmb extractAIC.glmb

Documented in extractAIC.glmb extractAIC.rglmb extractDIC

#' Extract DIC from a Fitted Bayesian Model
#'
#' Computes the Deviance Information Criterion (DIC) and the effective
#' number of parameters for Bayesian generalized linear models fitted
#' via \code{glmb()} or \code{rglmb()}. The DIC, introduced by
#' \insertCite{Spiegelhalter2002}{glmbayes}, provides a Bayesian analog to the
#' AIC \insertCite{Akaike1974}{glmbayes}.
#'
#' @param fit A fitted model of class \code{"glmb"} or \code{"rglmb"}.
#' @param ... Additional arguments passed to or from methods.
#'
#' @return A named numeric vector with components:
#'   \describe{
#'     \item{pD}{Estimated effective number of parameters}
#'     \item{DIC}{Deviance Information Criterion}
#'   }
#'
#' @seealso \code{\link{summary.glmb}}, \code{\link{glmb}}, \code{\link{glmbayes-package}},
#'   \code{\link{rglmb}}, \code{\link{rlmb}}, \code{\link{lmb}};
#'   \code{\link[stats]{extractAIC}} for the classical AIC computation on \code{lm}/\code{glm} fits
#' @references
#' \insertAllCited{}
#' @importFrom Rdpack reprompt
#' @example inst/examples/Ex_extractAIC.glmb.R
#'
#' @rdname extractDIC
#' @export
#' @method extractAIC glmb
## This method follows stats::extractAIC() conventions while returning DIC
## components for Bayesian fits. See inst/COPYRIGHTS.
extractAIC.glmb <- function(fit, ...) {
  c(pD = fit$pD, DIC = fit$DIC)
}

#' @rdname extractDIC
#' @export
#' @method extractAIC rglmb
extractAIC.rglmb <- function(fit, ...) {
  fit2 <- summary(fit)
  extractAIC(fit2, ...)
}

#' @rdname extractDIC
#' @export
extractDIC <- function(fit, ...) UseMethod(extractAIC)

Try the glmbayes package in your browser

Any scripts or data that you put into this service are public.

glmbayes documentation built on Aug. 5, 2026, 1:07 a.m.