nl_derivatives: Compute first and second derivatives of the fitted spline...

View source: R/nl_derivatives.R

nl_derivativesR Documentation

Compute first and second derivatives of the fitted spline curve

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 se.fit column of nl_predict(). Results are passed to nl_turning_points to identify local turning points and inflection regions.

Usage

nl_derivatives(pred_df, x, time = NULL, h = NULL, level = 0.95)

Arguments

pred_df

A data frame returned by nl_predict.

x

Character; name of the focal predictor column.

time

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

h

Numeric; step size for finite-difference approximation. Default NULL uses 0.1 percent of the x range.

level

Confidence level for derivative CIs. Default 0.95.

Value

A data frame with columns x (the focal predictor), time (if applicable), fit (predicted outcome), d1 (first derivative), d1_lwr and d1_upr (lower and upper CI for the first derivative), d2 (second derivative), and d2_lwr and d2_upr (CI for the second derivative).

See Also

nl_turning_points, nl_plot


MultiSpline documentation built on April 16, 2026, 9:06 a.m.