% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/debtox.R
\name{plot_dose_response}
\alias{plot_dose_response}
\title{Plot DEBtox Dose-Response}
\usage{
plot_dose_response(
  fit,
  endpoint = "growth",
  n_draws = 100,
  n_conc = 50,
  dt = 1,
  t_end = NULL,
  seed = NULL
)
}
\arguments{
\item{fit}{A \code{\link[=bdeb_fit]{bdeb_fit()}} object from a DEBtox model.}

\item{endpoint}{Which endpoint to plot.  Currently only \code{"growth"}.}

\item{n_draws}{Number of posterior draws to use.  Default 100.}

\item{n_conc}{Number of concentration points in the continuous grid.
Default 50.}

\item{dt}{Euler integration step size (days).  Default 1.0.  Smaller
values are more accurate but slower.  The Stan model uses BDF with
adaptive stepping; this is an approximation for visualisation.}

\item{t_end}{End time for the simulation (days).  Default \code{NULL}
(uses the last observation time from the fitted data).}

\item{seed}{Integer seed for reproducible draw selection.
Default \code{NULL}.}
}
\value{
A ggplot2 object.
}
\description{
Produces a dose-response curve by \strong{forward-simulating} the full
4-state DEBtox ODE from the posterior in R (Euler integration).
For each posterior draw, the ODE is solved at every concentration in
a fine grid from 0 to \eqn{1.2 \times \max(C_w)}.  The y-axis shows
the predicted final structural length relative to the control (C = 0)
at the same draw, so that each curve propagates the full parameter
uncertainty through the dynamic model.
}
\details{
This is a \strong{visualisation tool}, not exact Stan inference.  The
R-side Euler integrator (step size \code{dt}) is an approximation of the
BDF solver used during fitting.  For quantitative
results, use \code{\link[=bdeb_ec50]{bdeb_ec50()}} which extracts the analytically computed
EC\eqn{_{50}} and NEC directly from the Stan posterior.

\strong{Performance note.} Each draw requires \code{n_conc} ODE integrations,
so \code{n_draws * n_conc} total.  With default settings (100 draws,
50 concentrations) this takes a few seconds.  Reduce \code{n_draws} for
faster interactive use.
}
\examples{
\donttest{
if (requireNamespace("cmdstanr", quietly = TRUE) &&
    nzchar(tryCatch(cmdstanr::cmdstan_path(), error = function(e) ""))) {
  data(debtox_growth)
  dat <- bdeb_data(growth = debtox_growth,
                   concentration = c("1" = 0, "11" = 20,
                                    "21" = 80, "31" = 200))
  fit <- bdeb_fit(bdeb_tox(dat, stress = "assimilation"),
                  chains = 2, iter_warmup = 200, iter_sampling = 200,
                  init = 0.5, refresh = 0)
  plot_dose_response(fit, n_draws = 50)
}
}
}
