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