gpt4 book ai didi

r - 为什么时间序列没有断点

转载 作者:行者123 更新时间:2023-12-05 05:24:25 25 4
gpt4 key购买 nike

我有以下时间序列:

Lines <- "D1,Diff
1,14/01/2015 00:00,0.03
2,14/01/2015 01:00,0.03
3,14/01/2015 02:00,0.01
4,14/01/2015 03:00,0.02
5,14/01/2015 04:00,0.03
6,14/01/2015 05:00,0.02
7,14/01/2015 06:00,0.01
8,14/01/2015 07:00,0.03
9,14/01/2015 08:00,0.02
10,14/01/2015 09:00,0.01
11,14/01/2015 10:00,0.03
12,14/01/2015 11:00,0.03
13,14/01/2015 12:00,0.03
14,14/01/2015 13:00,0.02
15,14/01/2015 14:00,0.01
16,14/01/2015 15:00,0.03
17,14/01/2015 16:00,0.03
18,14/01/2015 17:00,0.03
19,14/01/2015 18:00,0.01
20,14/01/2015 19:00,0.02
21,14/01/2015 20:00,0.03
22,14/01/2015 21:00,0.03
23,14/01/2015 22:00,0.02
24,14/01/2015 23:00,0.01
25,15/01/2015 00:00,0.03
26,15/01/2015 01:00,0.02
27,15/01/2015 02:00,0.03
28,15/01/2015 03:00,0
29,15/01/2015 04:00,0.03
30,15/01/2015 05:00,0.03
31,15/01/2015 06:00,0.03
32,15/01/2015 07:00,0
33,15/01/2015 08:00,0.03
34,15/01/2015 09:00,0.03
35,15/01/2015 10:00,0.03
36,15/01/2015 11:00,0.01
37,15/01/2015 12:00,0.02
38,15/01/2015 13:00,0.03
39,15/01/2015 14:00,0.03
40,15/01/2015 15:00,0.03
41,15/01/2015 16:00,0.02
42,15/01/2015 17:00,0.01
43,15/01/2015 18:00,0.03
44,15/01/2015 19:00,0.03
45,15/01/2015 20:00,0.03
46,15/01/2015 21:00,0.01
47,15/01/2015 22:00,0.02
48,15/01/2015 23:00,0.03
49,16/01/2015 00:00,0.03
50,16/01/2015 01:00,0
51,16/01/2015 02:00,0.03
52,16/01/2015 03:00,0.03
53,16/01/2015 04:00,0.02
54,16/01/2015 05:00,0.01
55,16/01/2015 06:00,0.03
56,16/01/2015 07:00,0.03
57,16/01/2015 08:00,0
58,16/01/2015 09:00,0.03
59,16/01/2015 10:00,0.03
60,16/01/2015 11:00,0.01
61,16/01/2015 12:00,0.02
62,16/01/2015 13:00,0.03
63,16/01/2015 14:00,0.02
64,16/01/2015 15:00,0.01
65,16/01/2015 16:00,0.03
66,16/01/2015 17:00,0.03
67,16/01/2015 18:00,0
68,16/01/2015 19:00,0.03
69,16/01/2015 20:00,0.03
70,16/01/2015 21:00,0
71,16/01/2015 22:00,0.03
72,16/01/2015 23:00,0.02"

我使用以下命令:

library("strucchange")
z <- read.zoo(text = Lines, tz = "", format = "%d/%m/%Y %H:%M", sep = ",")
bp <- breakpoints(z~ 1, h = 36)
> bp

Optimal 1-segment partition:

Call:
breakpoints.formula(formula = z ~ 1, h = 36)

Breakpoints at observation number:
NA

Corresponding to breakdates:
NA

我想找到分割。每天我都会找到 Optimal 3-segment 分区。但是,在 3 天(72 小时)内没有找到任何片段。如何找到 12 个段(断点)?

最佳答案

关于断点(又名变点)检测,这里我借用了 Andrew Gelman 博士 (https://statmodeling.stat.columbia.edu/2016/03/18/i-definitely-wouldnt-frame-it-as-to-determine-if-the-time-series-has-a-change-point-or-not-the-time-series-whatever-it-is-has-a-change-point-at-every-time-the-question/) 的一篇博客文章的标题:

I definitely wouldn’t frame it as “To determine if the time series has a change-point or not.” The time series, whatever it is, has a change point at every time. The question might be, “Is a change point necessary to model these data?” That’s a question I could get behind.

因此,考虑到时间序列分割是基于模型的,何时出现断点以及出现多少断点或多或少取决于模型(例如,取决于假设);这也是为什么在 R 中有许多可供选择的断点检测模型的原因——同样的论点基本上适用于所有数据分析。话虽如此,以下是两个贝叶斯变点包的一些快速结果:bcpRbeast(作为免责声明,我开发了后者)。与那些寻求单组最佳断点位置的基于频率的模型不同,贝叶斯方法试图估计任何给定时间点发生断点的概率。

# Your sample time series; this is a pure data vector without the time info.
z = c( 0.03,0.03,0.01,0.02,0.03,0.02,0.01,0.03,0.02,0.01,0.03,0.03,0.03,0.02,0.01,0.03,
0.03,0.03,0.01,0.02,0.03,0.03,0.02,0.01,0.03,0.02,0.03,0.00,0.03,0.03,0.03,0.00,
0.03,0.03,0.03,0.01,0.02,0.03,0.03,0.03,0.02,0.01,0.03,0.03,0.03,0.01,0.02,0.03,
0.03,0.00,0.03,0.03,0.02,0.01,0.03,0.03,0.00,0.03,0.03,0.01,0.02,0.03,0.02,0.01,
0.03,0.03,0.00,0.03,0.03,0.00,0.03,0.02)

library(bcp)
out = bcp(z)
plot(out)

没有找到断点,如下图,但不知何故在后验概率曲线中,某处有一点点概率可以找到变化点。总体而言,表明断点的统计证据非常薄弱。

enter image description here

尝试使用 Rbeast,它旨在检测断点和分解时间序列(即,将季节性与趋势分开),但您的数据不包含周期性/季节性成分;这就是 season='none'beast 函数中使用的原因。

library(Rbeast)
out = beast(z, season='none')
plot(out)

同样,表明存在断点的总体证据很少,但 Rbeast 发现了一些比其他位置更可能是断点的位置,如 Pr( TCP)曲线。毫不奇怪,这些峰值概率的幅度非常小。平均而言,beast 找到 1 个断点,如果它必须精确定位其位置,最有可能的位置是最后一个峰值 - 垂直虚线标记的那个。

enter image description here

同样,如何分割时间序列取决于您如何定义断点。我很确定如果您尝试不同的方法,结果会有所不同。如果您打算查找任何具有字面变化(即不恒定)的位置。你可以尝试这样的事情

which(abs(diff(z)) >0.02)

如您所料,给出了 12 个断点(不确定这些是否是您期望看到的 12 个断点。

关于r - 为什么时间序列没有断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34840881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com