[R] How to store the parameter estimated by nls( ) to a variable?

Joerg van den Hoff j.van_den_hoff at fzd.de
Mon Aug 13 11:54:37 CEST 2007


On Sun, Aug 12, 2007 at 10:50:59AM -0700, Yuchen Luo wrote:
> Dear Professor Murdoch.
> Thank you so much!!!!
> 
> Best Wishes
> Yuchen Luo
> 
> On 8/12/07, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> >
> > 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
> >
> 

further information might be extracted from the `summary' return value.
e.g., if you need not only the parameters but also their error
estimates, you could get them via

summary(a)$parameters[, "Std. Error"]

(question: is this the canonical way to do it or is their a better one?)



More information about the R-help mailing list