简体   繁体   中英

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. 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]

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