arima$residuals 不包含日期
arima$residuals does not contain dates
绘制残差的拟合 arima() 函数我没有在 x 轴上得到索引(日期)。寻找答案的常见问题是人们可能还需要预测的日期。我只想要它用于拟合残差,以前似乎没有提出过这个问题。
这是我的数据集的前六行:
structure(c(-8.810021, 1.45281, -9.051401, 4.628075, -1.774445,
-5.25055, -4.08219945, -0.17376199, 1.32681098, 3.7986923, -0.03966156,
0.1651528, -3.989133, 0.1787311, -1.620197, 5.645238, 0.3424661,
-1.203798, -3.813763, -2.360084, 1.391327, 7.280618, -1.841673,
-1.498155), class = c("xts", "zoo"), index = structure(c(946944000,
947030400, 947116800, 947203200, 947462400, 947548800), tzone = "UTC", tclass = "Date"), .Dim = c(6L,
4L), .Dimnames = list(NULL, c("AAPL", "GE", "SPY", "WMT")))
对于 SPY 的数据,我找到了一个我想使用 arima() 继续使用的模型:
fitSPY<-arima(SMinexts[,"SPY"],order = c(1,0,3))
我可以使用几个函数来绘制残差。这里有两个:
checkresiduals(fitSPY)
plot(fitSPY)
我的问题是,我在绘制残差时没有得到 x 轴上的日期,就像我在其他地方看到的那样,例如:https://otexts.com/fpp2/regarima.html.
来自 fitSPY 的 str 我猜问题是时间序列日期被注册为 [1-4024] 而不是数据集的日期。我只是不知道如何解决这个问题。
> str(fitSPY)
List of 14
$ coef : Named num [1:5] -0.9179 0.8524 -0.1318 -0.0784 0.0165
..- attr(*, "names")= chr [1:5] "ar1" "ma1" "ma2" "ma3" ...
$ sigma2 : num 1.6
$ var.coef : num [1:5, 1:5] 2.75e-03 -2.72e-03 1.78e-04 2.24e-05 2.04e-07 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:5] "ar1" "ma1" "ma2" "ma3" ...
.. ..$ : chr [1:5] "ar1" "ma1" "ma2" "ma3" ...
$ mask : logi [1:5] TRUE TRUE TRUE TRUE TRUE
$ loglik : num -6657
$ aic : num 13326
$ arma : int [1:7] 1 3 0 0 1 0 0
$ residuals: Time-Series [1:4024] from 1 to 4024: -3.9849 -0.0787 -1.9213 5.4402 0.5981 ...
$ call : language arima(x = SMinexts[, "SPY"], order = c(1, 0, 3))
$ series : chr "SMinexts[, \"SPY\"]"
$ code : int 1
$ n.cond : int 0
$ nobs : int 4024
$ model :List of 10
..$ phi : num -0.918
..$ theta: num [1:3] 0.8524 -0.1318 -0.0784
..$ Delta: num(0)
..$ Z : num [1:4] 1 0 0 0
..$ a : num [1:4] -1.0219 -0.8423 0.1836 0.0782
..$ P : num [1:4, 1:4] 0 0 0 0 0 ...
..$ T : num [1:4, 1:4] -0.918 0 0 0 1 ...
..$ V : num [1:4, 1:4] 1 0.8524 -0.1318 -0.0784 0.8524 ...
..$ h : num 0
..$ Pn : num [1:4, 1:4] 1 0.8524 -0.1318 -0.0784 0.8524 ...
- attr(*, "class")= chr "Arima"
希望你能帮帮我。
您可以使用原始数据和绘图中的索引将残差作为 xts 对象。
resid <- xts(fitSPY$residuals, index(SMinexts))
plot(resid, observation.based =TRUE, yaxis.right = FALSE)
您也可以将索引强制转换为列表中的残差
fitSPY$residuals <- xts(fitSPY$residuals, index(SMinexts))
绘制残差的拟合 arima() 函数我没有在 x 轴上得到索引(日期)。寻找答案的常见问题是人们可能还需要预测的日期。我只想要它用于拟合残差,以前似乎没有提出过这个问题。
这是我的数据集的前六行:
structure(c(-8.810021, 1.45281, -9.051401, 4.628075, -1.774445,
-5.25055, -4.08219945, -0.17376199, 1.32681098, 3.7986923, -0.03966156,
0.1651528, -3.989133, 0.1787311, -1.620197, 5.645238, 0.3424661,
-1.203798, -3.813763, -2.360084, 1.391327, 7.280618, -1.841673,
-1.498155), class = c("xts", "zoo"), index = structure(c(946944000,
947030400, 947116800, 947203200, 947462400, 947548800), tzone = "UTC", tclass = "Date"), .Dim = c(6L,
4L), .Dimnames = list(NULL, c("AAPL", "GE", "SPY", "WMT")))
对于 SPY 的数据,我找到了一个我想使用 arima() 继续使用的模型:
fitSPY<-arima(SMinexts[,"SPY"],order = c(1,0,3))
我可以使用几个函数来绘制残差。这里有两个:
checkresiduals(fitSPY)
plot(fitSPY)
我的问题是,我在绘制残差时没有得到 x 轴上的日期,就像我在其他地方看到的那样,例如:https://otexts.com/fpp2/regarima.html.
来自 fitSPY 的 str 我猜问题是时间序列日期被注册为 [1-4024] 而不是数据集的日期。我只是不知道如何解决这个问题。
> str(fitSPY)
List of 14
$ coef : Named num [1:5] -0.9179 0.8524 -0.1318 -0.0784 0.0165
..- attr(*, "names")= chr [1:5] "ar1" "ma1" "ma2" "ma3" ...
$ sigma2 : num 1.6
$ var.coef : num [1:5, 1:5] 2.75e-03 -2.72e-03 1.78e-04 2.24e-05 2.04e-07 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:5] "ar1" "ma1" "ma2" "ma3" ...
.. ..$ : chr [1:5] "ar1" "ma1" "ma2" "ma3" ...
$ mask : logi [1:5] TRUE TRUE TRUE TRUE TRUE
$ loglik : num -6657
$ aic : num 13326
$ arma : int [1:7] 1 3 0 0 1 0 0
$ residuals: Time-Series [1:4024] from 1 to 4024: -3.9849 -0.0787 -1.9213 5.4402 0.5981 ...
$ call : language arima(x = SMinexts[, "SPY"], order = c(1, 0, 3))
$ series : chr "SMinexts[, \"SPY\"]"
$ code : int 1
$ n.cond : int 0
$ nobs : int 4024
$ model :List of 10
..$ phi : num -0.918
..$ theta: num [1:3] 0.8524 -0.1318 -0.0784
..$ Delta: num(0)
..$ Z : num [1:4] 1 0 0 0
..$ a : num [1:4] -1.0219 -0.8423 0.1836 0.0782
..$ P : num [1:4, 1:4] 0 0 0 0 0 ...
..$ T : num [1:4, 1:4] -0.918 0 0 0 1 ...
..$ V : num [1:4, 1:4] 1 0.8524 -0.1318 -0.0784 0.8524 ...
..$ h : num 0
..$ Pn : num [1:4, 1:4] 1 0.8524 -0.1318 -0.0784 0.8524 ...
- attr(*, "class")= chr "Arima"
希望你能帮帮我。
您可以使用原始数据和绘图中的索引将残差作为 xts 对象。
resid <- xts(fitSPY$residuals, index(SMinexts))
plot(resid, observation.based =TRUE, yaxis.right = FALSE)
您也可以将索引强制转换为列表中的残差
fitSPY$residuals <- xts(fitSPY$residuals, index(SMinexts))