在 R 中使用 ts 异常值检测异常值
Outier detection using tsoutlier in R
我正在尝试使用 ARIMA 模型预测 Nifty 的每周股价。可以下载数据here。我尝试了以下三种情况:
第一种情况: 我使用 tsoutliers 包中的 tso
函数来识别异常值(如果有)并拟合 ARIMA 模型。我得到的结果为 ARIMA(1,1,1),没有检测到异常值。最小代码:
outliers1 <- tso(close, tsmethod = c("auto.arima"), args.tsmethod = list(allowdrift=TRUE))
获得的结果:
ARIMA(1,1,1)
Coefficients:
ar1 ma1
0.6112 -0.5684
s.e. 0.3496 0.3632
sigma^2 estimated as 25268: log likelihood=-2523.68
AIC=5053.35 AICc=5053.41 BIC=5065.24
No outliers were detected.
第二种情况: 由于没有检测到异常值,我使用预测包中的 auto.arima()
来查看我得到的模型。正如之前帖子中所建议的那样,我逐步逼近了 FALSE。我获得了 ARIMA (3,1,2) 模型。最小代码:
close <- read.ts("close.csv", header = FALSE")
fit <- auto.arima(close, stepwise = FALSE, trace = TRUE, approximation = FALSE)
获得的结果:
Series: close
ARIMA(3,1,2) with drift
Coefficients:
ar1 ar2 ar3 ma1 ma2 drift
-1.7302 -0.7838 0.0624 1.7730 0.9097 10.4769
s.e. 0.0695 0.1125 0.0578 0.0483 0.0475 8.4509
sigma^2 estimated as 24413: log likelihood=-2510.18
AIC=5034.37 AICc=5034.66 BIC=5062.11
第三种情况: 在我的第三种情况下,我尝试使用在 tso 中的第二种情况下获得的 ARIMA(3,1,2) 来检查任何异常值。但是该模型没有检测到异常值。最小代码:
outlier2 <- tso(close, maxit = 10, tsmethod = c("arima"), args.tsmethod = list(order =c(3,1,2)))
获得的结果:
Coefficients:
ar1 ar2 ar3 ma1 ma2
-0.2224 0.3573 -0.0186 0.2451 -0.2548
s.e. 0.7914 0.4344 0.1107 0.7884 0.4603
sigma^2 estimated as 24986: log likelihood = -2521.51, aic = 5055.02
No outliers were detected.
我的问题是,如果数据中没有任何异常值,那么为什么情况 1 和情况 2 的结果不同。我在模型构建中是否遗漏了什么?此外,同时使用 ARIMA (3,1,2) 和 (1,1,1) 获得的预测结果很差。
在第一种情况下 tso
使用默认参数 stepwise=TRUE
。在第二种情况下,您设置 stepwise=FALSE
。这可能导致对 ARIMA 模型的不同选择。在 tso
中通过参数 args.tsmethod
传递 stepwise=FALSE
应该会产生相同的结果(除非为该模型找到异常值)。
我正在尝试使用 ARIMA 模型预测 Nifty 的每周股价。可以下载数据here。我尝试了以下三种情况:
第一种情况: 我使用 tsoutliers 包中的 tso
函数来识别异常值(如果有)并拟合 ARIMA 模型。我得到的结果为 ARIMA(1,1,1),没有检测到异常值。最小代码:
outliers1 <- tso(close, tsmethod = c("auto.arima"), args.tsmethod = list(allowdrift=TRUE))
获得的结果:
ARIMA(1,1,1)
Coefficients:
ar1 ma1
0.6112 -0.5684
s.e. 0.3496 0.3632
sigma^2 estimated as 25268: log likelihood=-2523.68
AIC=5053.35 AICc=5053.41 BIC=5065.24
No outliers were detected.
第二种情况: 由于没有检测到异常值,我使用预测包中的 auto.arima()
来查看我得到的模型。正如之前帖子中所建议的那样,我逐步逼近了 FALSE。我获得了 ARIMA (3,1,2) 模型。最小代码:
close <- read.ts("close.csv", header = FALSE")
fit <- auto.arima(close, stepwise = FALSE, trace = TRUE, approximation = FALSE)
获得的结果:
Series: close
ARIMA(3,1,2) with drift
Coefficients:
ar1 ar2 ar3 ma1 ma2 drift
-1.7302 -0.7838 0.0624 1.7730 0.9097 10.4769
s.e. 0.0695 0.1125 0.0578 0.0483 0.0475 8.4509
sigma^2 estimated as 24413: log likelihood=-2510.18
AIC=5034.37 AICc=5034.66 BIC=5062.11
第三种情况: 在我的第三种情况下,我尝试使用在 tso 中的第二种情况下获得的 ARIMA(3,1,2) 来检查任何异常值。但是该模型没有检测到异常值。最小代码:
outlier2 <- tso(close, maxit = 10, tsmethod = c("arima"), args.tsmethod = list(order =c(3,1,2)))
获得的结果:
Coefficients:
ar1 ar2 ar3 ma1 ma2
-0.2224 0.3573 -0.0186 0.2451 -0.2548
s.e. 0.7914 0.4344 0.1107 0.7884 0.4603
sigma^2 estimated as 24986: log likelihood = -2521.51, aic = 5055.02
No outliers were detected.
我的问题是,如果数据中没有任何异常值,那么为什么情况 1 和情况 2 的结果不同。我在模型构建中是否遗漏了什么?此外,同时使用 ARIMA (3,1,2) 和 (1,1,1) 获得的预测结果很差。
在第一种情况下 tso
使用默认参数 stepwise=TRUE
。在第二种情况下,您设置 stepwise=FALSE
。这可能导致对 ARIMA 模型的不同选择。在 tso
中通过参数 args.tsmethod
传递 stepwise=FALSE
应该会产生相同的结果(除非为该模型找到异常值)。