predict.gsl_nls: Calculate model predicted values

View source: R/nls_methods.R

predict.gsl_nlsR Documentation

Calculate model predicted values

Description

Returns predicted values for the expected response from a fitted "gsl_nls" object. Asymptotic confidence or prediction (tolerance) intervals at a given level can be evaluated by specifying the appropriate interval argument.

Usage

## S3 method for class 'gsl_nls'
predict(
  object,
  newdata,
  scale = NULL,
  interval = c("none", "confidence", "prediction"),
  level = 0.95,
  ...
)

Arguments

object

An object inheriting from class "gsl_nls".

newdata

A named list or data.frame in which to look for variables with which to predict. If newdata is missing, the predicted values at the original data points are returned.

scale

A numeric scalar or vector. If it is set, it is used as the residual standard deviation (or vector of residual standard deviations) in the computation of the standard errors, otherwise this information is extracted from the model fit.

interval

A character string indicating if confidence or prediction (tolerance) intervals at the specified level should be returned.

level

A numeric scalar between 0 and 1 giving the confidence level for the intervals (if any) to be calculated.

...

At present no optional arguments are used.

Value

If interval = "none" (default), a vector of predictions for the mean response. Otherwise, a matrix with columns fit, lwr and upr. The first column (fit) contains predictions for the mean response. The other two columns contain lower (lwr) and upper (upr) confidence or prediction bounds at the specified level.

See Also

predict.nls

Examples

## data
set.seed(1)
n <- 50
xy <- data.frame(
  x = (1:n) / n, 
  y = 2.5 * exp(-1.5 * (1:n) / n) + rnorm(n, sd = 0.1)
)
## model
obj <- gsl_nls(fn = y ~ A * exp(-lam * x), data = xy, start = c(A = 1, lam = 1))

predict(obj)
predict(obj, newdata = data.frame(x = 1:(2 * n) / n))
predict(obj, interval = "confidence")
predict(obj, interval = "prediction", level = 0.99)

gslnls documentation built on Jan. 17, 2023, 5:15 p.m.