[R] nls fits by groups

Gabor Grothendieck ggrothendieck at gmail.com
Sun Sep 23 17:17:07 CEST 2007

Check out the subset= argument to nls, e.g. to regress Sepal.Length
on Sepal.Width separately for each Species using the built in iris data set:

f <- function(s) nls(Sepal.Length ~ a*Sepal.Width, data = iris,
   start = c(a = 1), subset = iris$Species == s)
sapply(levels(iris$Species), f, simplify = FALSE)

On 9/23/07, Aleksi Lehtonen <lehtonen.aleksi at gmail.com> wrote:
> Dear Colleagues,
> 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....
> regards, Aleksi Lehtonen
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list