if (N <= 0) NULL else seq(N) 错误:缺少 TRUE/FALSE 需要的值
Error in if (N <= 0) NULL else seq(N) : missing value where TRUE/FALSE needed
maxP <- 2
maxQ <- 2
AIC <- matrix(0,nrow=maxP,ncol=maxQ)
BIC <- matrix(0,nrow=maxP,ncol=maxQ)
HQC <- matrix(0,nrow=maxP,ncol=maxQ)
# Save all information criteria
for (p in 0:maxP){
for(q in 0:maxQ){
if (p>0) {ARLags <- 1:p}
else {ARLags <- 0}
if (q>0) {MALags <- 1:q}
else{MALags <- 0}
# Estimate the model
CPI_fit <- arma(CPI, order(ARLags, MALags, include.intercept = TRUE)
# Save the criteria in a P x Q matrix
AIC[p+1, q+1] <- CPI_fit$aic
BIC[p+1, q+1] <- CPI_fit$bic
}
}
AIC
BIC
我正在尝试对 select ARMA 模型的模型规范进行自动处理,但我总是收到此错误消息:
Error in if (N <= 0) NULL else seq(N) :
missing value where TRUE/FALSE needed
这是什么意思,我该如何预防?
我假设您正在使用 tseries::arma
。
问题出在调用
arma(CPI, order(ARLags, MALags), include.intercept = TRUE)
您可以通过调用traceback()
找到调用错误的原因。这为我们提供了错误的线索:
2: seqN(order[2])
1: arma(CPI, order(ARLags, MALags), include.intercept = TRUE)
arma
的第二个形式是 order
,您已经提供了 order(ARLags, MALags)
。这意味着对于函数调用,我们有
order = order(ARLags, MALags)
来自上面使用的函数order
的description:
order
returns a permutation which rearranges its first argument into ascending or descending order, breaking ties by further arguments. sort.list
is the same, using only one argument.
(强调我的)这个排列用于对数据进行排序,是一个与输入长度相同的向量。同时,tseries::arma
、according to the help page:
中的正式
order
a two dimensional integer vector giving the orders of the model to fit. order[1]
corresponds to the AR part and order[2]
to the MA part.
这就是冲突。 arma
需要一个 二维整数向量 但提供了一个 一维向量 因为 p = 0
然后 ARlags = 0
和 order(0) = 1
.
您要提供 arma
的是 order = c(p,q)
- AR 和 MA 部分中的最大滞后项。试试这个
CPI_fit <- arma(CPI, c(p, q), include.intercept = TRUE)
maxP <- 2
maxQ <- 2
AIC <- matrix(0,nrow=maxP,ncol=maxQ)
BIC <- matrix(0,nrow=maxP,ncol=maxQ)
HQC <- matrix(0,nrow=maxP,ncol=maxQ)
# Save all information criteria
for (p in 0:maxP){
for(q in 0:maxQ){
if (p>0) {ARLags <- 1:p}
else {ARLags <- 0}
if (q>0) {MALags <- 1:q}
else{MALags <- 0}
# Estimate the model
CPI_fit <- arma(CPI, order(ARLags, MALags, include.intercept = TRUE)
# Save the criteria in a P x Q matrix
AIC[p+1, q+1] <- CPI_fit$aic
BIC[p+1, q+1] <- CPI_fit$bic
}
}
AIC
BIC
我正在尝试对 select ARMA 模型的模型规范进行自动处理,但我总是收到此错误消息:
Error in if (N <= 0) NULL else seq(N) :
missing value where TRUE/FALSE needed
这是什么意思,我该如何预防?
我假设您正在使用 tseries::arma
。
问题出在调用
arma(CPI, order(ARLags, MALags), include.intercept = TRUE)
您可以通过调用traceback()
找到调用错误的原因。这为我们提供了错误的线索:
2: seqN(order[2])
1: arma(CPI, order(ARLags, MALags), include.intercept = TRUE)
arma
的第二个形式是 order
,您已经提供了 order(ARLags, MALags)
。这意味着对于函数调用,我们有
order = order(ARLags, MALags)
来自上面使用的函数order
的description:
order
returns a permutation which rearranges its first argument into ascending or descending order, breaking ties by further arguments.sort.list
is the same, using only one argument.
(强调我的)这个排列用于对数据进行排序,是一个与输入长度相同的向量。同时,tseries::arma
、according to the help page:
order
a two dimensional integer vector giving the orders of the model to fit.order[1]
corresponds to the AR part andorder[2]
to the MA part.
这就是冲突。 arma
需要一个 二维整数向量 但提供了一个 一维向量 因为 p = 0
然后 ARlags = 0
和 order(0) = 1
.
您要提供 arma
的是 order = c(p,q)
- AR 和 MA 部分中的最大滞后项。试试这个
CPI_fit <- arma(CPI, c(p, q), include.intercept = TRUE)