我不是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
希望以上幫助。
你的問題到底是什麼?如何構建一個模型來預測您的時間序列數據或如何導入數據並解釋R創建的結構? – Thilo
關於你的輸出:如果你調用'str(yourdata)',你會看到你確實有一個data.frame有三列。您應該能夠引用您的值,例如'yourdata $ total'。 – Thilo
StatewideProjectiontest $ total NULL'data.frame':\t 11 obs。 1變量: $ V1:因子w/11水平「12/31/2004,51439,5.7」,..:11 10 9 8 7 6 5 4 3 2 ... – dartdog