auto.arima 个以上 ts 的残差

auto.arima residuals for more than one ts

我正在尝试编写一个函数,它给出 auto.arima 的残差以应用 Box-Ljung 检验。我试过 lapply() 但我现在不知道如何使用它来获取每个系列的残差。

library(fpp2)

#Make up some Time Series
dj1=dj
dj2=dj+2
dj3=dj+7


dataframe=cbind(dj1,dj2,dj3)
dataframe=as.data.frame(dataframe)


#Return calculation
Ret=diff(log(as.matrix(dataframe)),1)
Ret=as.data.frame(Ret)

AutoArima= lapply(Ret, function(x) auto.arima(x))
AutoArima

我想要一个 matrix/dataframe 包含 3 列 dj1dj2dj3 和 291 行(其中包含每列的残差)。

我能够计算单个时间序列的残差,但不能为每个序列组织成 dataframe/matrix。我尝试了一些其他的东西,但它给出了: Error in auto.arima(x) : auto.arima can only handle univariate time series

如有任何帮助,我们将不胜感激。

这对我有用:

library(purrr) 
df = map_df(AutoArima[1:ncol(Ret)],resid)

您可以将这两行添加到您的代码中

res=lapply(AutoArima,function(x) x$residuals)
res0=do.call("cbind",res)

我认为 res0 就是您要查找的内容