简体   繁体   中英

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)

I have values for 500 dates and I want to forecast values for the next 20 dates. 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. I am new to R and I have heard that there is a package for time series analysis and forecasting. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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