% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dose_response.R
\name{fit_dose_response}
\alias{fit_dose_response}
\alias{coef.dsr_4pl}
\alias{predict.dsr_4pl}
\alias{fitted.dsr_4pl}
\alias{residuals.dsr_4pl}
\alias{print.dsr_4pl}
\title{Fit a four-parameter logistic dose-response model}
\usage{
fit_dose_response(data, response, concentration, bounds = NULL)

\method{coef}{dsr_4pl}(object, ...)

\method{predict}{dsr_4pl}(object, newdata = NULL, ...)

\method{fitted}{dsr_4pl}(object, ...)

\method{residuals}{dsr_4pl}(object, ...)

\method{print}{dsr_4pl}(x, ...)
}
\arguments{
\item{data}{A data frame containing at least the response and concentration
columns for one drug and one condition.}

\item{response}{Name of the (normalised) response column, as a string.}

\item{concentration}{Name of the concentration column, as a string.}

\item{bounds}{Optional named list overriding the box constraints used by the
bounded optimiser. Recognised names are \code{top}, \code{bottom}, \code{ic50} and \code{hill},
each a numeric length-two vector \code{c(lower, upper)}.}

\item{object}{A \code{dsr_4pl} object.}

\item{...}{Ignored, for S3 method consistency.}

\item{newdata}{Optional numeric vector of concentrations at which to predict.
Defaults to the concentrations used for fitting.}

\item{x}{A \code{dsr_4pl} object.}
}
\value{
An object of class \code{dsr_4pl}: a list with elements \code{coefficients}
(named numeric vector \code{top}, \code{ic50}, \code{hill}, \code{bottom}), \code{fitted},
\code{residuals}, \code{convergence} (logical), \code{sse}, \code{data} and \code{call}. The
companion methods \code{coef()}, \code{predict()}, \code{fitted()}, \code{residuals()} and
\code{print()} are provided for this class.
}
\description{
Fits a 4PL curve for a single drug under one condition by non-linear least
squares, entirely in base R (no external fitting package required). Robust
starting values are derived from the data and refined with a bounded
\code{L-BFGS-B} optimisation over several initial \code{IC50} guesses, falling back to
a derivative-free \code{Nelder-Mead} search if needed. The model uses the same
parameterisation as \code{\link[=four_pl]{four_pl()}}, which matches the \code{dr4pl} package
convention (\code{UpperLimit}, \code{IC50}, \code{Slope}, \code{LowerLimit}).
}
\details{
The fitted parameters can be passed directly to \code{\link[=compute_auc]{compute_auc()}} to
obtain a potency summary, for example
\code{do.call(compute_auc, c(list(min(x), max(x)), as.list(coef(fit))))}.
}
\section{Functions}{
\itemize{
\item \code{coef(dsr_4pl)}: Extract the fitted 4PL coefficients (\code{top},
\code{ic50}, \code{hill}, \code{bottom}).

\item \code{predict(dsr_4pl)}: Predict responses from a fitted model.

\item \code{fitted(dsr_4pl)}: Extract fitted values.

\item \code{residuals(dsr_4pl)}: Extract residuals.

\item \code{print(dsr_4pl)}: Print a short summary of the fitted model.

}}
\examples{
one <- subset(
  screen_doseresponse,
  drug_name == "DrugA" & condition == "Gy0" & experiment_type == "sample"
)
fit <- fit_dose_response(one, "normalized_cell_count", "concentration")
coef(fit)
compute_auc(
  min(one$concentration), max(one$concentration),
  top = coef(fit)[["top"]], ic50 = coef(fit)[["ic50"]],
  hill = coef(fit)[["hill"]], bottom = coef(fit)[["bottom"]]
)

}
\seealso{
\code{\link[=four_pl]{four_pl()}}, \code{\link[=compute_auc]{compute_auc()}}
}
