R - 如何以编程方式获得分段函数中的断点?

时间:2016-04-14 17:25:04

标签: r regression

使用mtcars数据集,我试图确定mpg的断线回归拟合作为hp和wt的函数,带有断点。这是代码:

mpg = mtcars$mpg
wt = mtcars$wt
hp = mtcars$hp

reg = lm (mpg ~ hp +wt)

hp_thresh = 150
wt_thresh = 3

library(segmented)
seg.o = segmented (reg,seg.Z=~hp+wt, psi=list (hp=hp_thresh, wt=wt_thresh))
summary (seg.o)

如何以编程方式获取断点?

1 个答案:

答案 0 :(得分:1)

想出来,以下是诀窍:

summary.segmented(seg.o)$psi [1,2]
summary.segmented(seg.o)$psi [2,2]