Reputation: 2283
I use the following time series:
Lines <- "D1,Value
1,20/11/2014 16:00,0.01
2,20/11/2014 17:00,0.01
3,20/11/2014 19:00,0.01
4,20/11/2014 22:00,0.20
5,20/11/2014 23:00,0.03"
library (zoo)
library (strucchange)
z <- read.zoo(text = Lines, tz = "", format = "%d/%m/%Y %H:%M", sep = ",")
bp <- breakpoints(z ~ 1, h = 2)
plot(z)
abline(v = time(z)[bp$breakpoints])
I would like to add to the graph for each segment the fitted model and in addition to create a dataframe that has the intercept and the slope of the fitted model. For the fitted model per segment graph I tried to use the following:
lines(z, fitted(bp, breaks = 1), col = 2, lwd = 2)
but there is no line. For the dataframe I tried to use:
coef(bp, breaks = 1)
However, I need the slope as well.
Upvotes: 2
Views: 75
Reputation: 269694
It seems that breakpoints returns a "ts"
object even if the input is zoo so try this:
fit <- zoo(fitted(bp), time(z))
lines(fit, col = "blue", lty = 2, lwd = 2)
Upvotes: 3