使用 R Studio 的子集

Subset using R Studio

如果我不希望所有观察结果都包含在 R 中,如何使用 R 计算 ADF 检验? 我的时间序列包含 3000 个观察值。现在我想为 200 个第一个观察值计算 ADF 测试。我尝试了以下操作:来自包 urcalibrary(urca)ur.df(x, lags=5, selectlags="AIC", type="drift", subset=1:200),但我收到以下错误消息:

Error in summary(ur.df(Vstoxx, lags = 5, selectlags = "AIC", type = "drift",  : 
  Fehler bei der Auswertung des Argumentes 'object' bei der Methodenauswahl
for function 'summary': Error in ur.df(Vstoxx, lags = 5, selectlags = "AIC", type = "drift", subset = 1:200) : 
  unused argument (subset = 1:200)

其中德语部分翻译为:在方法选择中评估参数 'object' 期间出错。 这是一个小数据样本:

x
1   14.4700
2   14.5100
3   14.4200
4   13.8000
5   13.5700
6   12.9200
7   13.6800
8   14.0500
9   13.6400
10  13.5700
11  13.2000
12  13.1700
13  13.6300
14  14.1700
15  13.9600
16  14.1100
17  13.6300
18  13.3200
19  12.4600
20  12.8100
21  12.7200
22  12.3600
23  12.2500
24  12.3800
25  11.6000
26  11.9900
27  11.9200
28  12.1900
29  12.0400
30  11.9900
31  12.5200
32  12.3500
33  13.6600
34  13.5700
35  13.0100
36  13.2400
37  13.4900
38  13.9900
39  13.1900
40  12.2100
41  12.8900
42  12.3500
43  12.8600
44  12.5700
45  11.9300
46  11.7200
47  12.0000
48  12.5300
49  13.4700
50  12.9600
51  13.3500
52  12.4900
53  14.5700

非常感谢

无需添加 subset= 参数,您可以简单地使用索引对 x 进行子集化(参见下面我的示例)

x <- c(14.4700, 14.5100, 14.4200, 13.8000, 13.5700, 12.9200, 13.6800,
       14.0500, 13.6400, 13.5700, 13.2000, 13.1700, 13.6300, 14.1700, 13.9600, 
       14.1100, 13.6300, 13.3200, 12.4600, 12.8100, 12.7200, 12.3600, 12.2500, 12.3800, 
       11.6000, 11.9900, 11.9200, 12.1900, 12.0400, 11.9900, 12.5200, 12.3500, 13.6600, 
       13.5700, 13.0100, 13.2400, 13.4900, 13.9900, 13.1900, 12.2100, 12.8900, 12.3500, 
       12.8600, 12.5700, 11.9300, 11.7200, 12.0000, 12.5300, 13.4700, 12.9600, 13.3500, 
       12.4900, 14.5700)

library(urca)

# We'll use only the 50 first elements in x
ur.df(x[1:50], lags=5, selectlags="AIC", type="drift")

输出:

############################################################### 
# Augmented Dickey-Fuller Test Unit Root / Cointegration Test # 
############################################################### 

The value of the test statistic is: -2.1741 2.3635