Yuchen Luo
2007-Aug-12 06:11 UTC
[R] How to store the parameter estimated by nls( ) to a variable?
Dear Colleagues. I believe this should be a problem encountered by many: nls( ) is a very useful and efficient function to use if we are just to display the estimated value on screen. What if we need R to store the estimated parameter in a variable? For example: x=rnorm(10, mean=1000, sd=10) y=x^2+100+rnorm(10) a=nls(y~(x^2+para),control=list(maxiter = 1000, minFactor=0.5 ^1024),start=list(para=0.0)) How to store the estimated value of para in this case, in a variable, say, b? It is easy to display a and find all the information. How ever, I need to fit a different set of x and y in every loop of my code and I need to store the estimated values for further use. I have checked both the online manual and several S-plus books but no example as such showed up. Your help will be highly appreciated! Best Wishes Yuchen Luo [[alternative HTML version deleted]]
Duncan Murdoch
2007-Aug-12 12:26 UTC
[R] How to store the parameter estimated by nls( ) to a variable?
Yuchen Luo wrote:> Dear Colleagues. > > I believe this should be a problem encountered by many: > > nls( ) is a very useful and efficient function to use if we are just to > display the estimated value on screen. What if we need R to store the > estimated parameter in a variable? > > For example: > > x=rnorm(10, mean=1000, sd=10) > > y=x^2+100+rnorm(10) > > a=nls(y~(x^2+para),control=list(maxiter = 1000, minFactor=0.5 > ^1024),start=list(para=0.0)) > > How to store the estimated value of para in this case, in a variable, say, > b? > > It is easy to display a and find all the information. How ever, I need to > fit a different set of x and y in every loop of my code and I need to store > the estimated values for further use. I have checked both the online manual > and several S-plus books but no example as such showed up. > > Your help will be highly appreciated!coef(a) will get what you want. coef() works for most modelling functions where it makes sense. Duncan Murdoch