Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predictdf.nls

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

Exploratory Graphics for Pharmacometrics

v1.1.1
MIT + file LICENSE
Authors
Andrew Stein [aut, cre], Alison Margolskee [aut], Fariba Khanshan [aut], Konstantin Krismer [aut] (<https://orcid.org/0000-0001-8994-3416>), Matthew Fidler [ctb] (<https://orcid.org/0000-0001-8538-6691>), Novartis Pharma AG [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.