我使用以下时间序列:
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])
我想为每个段添加拟合模型的图形,另外创建一个具有截距和拟合模型斜率的数据框。 对于每段图表的拟合模型,我尝试使用以下内容:
lines(z, fitted(bp, breaks = 1), col = 2, lwd = 2)
但没有线。 对于我尝试使用的数据框:
coef(bp, breaks = 1)
但是,我也需要坡度。