My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

nls2 is an R package that adds the "brute-force" algorithm and multiple starting values to the R nls function. nls2 is free software licensed under the GPL and available from CRAN. It provides a function, nls2, which is a superset of the R nls function which it, in turn, calls.

News

August 22, 2010. nls2 version 0.1-3 uploaded to CRAN. See NEWS file.

Installation

As with any R package on CRAN, nls2 can be installed from within R using

install.packages("nls2")

Help

After installation, the nls2 help page can be accessed from within R via

library(nls2)
help(nls2)

or it can be accessed online here.

Examples

There are examples:

Citation

The citation for this package can be obtained by issuing this command from within R:

citation("nls2")

FAQs

Q. Why does this not work?

library(nls2)

# data is from ?nls
DNase1 <- subset(DNase, Run == 1)
fm1DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1)

# next line is wrong
predict(as.lm(fm1DNase1), newdata = list(conc = 1:12))

A. The problem is that the variables in the tangent linear model are Asym, xmid and scal -- not conc. One can only predict at the fitted points although one can interpolate among those -- in the next version of nls2 as.lm will have a newdata= argument which will generate a new lm based on a randomly synthesized response so that predict(as.lm(fm1DNase1, newdata = list(conc = 1:12), interval = "confidence") will be possible but in the meantime:

library(nls2)

# run nls
DNase1 <- subset(DNase, Run == 1)
fm1DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1)

# predict at original points
pred <- predict(as.lm(fm1DNase1), interval = "prediction")

# interpolate
x0 <- 1:12
pred0 <- apply(pred, 2, function(y) spline(DNase1$conc, y, xout = x0)$y)

# plot
plot(density ~ conc, DNase1)
matlines(DNase1$conc, pred)
matpoints(x0, pred0, col = 1:3, pch = 20)

(Note that this package is unrelated to the software of the same name associated with the book Statistical Tools for Nonlinear Regression by Huet et al.)

Powered by Google Project Hosting