% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nl_derivatives.R
\name{nl_derivatives}
\alias{nl_derivatives}
\title{Compute first and second derivatives of the fitted spline curve}
\usage{
nl_derivatives(pred_df, x, time = NULL, h = NULL, level = 0.95)
}
\arguments{
\item{pred_df}{A data frame returned by \code{\link{nl_predict}}.}

\item{x}{Character; name of the focal predictor column.}

\item{time}{Optional character; name of the time column. If present,
derivatives are computed separately within each time level.}

\item{h}{Numeric; step size for finite-difference approximation.
Default \code{NULL} uses 0.1 percent of the x range.}

\item{level}{Confidence level for derivative CIs. Default \code{0.95}.}
}
\value{
A data frame with columns \code{x} (the focal predictor),
\code{time} (if applicable), \code{fit} (predicted outcome),
\code{d1} (first derivative), \code{d1_lwr} and \code{d1_upr}
(lower and upper CI for the first derivative), \code{d2} (second
derivative), and \code{d2_lwr} and \code{d2_upr} (CI for the second
derivative).
}
\description{
Uses numerical differentiation on the prediction grid to compute the
first derivative (slope / marginal effect), the second derivative
(curvature), and propagated confidence bands for both, using the
delta method from the \code{se.fit} column of \code{nl_predict()}.
Results are passed to \code{\link{nl_turning_points}} to identify
local turning points and inflection regions.
}
\seealso{
\code{\link{nl_turning_points}}, \code{\link{nl_plot}}
}
