简体   繁体   English

为什么 predict(model, h=2) function 返回 NA 值(模型来自 R auto.arima())?

[英]Why forecast(model, h=2) function returns NA value (model is from R auto.arima())?

This R code predicts sp500 with arima model,这个 R 代码用 arima model 预测 sp500,

rm(list=ls())
load("StockData.Rdata")
library(seasonal)
library(forecast)
library(tseries)
library(astsa)
sp500 = StockData[,1]
model = auto.arima(sp500,
                     max.p=52,max.q=52,max.d=52,
                     seasonal = TRUE,
                     lambda = "auto", biasadj = TRUE)
predict = forecast(model,biasadj=TRUE, h=2)

Here, I want to use auto.arima with Box-Cox transformation, so I set lambda = "auto" , and biasadj = TRUE .在这里,我想使用带有 Box-Cox 转换的 auto.arima,所以我设置lambda = "auto"biasadj = TRUE However, the predicted value has mean NaN :但是,预测值的平均值为NaN

> forecast(model,biasadj=TRUE, h=2)
    Point Forecast      Lo 80     Hi 80      Lo 95     Hi 95
209            NaN -0.1278079 0.1206801 -0.1962931 0.1890652
210            NaN -0.1278079 0.1206801 -0.1962931 0.1890652

I have checked some GitHub questions and some people say that it is because there is NA value in the residual so the point forecast is NaN.我检查了一些 GitHub 问题,有人说这是因为残差中有 NA 值,所以点预测为 NaN。 However, the residual in model doesn't contain NaN so it should not be the case.但是, model中的残差不包含NaN ,因此不应如此。 So, how can I solve that?那么,我该如何解决呢?

Also, why is the predicted value same for t=209 and t=210?另外,为什么 t=209 和 t=210 的预测值相同?

I have a feeling there is a misunderstanding about what biasadj does, but I think you need to take a step back and inspect the original data.我感觉对biasadj的作用存在误解,但我认为您需要退后一步检查原始数据。

Let's plot sp500 :让我们 plot sp500

library(ggplot2)
ggplot(data.frame(x = seq_along(sp500), y = sp500), aes(x, y)) +
    geom_line()

在此处输入图像描述

A cursory inspection suggests no seasonality and no drift/linear trend;粗略检查表明没有季节性和漂移/线性趋势; there may be some indication of heteroskedasticity which may warrant a Box-Cox transformation.可能存在一些异方差性的迹象,这可能需要进行 Box-Cox 变换。

Keeping model parsimony in mind, I would start with a default call to auto.arima allowing for a automatic Box-Cox transformation牢记 model 简约,我将从对auto.arima的默认调用开始,允许自动 Box-Cox 转换

library(forecast)
model <- auto.arima(sp500, lambda = "auto")
#Series: sp500 
#ARIMA(0,0,1) with non-zero mean 
#Box Cox transformation: lambda= 0.7637886 
#
#Coefficients:
#    ma1     mean
#-0.1142  -1.3103
#s.e.   0.0582   0.0041
#
#sigma^2 estimated as 0.00548:  log likelihood=308.93
#AIC=-611.86   AICc=-611.77   BIC=-601.18

auto.arima determines the optimal model to be ARIMA(0,0,1) on Box-Cox-transformed data with lambda = 0.76, which corresponds to a simple first-order moving average model MA(1). auto.arima在 lambda = 0.76 的 Box-Cox 转换数据上确定最优 model 为 ARIMA(0,0,1),这对应于简单的一阶移动平均值 Z20F335E630DAF49DC4()。 This seems to be consistent with the earlier visual assessment.这似乎与早期的视觉评估一致。

When forecasting, forecast will automatically show estimates on the original scale, see eg预测时, forecast将自动显示原始比例的估计值,参见例如

autoplot(forecast(model, h = 10))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM