predict.nls: predict.nls

View source: R/predict.nls.R

predict.nlsR Documentation

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 documentation built on March 31, 2023, 11:46 p.m.