Christian,

Thank you for the response and hint.  This is essentially what I ended up doing 
but I ran into several problems using nls().  I have since switched to optim() 
and seem to be having better luck.  Again, thank you for your help.

> -----Original Message-----
> From: Christian Ritz [mailto:r...@life.ku.dk]
> Sent: Saturday, April 17, 2010 2:45 PM
> To: Derek Ogle
> Cc: r-help@r-project.org
> Subject: Re: [R] piecewise nls?
> 
> Hi Derek,
> 
> have a look at the following made-up example:
> 
> f1 <- function(x){2*x}
> f2 <- function(x){-10*x+1}
> 
> x<-rnorm(10)
> x
> (x<0)*f1(x)
> (x>=0)*f2(x)
> (x<0)*f1(x) + (x>=0)*f2(x)
> 
> 
> 
> Therefore I suggest you should specify the model as follows:
> 
> yourNLSmodel <- nls(Y ~ (X<Z) * f(X,a,b,c) + (X>=Z) * g(X,a,d,e), data
> = myData, ...)
> 
> 
> 
> Christian

______________________________________________
R-help@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.

Reply via email to