Learn R Programming

nlstac (version 0.2.0)

predict.nlstac: Predict a nls tac fit.

Description

Returns the prediction values of a nls tac fit model for a given set of predictors.

Usage

# S3 method for nlstac
predict(object, newdata = NULL, ...)

Value

A vector with the predicted values for the predictor given in the newdata input.

Arguments

object

An object of class "tac" obtained by the nls_tac function.

newdata

An optional data frame in which to look for variables with which to predict. It should contain at least the columns for the independent variables with the same names as the ones used in the formula passed to the nls_tac function. If omitted, the fitted values are used.

...

Ignored, for compatibility issues.

Author

Mariano Rodríguez-Arias (arias@unex.es). Deptartment of Mathematics

Juan Antonio Fernández Torvisco (jfernandck@alumnos.unex.es). Department of Mathematics

University of Extremadura (Spain)

Rafael Benítez (rafael.suarez@uv.es). Department of Business Mathematics

University of Valencia (Spain)

Examples

Run this code


x <- seq(from = 0, to = 3, length.out = 50)
y <- 3*exp(-5*x) + 2*x + 1 + 0.05*rnorm(50)
df <- data.frame(x = x, y = y)
form <- y ~ a1*exp(-b1*x) + a2*x + a3
nlbnds <- list(b1 = c(0.5,10)) # bouds for tac
fitmodel <-  nls_tac(formula = form, data = df, nlparam = nlbnds)
yhat <- predict(fitmodel) # predict values in the fitted abcisae
plot(x,y)
lines(x,yhat, col = "red", lwd = 2)
# Predicting for other points
newdata <- c(0.25,1.5,2.25)
yhat2 <- predict(fitmodel, newdata = data.frame(x = newdata))
points(newdata, yhat2, pch = 19, col = "blue", cex = 1.2)

Run the code above in your browser using DataLab