简体   繁体   English

R将预测应用于数据帧

[英]R apply prediction on data frame

My data frame looks like this: 我的数据框如下所示:

        Date  Value
1 01/04/2012  26200
2 02/04/2012  81100
3 03/04/2012  89800
4 04/04/2012 116800
5 05/04/2012 111300
6 06/04/2012 142200

(The above data is just the head() of the entire data set) (以上数据只是整个数据集的head())

I have values for 500 dates and I want to forecast values for the next 20 dates. 我有500个日期的值,我想预测接下来20个日期的值。 How do I go about doing this? 我该怎么做呢?

I thought that I would apply linear regression on column 2 and then apply predict() keeping the next 20 values of column 0 (ie 501, 502, 503, ... , 520) as X, but I think that will not be accurate. 我以为我会在第2列上应用线性回归,然后应用预测()来将第0列的下20个值(即501、502、503,...,520)保持为X,但是我认为这将不准确。 I am new to R and I have heard that there is a package for time series analysis and forecasting. 我是R的新手,我听说有一个用于时间序列分析和预测的软件包。 A solution using those packages might be helpful too. 使用这些软件包的解决方案也可能会有所帮助。

I thought that I would apply linear regression on column 2 and then apply predict() keeping the next 20 values of column 0 (ie 501, 502, 503, ... , 520) as X, but I think that will not be accurate. 我以为我会在第2列上应用线性回归,然后应用预测()来将第0列的下20个值(即501、502、503,...,520)保持为X,但是我认为这将不准确。

You are right, this approach is not appropriate as linear regression cannot take into account the autocorrelation structure of your time series. 没错,这种方法不合适,因为线性回归不能考虑时间序列的自相关结构。

Apart from the forecast package, you can also try the TSA package , but you might need some understanding in time series analysis fundamentals (such as autocorrelation, arma, arima models) in order to carry out meaningful analyses and predictions. 除了预测软件包之外,您还可以尝试使用TSA软件包 ,但是您可能需要对时间序列分析的基础知识(例如自相关,arma,Arima模型)有所了解,以便进行有意义的分析和预测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM