循环自回归输出时出错
Error looping through autoregression outputs
我正在尝试为已经差分的时间序列创建自回归模型。
我想将下面的代码放在一个循环中,以免重复。
gas_ar_date <- arima(diff_gas[[1]], order = c(1, 0, 0))
print("AR for Date")
gas_ar_date
print("******************************************")
gas_ar_change <- arima(diff_gas[[2]], order = c(1, 0, 0))
print("AR for Currency Change")
gas_ar_change
print("******************************************")
gas_ar_domestic <- arima(diff_gas[[3]], order = c(1, 0, 0))
print("AR for UK Domestic Production")
gas_ar_domestic
print("******************************************")
gas_ar_import <- arima(diff_gas[[4]], order = c(1, 0, 0))
print("AR for Import")
gas_ar_import
print("******************************************")
然而,当我尝试时:
for (i in 1:8) {
gas_ar[i] <- arima(diff_gas[[i]], order = c(1, 0, 0))
gas_ar[i]
}
我收到错误:
number of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement length
在这种情况下如何创建循环并获得 ARIMA 自回归模型的完整输出?
以下是数据概览:
如果你 str(fit1)
它应该是“14 人名单”
所以要么
gas_ar[[i]] <- arima(diff_gas[[i]], order = c(1, 0, 0))
或
gas_ar[i] <- list(arima(diff_gas[[i]], order = c(1, 0, 0)))
应该可以。
我不是 R 专家,但看起来您可以执行以下操作:
list<-c('date','change','domestic','import')
for (i in 1:4) {
paste('gas_ar',list[i],sep="") <- arima(diff_gas[[i]], order = c(1, 0, 0))
}
我正在尝试为已经差分的时间序列创建自回归模型。
我想将下面的代码放在一个循环中,以免重复。
gas_ar_date <- arima(diff_gas[[1]], order = c(1, 0, 0))
print("AR for Date")
gas_ar_date
print("******************************************")
gas_ar_change <- arima(diff_gas[[2]], order = c(1, 0, 0))
print("AR for Currency Change")
gas_ar_change
print("******************************************")
gas_ar_domestic <- arima(diff_gas[[3]], order = c(1, 0, 0))
print("AR for UK Domestic Production")
gas_ar_domestic
print("******************************************")
gas_ar_import <- arima(diff_gas[[4]], order = c(1, 0, 0))
print("AR for Import")
gas_ar_import
print("******************************************")
然而,当我尝试时:
for (i in 1:8) {
gas_ar[i] <- arima(diff_gas[[i]], order = c(1, 0, 0))
gas_ar[i]
}
我收到错误:
number of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement length
在这种情况下如何创建循环并获得 ARIMA 自回归模型的完整输出?
以下是数据概览:
如果你 str(fit1)
它应该是“14 人名单”
所以要么
gas_ar[[i]] <- arima(diff_gas[[i]], order = c(1, 0, 0))
或
gas_ar[i] <- list(arima(diff_gas[[i]], order = c(1, 0, 0)))
应该可以。
我不是 R 专家,但看起来您可以执行以下操作:
list<-c('date','change','domestic','import')
for (i in 1:4) {
paste('gas_ar',list[i],sep="") <- arima(diff_gas[[i]], order = c(1, 0, 0))
}