我不是 100% 确定你在问什么,但我假设你想创建一些包含一些回归的时间序列模型。下面概述了构建一个简单的时间序列模型和一个包含回归量的模型。
# load the base data as presented in the question
Workbook1 <- structure(list(Year = structure(1:10, .Label = c("31-Dec-04",
"31-Dec-05", "31-Dec-06", "31-Dec-07", "31-Dec-08", "31-Dec-09",
"31-Dec-10", "31-Dec-11", "31-Dec-12", "31-Dec-13"), class = "factor"),
total = c(51439L, 59674L, 58664L, 55698L, 42235L, 37918L,
36234L, 36965L, 39535L, NA), UnemplRt = c(5.7, 4.7, 3.8,
3.7, 4.3, 8.5, 10.9, 10, 8.3, 7.1)), .Names = c("Year", "total",
"UnemplRt"), class = "data.frame", row.names = c(NA, -10L))
# Make a time series out of the value
dependent <- ts(Workbook1[1:9,]$total, start=c(2004), frequency=1)
# load forecast package
require(forecast)
# make a model that fits, you can get other models as well. Think it is best to some studying of the forecast package documentation.
fit <- auto.arima(dependent)
# do the actual forecast
fcast <- forecast(fit)
# here some results of the forecast
fcast
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2013 39535 31852.42 47217.58 27785.501 51284.50
# You can make a plot as following:
plot(fcast)
当您包含一些失业率数据时,我假设您可能希望在某种回归模型中将其包含在您的预测中。下面是一个关于如何解决这个问题的模型:
# load independent variables in variables.
unemployment <- ts(Workbook1[1:9,]$UnemplRt, start=c(2004), frequency=1)
unemployment_future <- ts(Workbook1[10:10,]$UnemplRt, start=c(2004), frequency=1)
# make a model that fits the history
fit2 <- auto.arima(dependent, xreg=unemployment)
# generate a forecast with the already known unemployment rate for 2013.
fcast2 <- forecast(fit2,xreg=unemployment_future)
这里是预测的结果,你可以再次像上面那样绘制它。
fcast2
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2013 45168.02 38848.92 51487.12 35503.79 54832.25
希望以上有所帮助。