首页 > 解决方案 > 仅使用 auto.arima 和 xreg 的样本外预测图

问题描述

这是我的第一篇文章,如果这很笨重或格式不正确,非常抱歉。

 period texas u3    national u3

1976    5.758333333 7.716666667

1977    5.333333333 7.066666667

1978    4.825   6.066666667

1979    4.308333333 5.833333333

1980    5.141666667 7.141666667

1981    5.291666667 7.6

1982    6.875   9.708333333

1983    7.916666667 9.616666667

1984    6.125   7.525

1985    7.033333333 7.191666667

1986    8.75    6.991666667

1987    8.441666667 6.191666667

1988    7.358333333 5.491666667

1989    6.658333333 5.266666667

1990    6.333333333 5.616666667

1991    6.908333333 6.816666667

1992    7.633333333 7.508333333

1993    7.158333333 6.9

1994    6.491666667 6.083333333

1995    6.066666667 5.608333333

1996    5.708333333 5.416666667

1997    5.308333333 4.95

1998    4.883333333 4.508333333

1999    4.666666667 4.216666667

2000    4.291666667 3.991666667

2001    4.941666667 4.733333333

2002    6.341666667 5.775

2003    6.683333333 5.991666667

2004    5.941666667 5.533333333

2005    5.408333333 5.066666667

2006    4.891666667 4.616666667

2007    4.291666667 4.616666667

2008    4.808333333 5.775

2009    7.558333333 9.266666667

2010    8.15    9.616666667

2011    7.758333333 8.95

2012    6.725   8.066666667

2013    6.283333333 7.375

2014    5.1 6.166666667

2015    4.45    5.291666667

2016    4.633333333 4.866666667

2017    4.258333333 4.35

2018    3.858333333 3.9

2019    ____    3.5114

2020    ____    3.477

2021    ____    3.7921

2022    ____    4.0433

2023    ____    4.1339

2024    ____    4.2269

2025    ____    4.2738

如何将 R 中的 auto.arima 与外部回归器一起使用来进行预测,但只绘制样本外值?我相信预测值是正确的,但年份不匹配。因此,如果我有 1976-2018 年的年度数据并预测因变量(第 2 列)(我想预测到 2025 年),它会绘制 2019-2068 年期间的“预测”。奇怪的是,这些数字与样本数据非常吻合(2019 年的“预测”似乎是 1980 年的模型预测等等,一直到 2068 年与 2025 年相匹配。

我希望能够消除它并拥有它,因此“2062-2068”的结果是 2019-2025。我会尝试附上情节的图片,这样可能更容易想象我的困境。

下面是 R 脚本:

#Download the CVS file, the dependent variable in the second column, xreg in the third, and years in the first. All columns have headers.

library(forecast)
library(DataCombine)
library(tseries)
library(MASS)
library(TSA)

ts(TXB102[,2], frequency = 1, start = c(1976, 1),end = c(2018, 1)) -> TXB102ts
ts(TXB102[,3], frequency = 1, start = c(1976, 1), end = c(2018,1)) -> TXB102xregtest
ts(TXB102[,3], frequency = 1, start = c(1976, 1), end = c(2025,1)) -> TXB102xreg

as.vector(t(TXB102ts)) -> y
as.vector(t(TXB102xregtest)) -> xregtest
as.vector(t(TXB102xreg)) -> xreg

y <- ts(y,frequency = 1, start = c(1976,1),end = c(2018,1))
xregtest <- ts(xregtest, frequency = 1, start = c(1976,1), end=c(2018,1))
xreg <- ts(xreg, frequency = 1, start = c(1976,1), end=c(2025,1))

summary(y)
plot(y)

ndiffs(y)

ARIMA <- auto.arima(y, trace = TRUE, stepwise = FALSE, approximation = FALSE, xreg=xregtest)

ARIMA

forecast(ARIMA,xreg=xreg)
plot(forecast(ARIMA,xreg=xreg))   

以下是我运行脚本后得到的图。

阴谋

TLDR:我如何获得 2019-2025 年的真实样本外预测,而不是它作为 2019-2068 年传递的样本内模型拟合。

标签: rforecastingarimaeconomicsforecast

解决方案


推荐阅读