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

predict.nls

predict.nls


Description

predict.nls

Usage

## S3 method for class 'nls'
predict(
  object,
  newdata = NULL,
  se.fit = FALSE,
  interval = "none",
  level = 0.95,
  ...
)

Arguments

object

Object of class inheriting from "nls"

newdata

An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.

se.fit

A switch indicating if standard errors are required.

interval

Type of interval calculation, "none" or "confidence"

level

Level of confidence interval to use

...

additional arguments affecting the predictions produced.

Value

predict.nls produces a vector of predictions or a matrix of predictions and bounds with column names fit, lwr, and upr if interval is set.

If se.fit is TRUE, a list with the following components is returned:

fit

vector or matrix as above

se.fit

standard error of predicted means

residual.scale

residual standard deviations

df

degrees of freedom for residual

Examples

set.seed(12345)
data_to_plot <- data.frame(x1 = rep(c(0, 25, 50, 100, 200, 400, 600), 10)) %>%
  dplyr::mutate(AUC = x1*rlnorm(length(x1), 0, 0.3),
         x2 = x1*stats::rlnorm(length(x1), 0, 0.3),
         Response = (15 + 50*x2/(20+x2))*stats::rlnorm(length(x2), 0, 0.3))


gg <- ggplot2::ggplot(data = data_to_plot, ggplot2::aes(x = AUC, y = Response)) + 
  ggplot2::geom_point() + 
  xgx_geom_smooth(method = "nls",  
                  method.args = list(formula = y ~ E0 + Emax* x / (EC50 + x),
                                     start = list(E0 = 15, Emax = 50, EC50 = 20) ), 
                  color = "black", size = 0.5, alpha = 0.25)
gg

mod <- stats::nls(formula = Response ~ E0 + Emax * AUC / (EC50 + AUC), 
data = data_to_plot, 
start = list(E0 = 15, Emax = 50, EC50 = 20))

predict.nls(mod)

predict.nls(mod, se.fit = TRUE)

predict.nls(mod, 
            newdata = data.frame(AUC = c(0, 25, 50, 100, 200, 400, 600)), 
            se.fit = TRUE)
            
predict.nls(mod, 
            newdata = data.frame(AUC = c(0, 25, 50, 100, 200, 400, 600)), 
            se.fit = TRUE, interval = "confidence", level = 0.95)
            
predict(mod, 
            newdata = data.frame(AUC = c(0, 25, 50, 100, 200, 400, 600)), 
            se.fit = TRUE, interval = "confidence", level = 0.95)

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.