How to export breakpoints index into a vector from strucchange package?
I'm using the strucchange package in order to determine where my curve model segments.
My code looks like this:
l.fit <- loess(data$y~data$x) px <- predict(l.fit,newdata=data$x) bp <- breakpoints(px~1)
Now, the output of bp:
Optimal 6-segment partition: Call: breakpoints.formula(formula = px ~ 1) Breakpoints at observation number: 161 254 347 440 533 Corresponding to breakdates: 0.2571885 0.4057508 0.5543131 0.7028754 0.8514377
The breakdates are kind of useless, as my x scale goes from 1 to 700 or so. But the breakpoints themselves are exactly what I want, specifically the last one, 533.
If i type:
$breakpoints  161 254 347 440 533
but if I try to assign bp to a new vector, I get nothing. Is there anyway I can isolate the last breakpoint, i.e. 533, and assign it to a variable so I can plot a vertical line at the breakpoint? I need to do this for a couple hundred datasets, so being able to isolate the breakpoints would be really useful.
[ extraction doesn't drop to the simpliest form, so it remains a list. Use [[ or $ extraction instead to get a numeric vector.
bps <- bp[]
bps <- bp$breakpoints
To get the last one, you would need to either count its length and select the last one, or reverse it and select the first: