In a nls star things might be different than the lm planet…
[This article was first published on Stats raving mad » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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 their blog: Stats raving mad » R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.