ARIMA 预测 auto.Arima() 和 xreg 问题
ARIMA forecasting with auto.Arima() and xreg problem
我正在使用 auto.arima 处理大型数据集。数据集充满了零。
大多数排名不足的问题都可以,但是,我仍然不知道如何处理 'NN type' 的数据。它与 'PP type' 非常相似(它计算正常)。
NN 类型在我的数据中非常罕见。任何想法如何解决这个问题,或者至少如何快速检测 NN 类型?
library(forecast)
NN<-matrix(c(2, 2,2, 1, 1,1 ,
0, 0,0,0,0,1 ,
0, 0,0,1,1,0),
nrow=6)
PP<-matrix(c(2, 2,2, 1, 1,1 ,
0, 0,0,0,0,1 ,
0, 0,1,1,1,0),
nrow=6)
qty<-rpois(6,3000)
auto.arima(qty)
auto.arima(qty, xreg=PP)
auto.arima(qty, xreg=NN)
分析auto.arima
函数的代码,不难发现用来检查矩阵秩亏的代码。我建议以下功能:
is.rankdeficient <- function(xregg) {
constant_columns <- apply(xregg, 2, is.constant)
if (any(constant_columns)) {
xregg <- xregg[, -which(constant_columns)[1]]
}
sv <- svd(na.omit(cbind(rep(1, NROW(xregg)), xregg)))$d
min(sv)/sum(sv) < .Machine$double.eps
}
is.rankdeficient(PP)
# [1] FALSE
is.rankdeficient(NN)
# [1] TRUE
我正在使用 auto.arima 处理大型数据集。数据集充满了零。 大多数排名不足的问题都可以,但是,我仍然不知道如何处理 'NN type' 的数据。它与 'PP type' 非常相似(它计算正常)。 NN 类型在我的数据中非常罕见。任何想法如何解决这个问题,或者至少如何快速检测 NN 类型?
library(forecast)
NN<-matrix(c(2, 2,2, 1, 1,1 ,
0, 0,0,0,0,1 ,
0, 0,0,1,1,0),
nrow=6)
PP<-matrix(c(2, 2,2, 1, 1,1 ,
0, 0,0,0,0,1 ,
0, 0,1,1,1,0),
nrow=6)
qty<-rpois(6,3000)
auto.arima(qty)
auto.arima(qty, xreg=PP)
auto.arima(qty, xreg=NN)
分析auto.arima
函数的代码,不难发现用来检查矩阵秩亏的代码。我建议以下功能:
is.rankdeficient <- function(xregg) {
constant_columns <- apply(xregg, 2, is.constant)
if (any(constant_columns)) {
xregg <- xregg[, -which(constant_columns)[1]]
}
sv <- svd(na.omit(cbind(rep(1, NROW(xregg)), xregg)))$d
min(sv)/sum(sv) < .Machine$double.eps
}
is.rankdeficient(PP)
# [1] FALSE
is.rankdeficient(NN)
# [1] TRUE