1

I am looking to perform regression piecewise using non-linear functions with multiple breakpoints. I have done the piecewise linear regression, but when it comes to specifying non-linear functions of any kind, how do we setup in R?

Specifically, I am interested in 3 functions linear, exponential and exponential using two breakpoints. Please advise

karthik

user1229841
  • 31
  • 2
  • 4
  • How did you do your piecewise linear regression and why doesn't the same method generalize to non-linear functions? The `segmented` package can perform piecewise linear regressions, and if your model is `y ~ x + exp(x) + log(x)`, it is actually linear (with three predictor, `x`, `exp(x)` and `log(x)`). – Vincent Zoonekynd Feb 24 '12 at 03:35

2 Answers2

3

Would using nls() (nonlinear least squares) tackle your problem? I used a formulation similar to this, by adding in True/False statements for each "piece":

reg = nls( y ~ (Z < 0.33) * a + (Z < 0.33) * Z * b +
        (Z >= 0.33 & Z < 0.67) * Z ^ a2 +
        (Z >= 0.67) * a3 + (Z >= 0.67) * Z * a4,
        start = list(a = 0, b = 50, a2 = 100, a3 = 150, a4 = 80),
        data = yourdata)

In the stylized example above, breakpoints are at Z = 0.33 and Z = 0.67. If you can be more specific, or provide code of the three regressions separately, I can make my answer more specific.

baha-kev
  • 3,029
  • 9
  • 33
  • 31
0

My suggestion is to load the 'splines' package and then run the examples in help(bs). You can get piecewise cubic (but continuous at the knots) fits using the linear regression machinery. Harrell used this strategy to excellent effect in his 'rms' package. Load 'rms' and look at help(rcs). The example on that page uses his implementation of logistic regression but rcs() terms work in ols() and cph() as well.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • @IRFTM, Can you please take a look at this post [https://stackoverflow.com/questions/69814007/what-is-the-self-starting-model-function-in-r-that-uses-boltzmann-sigmoidal-equa] and advise me? – RanonKahn Nov 02 '21 at 19:46