添加人工断点
Adding artificial breakpoints
我有以下时间序列:
Lines <- "Hour,PF
0,14/01/2015 00:00,0.305
1,14/01/2015 01:00,0.306
2,14/01/2015 02:00,0.307
3,14/01/2015 03:00,0.3081
4,14/01/2015 04:00,0.3091
5,14/01/2015 05:00,0.3101
6,14/01/2015 06:00,0.3111
7,14/01/2015 07:00,0.3122
8,14/01/2015 08:00,0.455
9,14/01/2015 09:00,0.7103
10,14/01/2015 10:00,0.9656
11,14/01/2015 11:00,1
12,14/01/2015 12:00,0.9738
13,14/01/2015 13:00,0.9476
14,14/01/2015 14:00,0.9213
15,14/01/2015 15:00,0.8951
16,14/01/2015 16:00,0.8689
17,14/01/2015 17:00,0.8427
18,14/01/2015 18:00,0.6956
19,14/01/2015 19:00,0.6006
20,14/01/2015 20:00,0.5056
21,14/01/2015 21:00,0.4106
22,14/01/2015 22:00,0.3157
23,14/01/2015 23:00,0.3157"
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])
The Breakpoints are at observation number:
8 10 18 21
现在假设我有相同的时间序列,但在观察编号 11 - 缺少 24 小时。我想定义 Gap
(在这种情况下 =24 小时)并找到与前面示例中的相关断点,在间隙的开始和结束处有 2 个额外的断点。对于以下时间序列,断点将是:
8 10 12 13 18 21
这是有间隙的时间序列:
Lines <- "Hour,PF
0,14/01/2015 00:00,0.305
1,14/01/2015 01:00,0.306
2,14/01/2015 02:00,0.307
3,14/01/2015 03:00,0.3081
4,14/01/2015 04:00,0.3091
5,14/01/2015 05:00,0.3101
6,14/01/2015 06:00,0.3111
7,14/01/2015 07:00,0.3122
8,14/01/2015 08:00,0.455
9,14/01/2015 09:00,0.7103
10,14/01/2015 10:00,0.9656
11,14/01/2015 11:00,1 <---
12,15/01/2015 12:00,0.9738 <--- GAP of 24 hours
13,15/01/2015 13:00,0.9476
14,15/01/2015 14:00,0.9213
15,15/01/2015 15:00,0.8951
16,15/01/2015 16:00,0.8689
17,15/01/2015 17:00,0.8427
18,15/01/2015 18:00,0.6956
19,15/01/2015 19:00,0.6006
20,15/01/2015 20:00,0.5056
21,15/01/2015 21:00,0.4106
22,15/01/2015 22:00,0.3157
23,15/01/2015 23:00,0.3157"
你的差距实际上是整整一个月(14/01 to14/02)。
c(0,1)+which.max(diff(time(z))) # 12,13
将 return 可以附加到断点的最大间隙的索引。
注意:差距的起点和终点是 12,13 而不是 11,12,因为 R 中的索引从 1 开始。
我有以下时间序列:
Lines <- "Hour,PF
0,14/01/2015 00:00,0.305
1,14/01/2015 01:00,0.306
2,14/01/2015 02:00,0.307
3,14/01/2015 03:00,0.3081
4,14/01/2015 04:00,0.3091
5,14/01/2015 05:00,0.3101
6,14/01/2015 06:00,0.3111
7,14/01/2015 07:00,0.3122
8,14/01/2015 08:00,0.455
9,14/01/2015 09:00,0.7103
10,14/01/2015 10:00,0.9656
11,14/01/2015 11:00,1
12,14/01/2015 12:00,0.9738
13,14/01/2015 13:00,0.9476
14,14/01/2015 14:00,0.9213
15,14/01/2015 15:00,0.8951
16,14/01/2015 16:00,0.8689
17,14/01/2015 17:00,0.8427
18,14/01/2015 18:00,0.6956
19,14/01/2015 19:00,0.6006
20,14/01/2015 20:00,0.5056
21,14/01/2015 21:00,0.4106
22,14/01/2015 22:00,0.3157
23,14/01/2015 23:00,0.3157"
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])
The Breakpoints are at observation number:
8 10 18 21
现在假设我有相同的时间序列,但在观察编号 11 - 缺少 24 小时。我想定义 Gap
(在这种情况下 =24 小时)并找到与前面示例中的相关断点,在间隙的开始和结束处有 2 个额外的断点。对于以下时间序列,断点将是:
8 10 12 13 18 21
这是有间隙的时间序列:
Lines <- "Hour,PF
0,14/01/2015 00:00,0.305
1,14/01/2015 01:00,0.306
2,14/01/2015 02:00,0.307
3,14/01/2015 03:00,0.3081
4,14/01/2015 04:00,0.3091
5,14/01/2015 05:00,0.3101
6,14/01/2015 06:00,0.3111
7,14/01/2015 07:00,0.3122
8,14/01/2015 08:00,0.455
9,14/01/2015 09:00,0.7103
10,14/01/2015 10:00,0.9656
11,14/01/2015 11:00,1 <---
12,15/01/2015 12:00,0.9738 <--- GAP of 24 hours
13,15/01/2015 13:00,0.9476
14,15/01/2015 14:00,0.9213
15,15/01/2015 15:00,0.8951
16,15/01/2015 16:00,0.8689
17,15/01/2015 17:00,0.8427
18,15/01/2015 18:00,0.6956
19,15/01/2015 19:00,0.6006
20,15/01/2015 20:00,0.5056
21,15/01/2015 21:00,0.4106
22,15/01/2015 22:00,0.3157
23,15/01/2015 23:00,0.3157"
你的差距实际上是整整一个月(14/01 to14/02)。
c(0,1)+which.max(diff(time(z))) # 12,13
将 return 可以附加到断点的最大间隙的索引。
注意:差距的起点和终点是 12,13 而不是 11,12,因为 R 中的索引从 1 开始。