% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/diagnostics.R
\name{bdeb_loo}
\alias{bdeb_loo}
\title{LOO Cross-Validation for Model Comparison}
\usage{
bdeb_loo(fit, endpoint = c("all", "growth", "reproduction"), ...)
}
\arguments{
\item{fit}{A \code{\link[=bdeb_fit]{bdeb_fit()}} object.}

\item{endpoint}{Which log-likelihood to use for \code{"growth_repro"}
models: \code{"all"} (default, concatenates growth + reproduction),
\code{"growth"}, or \code{"reproduction"}.  Ignored for \code{"individual"} models.}

\item{...}{Additional arguments passed to \code{\link[loo:loo]{loo::loo()}}.}
}
\value{
A \code{loo} object (see \code{\link[loo:loo]{loo::loo()}}).
}
\description{
Computes approximate leave-one-out cross-validation (LOO-CV) using
Pareto-smoothed importance sampling (PSIS; Vehtari et al., 2017).
Requires that the Stan model includes a \code{log_lik} array in the
\verb{generated quantities} block.
}
\details{
Currently supported for \code{"individual"} and \code{"growth_repro"} models
only.  The \code{"hierarchical"} and \code{"debtox"} models do not store
per-observation \code{log_lik} in \verb{generated quantities}:
\code{"hierarchical"} computes the likelihood inside \code{reduce_sum}
(no access to individual contributions outside the function);
\code{"debtox"} uses the same \code{reduce_sum} approach and its
\verb{generated quantities} block only computes EC50/NEC.
Adding per-group \code{log_lik} to DEBtox is planned for a future
version.  An informative error is raised for unsupported types.
}
\section{Conditional independence assumption}{

For \code{"growth_repro"} models with \code{endpoint = "all"}, growth and
reproduction observations are concatenated and each treated as an
independent data point.  This is valid because the two endpoints are
\strong{conditionally independent given the latent DEB process} (growth
observations depend only on \eqn{V(t)}, reproduction counts depend
only on \eqn{\Delta E_R}; given the ODE solution, they share no
additional error).  Use \code{endpoint = "growth"} or
\code{endpoint = "reproduction"} to compute LOO for a single endpoint.
}

\examples{
\donttest{
if (requireNamespace("cmdstanr", quietly = TRUE) &&
    nzchar(tryCatch(cmdstanr::cmdstan_path(), error = function(e) ""))) {
  data(eisenia_growth)
  dat <- bdeb_data(growth = eisenia_growth[eisenia_growth$id == 1, ])
  fit <- bdeb_fit(bdeb_model(dat, type = "individual"),
                  chains = 2, iter_warmup = 200, iter_sampling = 200,
                  refresh = 0)
  bdeb_loo(fit)
}
}
}
\references{
Vehtari, A., Gelman, A. and Gabry, J. (2017). Practical Bayesian
model evaluation using leave-one-out cross-validation and WAIC.
\emph{Statistics and Computing}, 27(5), 1413--1432.
\doi{10.1007/s11222-016-9696-4}
}
