使用分段包进行分段线性回归的“固定结和预测”

时间:2013-01-22 14:59:07

标签: r linear-regression

嗨,这个问题与先前提出的问题有关,但由于这个问题已成功回答,而且我的查询现在有所不同,我觉得新问题是有效的。如果您认为这是错误的地方,请随时将其移至Cross Validated。

与此相关的问题是here。我将在此提供相同的数据供参考:

x<-c(1e-08, 1.1e-08, 1.2e-08, 1.3e-08, 1.4e-08, 1.6e-08, 1.7e-08, 
1.9e-08, 2.1e-08, 2.3e-08, 2.6e-08, 2.8e-08, 3.1e-08, 3.5e-08, 
4.2e-08, 4.7e-08, 5.2e-08, 5.8e-08, 6.4e-08, 7.1e-08, 7.9e-08, 
8.8e-08, 9.8e-08, 1.1e-07, 1.23e-07, 1.38e-07, 1.55e-07, 1.76e-07, 
1.98e-07, 2.26e-07, 2.58e-07, 2.95e-07, 3.25e-07, 3.75e-07, 4.25e-07, 
4.75e-07, 5.4e-07, 6.15e-07, 6.75e-07, 7.5e-07, 9e-07, 1.15e-06, 
1.45e-06, 1.8e-06, 2.25e-06, 2.75e-06, 3.25e-06, 3.75e-06, 4.5e-06, 
5.75e-06, 7e-06, 8e-06, 9.25e-06, 1.125e-05, 1.375e-05, 1.625e-05, 
1.875e-05, 2.25e-05, 2.75e-05, 3.1e-05)

y2<-c(-0.169718017273307, 7.28508517630734, 71.6802510299446, 164.637259265704, 
322.02901173786, 522.719633360006, 631.977073772459, 792.321270345847, 
971.810607095548, 1132.27551798986, 1321.01923840546, 1445.33152600664, 
1568.14204073109, 1724.30089942149, 1866.79717333592, 1960.12465709003, 
2028.46548012508, 2103.16027631327, 2184.10965255236, 2297.53360080873, 
2406.98288043262, 2502.95194879366, 2565.31085776325, 2542.7485752473, 
2499.42610084412, 2257.31567571328, 2150.92120390084, 1998.13356362596, 
1990.25434682546, 2101.21333152526, 2211.08405955931, 1335.27559108724, 
381.326449703455, 430.9020598199, 291.370887491989, 219.580548355043, 
238.708972427248, 175.583544448326, 106.057481792519, 59.8876372379487, 
26.965143266819, 10.2965349811467, 5.07812046132922, 3.19125838983254, 
0.788251933518549, 1.67980552001939, 1.97695007279929, 0.770663673279958, 
0.209216903989619, 0.0117903221723813, 0.000974437796492681, 
0.000668823762763647, 0.000545308757270207, 0.000490042305650751, 
0.000468780182460397, 0.000322977916070751, 0.000195423690538495, 
0.000175847622407421, 0.000135771259866332, 9.15607623591363e-05)

我已成功使用1e-071e-06处的断点进行分段线性模型:

linear.model2<-lm(y~x)
segmented.mod2<-segmented(linear.model2,seg.Z= ~x, psi=c(0.0000001,0.000001))

结果情节看起来像这样,并且非常适合: Segmented fit http://i49.tinypic.com/nqe6c.jpg

但很明显,断点不是我设置它们的地方(summary(segmented.mod2)确认)。现在我意识到这是包的重点,它会迭代直到找到定义最佳拟合的断点,但是我有理论上的理由让这些精确断点定义最佳拟合(我想你会称这个固定的结? )。这是否可以使用分段软件包,或者任何人都可以提供更准确定义断点的更好解决方案吗?

另一个问题是,由于我将使用这些关系进行预测,因此我想提取定义线段的斜率和截距。这应该可以使用slope(segmented.mod2)intercept(segmented.mod2),但是这种情况下的结果似乎与我的预期不符:

Est.   St.Err.  t value  CI(95%).l  CI(95%).u
slope1  4.614e+10 3.936e+09  11.7200  3.824e+10  5.403e+10
slope2 -6.177e+09 4.397e+08 -14.0500 -7.059e+09 -5.296e+09
slope3 -2.534e+06 5.376e+06  -0.4714 -1.332e+07  8.248e+06

Est.
intercept1 -165.90
intercept2 3061.00
intercept3   46.93

这些行的格式是y=mx+c吗?这可能是一个非常愚蠢的问题,但他们是我最喜欢的! ;)

将非常感激地收到任何建议。

1 个答案:

答案 0 :(得分:2)

如果在第一次迭代后停止计算,则第一个断点将是起始值:

sctrl <- seg.control(toll = 1e-04, it.max = 1, display = FALSE,
     stop.if.error = TRUE, K = 10, quant = FALSE, last = TRUE, maxit.glm = 25, h = 1, 
     n.boot=20, size.boot=NULL, gap=FALSE, jt=FALSE, nonParam=TRUE,
     random=TRUE, powers=c(1,1), seed=NULL)
 linear.model2<-lm(y2~x)
 segmented.mod3<-segmented(linear.model2,seg.Z= ~x, control=sctrl, 
                                psi=c(0.0000001,0.000001))
 plot(log(x) ,predict(segmented.mod3))
 abline(v=log(0.0000001))           # cannot see anything of value on original scale
 abline(v=log(0.000001))