dar*_*dog 1 regression r time-series forecasting dataframe
我有一个非常简单的csv文件,我正在尝试使用不同的预测方法.
Year total UnemplRt
1 12/31/2013 NA 7.1
2 12/31/2012 39535 8.3
3 12/31/2011 36965 10.0
4 12/31/2010 36234 10.9
5 12/31/2009 37918 8.5
6 12/31/2008 42235 4.3
7 12/31/2007 55698 3.7
8 12/31/2006 58664 3.8
9 12/31/2005 59674 4.7
10 12/31/2004 51439 5.7
Run Code Online (Sandbox Code Playgroud)
当我使用R studio导入它时,我得到这个列表.(上面)只有列表名称.和Col标题,我似乎无法参考.
我是R的新手,但我知道我应该有一个Dataframe,第一列应该是日期类型.不知道如何从这里到达那里..然后..那是正确的输入预测布局吗?
如何使用预测(Mutli模型)使用行10-4在3上使用UnemplRt预测"总数"(预先知道等等,即10-3预测2和10-2预测1)当然这将是对即将到来的一年的预测...我已经在电子表格中使用直线回归计算了它,但是它太高了,所以我正在寻找最近的因素数据更好,注意曲线而不仅仅是直线.
这非常简单,但希望足够通用,其他人也会发现答案也很有用.
我不是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)
Run Code Online (Sandbox Code Playgroud)
当你正在包括一些失业率数字,我认为你可能要包括这在某种回归模型的你的预测.下面是一个关于如何处理这个问题的模型:
# 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)
Run Code Online (Sandbox Code Playgroud)
在这里预测的结果,你可以再次如上所述绘制它的情节.
fcast2
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2013 45168.02 38848.92 51487.12 35503.79 54832.25
Run Code Online (Sandbox Code Playgroud)
希望以上有所帮助.