Is it possible to include a factor in an nls formula? I've searched the help pages without any luck so I guess it is not feasible. I've given it a few attempts without luck getting the message: + not meaningful for factors in: Ops.factor(independ^EE, a) This is a toy example, my realworld case is much more complicated (and can not be solved linearizing an using lm) a<-as.factor(c(rep(1,50),rep(0,50))) independ<-rnorm(100) respo<-rep(NA,100) respo[a==1]<-(independ[a==1]^2.3)+2 respo[a==0]<-(independ[a==0]^2.1)+3 nls(respo~independ^EE+a,start=list(EE=1.8),trace=TRUE) Any pointers welcomed Many Thanks, Manu
Manuel, I don't think that it works very easily. Instead, try gnls() in the nlme package. Cheers Andrew On Thu, Apr 20, 2006 at 11:18:02AM +0200, Manuel Gutierrez wrote:> Is it possible to include a factor in an nls formula? > I've searched the help pages without any luck so I > guess it is not feasible. > I've given it a few attempts without luck getting the > message: > + not meaningful for factors in: > Ops.factor(independ^EE, a) > > This is a toy example, my realworld case is much more > complicated (and can not be solved linearizing an > using lm) > a<-as.factor(c(rep(1,50),rep(0,50))) > independ<-rnorm(100) > respo<-rep(NA,100) > respo[a==1]<-(independ[a==1]^2.3)+2 > respo[a==0]<-(independ[a==0]^2.1)+3 > nls(respo~independ^EE+a,start=list(EE=1.8),trace=TRUE) > > Any pointers welcomed > Many Thanks, > Manu > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 Email: a.robinson at ms.unimelb.edu.au http://www.ms.unimelb.edu.au
On Thu, 20 Apr 2006, Manuel Gutierrez wrote:> Is it possible to include a factor in an nls formula?Yes. What do you intend by it? If you mean what it would mean for a lm formula, you need A[a] and starting values for A. There's an example on p.219 of MASS4.> I've searched the help pages without any luck so I > guess it is not feasible. > I've given it a few attempts without luck getting the > message: > + not meaningful for factors in: > Ops.factor(independ^EE, a) > > This is a toy example, my realworld case is much more > complicated (and can not be solved linearizing an > using lm) > a<-as.factor(c(rep(1,50),rep(0,50))) > independ<-rnorm(100) > respo<-rep(NA,100) > respo[a==1]<-(independ[a==1]^2.3)+2 > respo[a==0]<-(independ[a==0]^2.1)+3 > nls(respo~independ^EE+a,start=list(EE=1.8),trace=TRUE) > > Any pointers welcomed > Many Thanks, > Manu > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595