时间序列段没有适合的模型行

时间:2016-01-28 19:33:47

标签: r time-series segment

我使用以下时间序列:

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)

但是,我也需要坡度。

1 个答案:

答案 0 :(得分:3)

即使输入是动物园,似乎断点返回"ts"对象,所以试试这个:

fit <- zoo(fitted(bp), time(z))
lines(fit, col = "blue", lty = 2, lwd = 2)

enter image description here