predictdf.nls: Prediction data frame for nls

View source: R/xgx_stat_smooth.R

predictdf.nlsR Documentation

Prediction data frame for nls

Description

Get predictions with standard errors into data frame for use with geom_smooth

Usage

## S3 method for class 'nls'
predictdf(model, xseq, se, level)

Arguments

model

nls object

xseq

newdata

se

Display confidence interval around smooth?

level

Level of confidence interval to use

Details

ggplot2::geom_smooth produces confidence intervals by silently calling functions of the form predictdf.method, where method is "loess", "lm", "glm" etc. depending on what method is specified in the call to geom_smooth. Currently ggplot2 does not define a predictdf.nls function for method of type "nls", and thus confidence intervals cannot be automatically generated by geom_smooth for method = "nls". Here we define predictdf.nls for calculating the confidence intervals of an object of type nls. geom_smooth will silently call this function whenever method = "nls", and produce the appropriate confidence intervals.

predictdf.nls calculates CI for a model fit of class nls based on the "delta-method" http://sia.webpopix.org/nonlinearRegression.html#confidence-intervals-and-prediction-intervals)

CI = [ f(x0, beta) + qt_(alpha/2, n - d) * se(f(x0, beta)), f(x0, beta) + qt_(1 - alpha/2, n - d) * se(f(x0, beta))]

where: beta = vector of parameter estimates x = independent variable se(f(x0, beta)) = sqrt( delta(f)(x0, beta) * Var(beta) * (delta(f)(x0, beta))' ) delta(f) is the gradient of f

Value

dataframe with x and y values, if se is TRUE dataframe also includes ymin and ymax


xgxr documentation built on March 31, 2023, 11:46 p.m.