predict.nls
Predicting from Nonlinear Least Squares Fits
Description
Produces predicted values.
Usage
predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf, interval = c("none", "confidence", "prediction"), level = 0.95, ...)
Arguments
object |
an object that inherites from class nls.
|
newdata |
a named list or a data frame, which is used to provide variables to
predict. If this argument is not provided, or it is not a named list or
data.frame, then the fitted values at the original data points are
returned.
|
se.fit |
a logical flag. If TRUE, calculates the standard errors of the predictions. This argument is not used at present.
|
scale |
a number used as the residual standard deviation in calculating the standard errors. This argument is not used at present.
|
df |
a positive numer. Specifies the number of degrees of freedom for the scale estimate. This argument is not used at present.
|
interval |
a character string. Indicates whether to calculate prediction intervals or a confidence interval on the mean response.
This argument is not used at present.
|
level |
a number between 0 to 1. Provides the confidence level for the intervals to be calcuated. This argument is not used at present.
|
... |
any other optional arguments. This argument is not used at present.
|
Details
predict.nls produces predicted values; use the evaluating the regression function in the frame newdata.
Value
returns a vector of predictions.
See Also
Examples
tDat <- data.frame(
x = c(2.3, 3.2, 4.3, 5.3, 5.7, 6.3, 6.8, 9.6, 9.8, 10.7,
12.7, 13.2, 13.4, 13.7, 14.5, 15.4, 16.5, 17, 17.1, 17.9),
y = c(8.8, 9.6, 8, 4.2, 2.5, 0, -2, -7.1, -6.9, -4.9,
1.6, 2.8, 3.4, 3.8, 4.6, 4.1, 1.9, 0.7, 0.2, -1.8))
fit1 <- nls(y ~ beta1 * sin(x * freq1) + beta2 * sin(x * freq2),
data=tDat, start=list(freq1=0.5, freq2=0.3, beta1=5, beta2=5))
# return fitted values on original data points
predict(fit1)
# predict from the first two fitted data points
identical(predict(fit1, newdata=list(x=c(2.3,3.2))), predict(fit1)[1:2])
# predict from a set of x values
predict(fit1, newdata=data.frame(x=seq(0,20,by=2)))