首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过R studio将CSV输入到带日期的R预测?

通过R studio将CSV输入到带日期的R预测?
EN

Stack Overflow用户
提问于 2012-12-26 01:43:43
回答 1查看 1.9K关注 0票数 1

我有一个非常简单的csv文件,我正在尝试不同的预测方法。

代码语言:javascript
运行
复制
          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 

当我使用R studio导入它时,我得到了这个列表。(上图),它只有列表名称。以及我似乎不能引用的Col头。

我完全是R的新手,但是我想我应该有一个Dataframe,并且第一列应该是date类型。不知道从这里怎么走..然后..。这是预测输入的正确布局吗?

如何使用预测(多模型)来使用行10-4使用3上的UnemplRt预测3上的“总数”(这是预先知道的,依此类推。10-3到预测2和10-2到预测1)当然是对即将到来的一年的预测…我已经从电子表格中的直线回归中得到了它,但它太高了,所以我正在寻找能更好地对最近的数据进行因子分析的方法,并关注曲线,而不仅仅是直线。

这是可怕的简单化,但希望足够通用,以便其他人也能找到有用的答案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-26 02:56:30

我不是100%确定你在问什么,但我假设你想创建一些包含一些回归的时间序列模型。下面概述了构建一个简单的时间序列模型和一个包含回归器的模型。

代码语言:javascript
运行
复制
# 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)

由于您包含了一些失业率数据,因此我假设您可能希望在某种回归模型的预测中包含这些数据。下面是一个关于如何实现这一点的模型:

代码语言:javascript
运行
复制
# 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)

这里是预测的结果,你也可以像上面一样绘制一张图。

代码语言:javascript
运行
复制
fcast2
     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
2013       45168.02 38848.92 51487.12 35503.79 54832.25

希望以上内容能有所帮助。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14032768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档