# [R] piece wise functions

Casiano Rodriguez Leon casiano at ull.es
Mon Apr 21 15:09:36 CEST 2003

```Hello,

Apologies if this question has already arised, hope you can
help me to the find the solution to this or point the place to look at.

I have a multidimensional piece-wise regression linear problem, i.e.
to find not only the regression coefficients for each "interval" but
also the beginning and ends of the intervals.

To simplify it to the one dimensional case and
two intervals, the problem is to find A_0, A_1, ... A_p and "C"
from the given sample, assuming the curve is like this:

A_0*f_0(x)+A_1*f_1(x)+ ... + A_p*f_p(x) with x < C

A_0'*f_0(x)+A_1'*f_1(x)+ ... + A_p'*f_p(x) with x >= C

Functions f_1, f_2, ... f_p are known.

Is there anything in R for that?

I have tried to use nonlinear (nls package)
regression, "forcing" with the "nls" function the shape of the surface,
but it does not work.

By the way, the cofficients A_i have to be positive, but I suppose this is
another question.

Thanks

Casiano
casiano at ull.es

```