Reputation: 185
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?
Upvotes: 0
Views: 1094
Reputation: 185
Figured this out, following does the trick:
summary.segmented(seg.o)$psi [1,2]
summary.segmented(seg.o)$psi [2,2]
Upvotes: 1