简体   繁体   English

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

[英]R - how do you get breakpoints in segmented function programatically?

Using the mtcars data set, I am trying to determine the broken line regression fit of mpg as a function of hp and wt, with breakpoints. 使用mtcars数据集,我试图确定mpg的折线回归拟合与hp和wt以及断点的关系。 Here is the code: 这是代码:

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)

How can I get the breakpoints programmatically? 如何以编程方式获取断点?

Figured this out, following does the trick: 想通了,以下是窍门:

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

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

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