% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/method-loglik.R
\name{logLik}
\alias{logLik}
\alias{logLik,INLAvaan-method}
\alias{AIC,INLAvaan-method}
\alias{BIC,INLAvaan-method}
\title{Log-Likelihood for INLAvaan Models}
\usage{
\S4method{logLik}{INLAvaan}(object, type = c("marginal", "plugin"), ...)

\S4method{AIC}{INLAvaan}(object, ..., k = 2)

\S4method{BIC}{INLAvaan}(object, ...)
}
\arguments{
\item{object}{An object of class \link{INLAvaan}.}

\item{type}{Character. \code{"marginal"} (default) returns the
Laplace-approximated marginal log-likelihood (log evidence), the same
quantity \code{\link[=compare]{compare()}} uses for Bayes factors. \code{"plugin"} returns the
classical log-likelihood evaluated at the posterior mean point estimate,
with \code{df}/\code{nobs} attributes and class \code{"logLik"} so it
supports \code{\link[stats]{AIC}}/\code{\link[stats]{BIC}} at the point
estimate. Requires the model to have been fitted with
\code{test != "none"}.}

\item{...}{Currently unused.}

\item{k}{Numeric penalty per parameter passed to the (disabled) \code{AIC()}
method; see \code{\link[stats:AIC]{stats::AIC()}}. Defaults to 2.}
}
\value{
For \code{type = "marginal"}, a length-one numeric of class
\code{inlavaan_logLik} that prints with a note on its interpretation.
For \code{type = "plugin"}, a standard \code{"logLik"} object.
}
\description{
Extract a log-likelihood-flavoured summary from a fitted \code{INLAvaan}
model. Two distinct quantities are available, deliberately not conflated:
the Bayesian marginal log-likelihood (the default) and the classical
log-likelihood evaluated at the posterior mean.
}
\details{
The marginal log-likelihood already integrates over the (Laplace-
approximated) posterior, so it is not on the same scale as a classical
log-likelihood and should not be passed to \code{AIC()}/\code{BIC()} --
doing so would double-penalise model complexity that the evidence has
already accounted for. Use \code{\link[=compare]{compare()}} to compare models via Bayes
factors, DIC, or LOO/WAIC. The plug-in variant exists for users who
specifically want a point-estimate-based classical comparison.

\code{AIC()}/\code{BIC()} on an \code{INLAvaan} fit are themselves
disabled (mirroring \code{\link[=anova]{anova()}}): both are large-sample asymptotic
approximations to quantities INLAvaan already computes directly --
\code{AIC} approximates predictive accuracy, which \code{\link[=loo]{loo()}}/\code{\link[=waic]{waic()}}
already estimate more rigorously; \code{BIC} approximates \eqn{-2} times
the log marginal likelihood, which \code{logLik()} already returns
directly (up to the Laplace approximation). Point-estimate AIC/BIC remain
available for reporting-convention purposes via
\code{AIC(logLik(object, type = "plugin"))} /
\code{BIC(logLik(object, type = "plugin"))}.
}
\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)

# Marginal log-likelihood (log evidence)
logLik(fit)

# Classical log-likelihood at the posterior mean, AIC/BIC-compatible
ll <- logLik(fit, type = "plugin")
AIC(ll)
}

}
\seealso{
\code{\link[=deviance]{deviance()}}, \code{\link[=compare]{compare()}}, \code{\link[=loo]{loo()}}, \code{\link[=waic]{waic()}}
}
