In a nls star things might be different than the lm planet…

March 10, 2010
By

(This article was first published on Stats raving mad » R, and kindly contributed to R-bloggers)

The nls() function has a well documented (and discussed) different behavior compared to the lm()’s. Specifically you can’t just put an indexed column from a data frame as an input or output of the model.

> nls(data[,2] ~ c + expFct(data[,4],beta), data = time.data,
+ start = start.list)
Error in parse(text = x) : unexpected end of input in "~ "

The following will work, when we assign things as vectors.

> nls(y ~ c + expFct(x,beta), data = time.data,start = start.list)
#
# Formula: y ~ c + expFct(x,beta)
#
# Parameters:
#        Estimate Std. Error t value Pr(>|t|)    
# c     3.7850419  0.0042017  900.83  < 2e-16 ***
# beta  0.0053321  0.0003733   14.28 1.31e-12 ***
# ---
# Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#
# Residual standard error: 0.01463 on 22 degrees of freedom
#
# Number of iterations to convergence: 1
# Achieved convergence tolerance: 7.415e-06

To leave a comment for the author, please follow the link and comment on his blog: Stats raving mad » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , ,

Comments are closed.