% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ppc.R
\name{bdeb_ppc}
\alias{bdeb_ppc}
\title{Posterior Predictive Checks for BDEB Models}
\usage{
bdeb_ppc(fit, type = c("growth", "reproduction", "all"))
}
\arguments{
\item{fit}{A \code{\link[=bdeb_fit]{bdeb_fit()}} object.}

\item{type}{Which endpoint to check: \code{"growth"}, \code{"reproduction"}, or
\code{"all"}. Default \code{"growth"}.}
}
\value{
A \code{bdeb_ppc} object containing observed data (\code{L_obs} or
\code{R_obs}), a matrix of replicated data (\code{L_rep} or \code{R_rep}), and
metadata for \code{\link[=plot.bdeb_ppc]{plot.bdeb_ppc()}}.
}
\description{
Extracts replicated data \eqn{y^{\mathrm{rep}}} generated in the Stan
\verb{generated quantities} block and pairs them with the observed data
\eqn{y}.  Following Gelman et al. (2013, Ch. 6), posterior predictive
checks (PPCs) answer: "could the observed data plausibly have been
generated by the fitted model?"  If the replicated data envelopes
consistently miss systematic features of \eqn{y}, the model is
mis-specified.
}
\details{
For growth endpoints, the replicated lengths \eqn{L^{\mathrm{rep}}_i}
are drawn as \eqn{L^{\mathrm{rep}}_i \sim N(\hat{L}_i, \sigma_L)} in
the Stan program.  For reproduction, \eqn{R^{\mathrm{rep}}_i \sim
\mathrm{NegBin}(k_R \Delta E_R, \phi)}.
}
\section{Supported models}{

\describe{
\item{\code{"individual"}}{Full PPC with \code{L_rep} and \code{L_obs}.}
\item{\code{"growth_repro"}}{Growth PPC via \code{L_rep}; reproduction PPC
via \code{R_rep}.}
\item{\code{"hierarchical"}}{Not available.  The Stan model uses
\code{reduce_sum} and does not generate \code{L_rep}.  Use
\code{\link[=bdeb_diagnose]{bdeb_diagnose()}} and trace plots for model checking.}
\item{\code{"debtox"}}{Not available for the same reason.  Use
\code{\link[=plot_dose_response]{plot_dose_response()}} for visual model checking.}
}
}

\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)
  ppc <- bdeb_ppc(fit, type = "growth")
  plot(ppc)
}
}
}
\references{
Gelman, A., Carlin, J.B., Stern, H.S., Dunson, D.B., Vehtari, A.
and Rubin, D.B. (2013). \emph{Bayesian Data Analysis}. 3rd edition.
Chapman & Hall/CRC. (Chapter 6: Model checking.)
}
