简体   繁体   中英

Piecewise non-linear regression using non-linear function in R

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM