[R] nls fits by groups

Ken Knoblauch knoblauch at lyon.inserm.fr
Sun Sep 23 21:17:25 CEST 2007


Aleksi Lehtonen <lehtonen.aleksi <at> gmail.com> writes:

> I am trying to estimate several non-linear models simultaneously. I don't
> want to use non-linear mixed model, but non-linear model with same form, but
> it should be estimated separately according to variable group (I have lots
> of groups that have lots of observations....). I would like to have unique
> parameters for each group.
> 
> e.g. something like this
> 
> mod <- nls(y ~ a*x^b, start=c(a=1, b=1), group=group)
> 
> but knowing that group option does not work. If someone has an idea (or has
> done it already) how to implement this either using just nls statement or by
> building a simple function in R, I would be very grateful for hints....

Why not nlsList from the nlme package.  It would look something like this:

 mod <- nlsList(y ~ a*x^b | group, start=c(a=1, b=1))

you might have to add a data argument, too, depending on where your data is.

HTH,

Ken



More information about the R-help mailing list