% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/method-deviance.R
\name{deviance}
\alias{deviance}
\alias{deviance.INLAvaan}
\title{Deviance for INLAvaan Models}
\usage{
\method{deviance}{INLAvaan}(object, type = c("mean", "plugin"), ...)
}
\arguments{
\item{object}{An object of class \link{INLAvaan}.}

\item{type}{Character. \code{"mean"} (default) returns the posterior mean
deviance \eqn{\bar{D} = E[-2\log p(y \mid \theta)]}, averaged over
posterior draws. \code{"plugin"} returns the deviance evaluated at the
posterior mean point estimate, \eqn{\hat{D} = -2\log p(y \mid \hat\theta)}
(matching \code{-2 * logLik(object, type = "plugin")}). Both require the
model to have been fitted with \code{test != "none"}.}

\item{...}{Currently unused.}
}
\value{
A length-one numeric of class \code{inlavaan_deviance}, with the
effective number of parameters (\code{pD}) and \code{DIC} attached as
attributes.
}
\description{
Extract the (Bayesian) deviance of a fitted \code{INLAvaan} model. Unlike
\pkg{lavaan}, which has no \code{deviance()} method, this follows the
BUGS/JAGS/Stan convention: "deviance" is \eqn{-2} times the log-likelihood,
summarised over the posterior.
}
\details{
\eqn{\bar{D}} and \eqn{\hat{D}} are the two ingredients of the Deviance
Information Criterion, \eqn{DIC = \bar{D} + p_D} where
\eqn{p_D = \bar{D} - \hat{D}} is the effective number of parameters. Use
\code{\link[=compare]{compare()}} to compare models by DIC (or Bayes factors, or LOO/WAIC)
rather than comparing raw deviances directly.
}
\examples{
\donttest{
HS.model <- "
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9
"
utils::data("HolzingerSwineford1939", package = "lavaan")
fit <- acfa(HS.model, HolzingerSwineford1939, std.lv = TRUE, nsamp = 100,
            test = "standard", verbose = FALSE)

deviance(fit)
attr(deviance(fit), "DIC")
}

}
\seealso{
\code{\link[=logLik]{logLik()}}, \code{\link[=compare]{compare()}}
}
