简体   繁体   English

在R中使用非线性函数的分段非线性回归

[英]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? 我已经完成了分段线性回归,但是当指定任何类型的非线性函数时,我们如何在R中设置?

Specifically, I am interested in 3 functions linear, exponential and exponential using two breakpoints. 具体来说,我对使用两个断点的3个函数线性,指数和指数感兴趣。 Please advise 请指教

karthik KARTHIK

Would using nls() (nonlinear least squares) tackle your problem? 使用nls() (非线性最小二乘)会解决你的问题吗? I used a formulation similar to this, by adding in True/False statements for each "piece": 我使用了类似于此的公式,为每个“片段”添加了True / False语句:

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. 在上面的程式化示例中,断点位于Z = 0.33且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) . 我的建议是加载“ splines”程序包,然后在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. Harrell在他的“ rms”软件包中使用了此策略,效果极佳。 Load 'rms' and look at help(rcs) . 加载“ rms”并查看help(rcs) The example on that page uses his implementation of logistic regression but rcs() terms work in ols() and cph() as well. 该页面上的示例使用了逻辑回归的实现,但rcs()术语也在ols()cph()中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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