[R] piecewise nls?

Christian Ritz ritz at life.ku.dk
Sat Apr 17 21:45:14 CEST 2010


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



More information about the R-help mailing list