[R] fit nonlinear model with groups
Bill Simpson
W.Simpson at gcal.ac.uk
Fri Feb 8 10:40:25 CET 2002
I wanted to fit a nonlinear model using nls to two groups. Here is a toy
example.
library(nlme)
x<-rep(1:5,2)
cond<-c(rep("a",5),rep("b",5))
cond<-as.factor(cond)
y[cond=="a"]<-1/x +2
y[cond=="b"]<-2/x+3
df<-data.frame(x,y,cond)
fit<-nls(y~c(a1,b1)[cond]/x+c(a2,b2)[cond],data=df,
start=list(a1=1,b1=2,a2=2,b2=3))
I based above on an example posted by Bill Venables.
I get message:
maximum number of iterations exceeded
even if I reset maxiter using nls.control and even though I start the
params at the right place.
This example seems to work OK if I do
fit<-nls(y~c(a1,b1)[cond]/x+a2,data=df,
start=list(a1=1,b1=2,a2=2))
So maybe the trick using c()[cond] can be used only once per formula.
How to do it? Thanks for any help.
Bill
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list