Reputation: 571
I am fairly new to the R package and I am dealing with time series. I have to build a prediction model for forecasting clicks for the future. The time interval for prediction needs to be hourly.
My example time series:
DateTime Clicks
(06/23/13 00:00:00) 757
(06/23/13 01:00:00) 714
(06/23/13 02:00:00) 776
(06/23/13 03:00:00) 870
(06/23/13 04:00:00) 1263
(06/23/13 05:00:00) 1457
(06/23/13 06:00:00) 1621
(06/23/13 07:00:00) 1606
(06/23/13 08:00:00) 1779
(06/23/13 09:00:00) 1832
(06/23/13 10:00:00) 1808
(06/23/13 11:00:00) 1789
(06/23/13 12:00:00) 1907
(06/23/13 13:00:00) 2021
(06/23/13 14:00:00) 2018
(06/23/13 15:00:00) 1836
(06/23/13 16:00:00) 1627
(06/23/13 17:00:00) 1331
(06/23/13 18:00:00) 1059
(06/23/13 19:00:00) 817
(06/23/13 20:00:00) 761
(06/23/13 21:00:00) 781
(06/23/13 22:00:00) 752
(06/23/13 23:00:00) 725
(06/24/13 00:00:00) 708
(06/24/13 01:00:00) 718
(06/24/13 02:00:00) 791
(06/24/13 03:00:00) 857
(06/24/13 04:00:00) 1094
(06/24/13 05:00:00) 1247
(06/24/13 06:00:00) 1316
(06/24/13 07:00:00) 1401
(06/24/13 08:00:00) 1575
(06/24/13 09:00:00) 1604
(06/24/13 10:00:00) 1774
(06/24/13 11:00:00) 1865
(06/24/13 12:00:00) 1964
(06/24/13 13:00:00) 2002
(06/24/13 14:00:00) 2043
(06/24/13 15:00:00) 2030
(06/24/13 16:00:00) 1733
(06/24/13 17:00:00) 1420
(06/24/13 18:00:00) 1075
(06/24/13 19:00:00) 831
(06/24/13 20:00:00) 789
(06/24/13 21:00:00) 791
(06/24/13 22:00:00) 715
(06/24/13 23:00:00) 683
(06/25/13 00:00:00) 802
(06/25/13 01:00:00) 811
(06/25/13 02:00:00) 838
(06/25/13 03:00:00) 851
(06/25/13 04:00:00) 1064
(06/25/13 05:00:00) 1191
(06/25/13 06:00:00) 1242
(06/25/13 07:00:00) 1233
(06/25/13 08:00:00) 1452
(06/25/13 09:00:00) 1501
(06/25/13 10:00:00) 1718
(06/25/13 11:00:00) 1861
(06/25/13 12:00:00) 1896
(06/25/13 13:00:00) 2073
(06/25/13 14:00:00) 2279
(06/25/13 15:00:00) 2239
(06/25/13 16:00:00) 2018
(06/25/13 17:00:00) 1550
(06/25/13 18:00:00) 1182
(06/25/13 19:00:00) 1063
(06/25/13 20:00:00) 973
(06/25/13 21:00:00) 1027
(06/25/13 22:00:00) 961
(06/25/13 23:00:00) 890
(06/26/13 00:00:00) 894
(06/26/13 01:00:00) 835
(06/26/13 02:00:00) 852
(06/26/13 03:00:00) 893
(06/26/13 04:00:00) 1111
(06/26/13 05:00:00) 1239
(06/26/13 06:00:00) 1263
(06/26/13 07:00:00) 1260
(06/26/13 08:00:00) 1451
(06/26/13 09:00:00) 1556
(06/26/13 10:00:00) 1733
(06/26/13 11:00:00) 1981
(06/26/13 12:00:00) 2063
(06/26/13 13:00:00) 2150
(06/26/13 14:00:00) 2278
(06/26/13 15:00:00) 2188
(06/26/13 16:00:00) 1980
(06/26/13 17:00:00) 1611
(06/26/13 18:00:00) 1381
(06/26/13 19:00:00) 1211
(06/26/13 20:00:00) 1129
(06/26/13 21:00:00) 1092
(06/26/13 22:00:00) 1009
(06/26/13 23:00:00) 973
(06/27/13 00:00:00) 865
(06/27/13 01:00:00) 805
(06/27/13 02:00:00) 840
(06/27/13 03:00:00) 813
(06/27/13 04:00:00) 1010
(06/27/13 05:00:00) 1201
(06/27/13 06:00:00) 1329
(06/27/13 07:00:00) 1343
(06/27/13 08:00:00) 1532
(06/27/13 09:00:00) 1612
(06/27/13 10:00:00) 1768
(06/27/13 11:00:00) 1977
(06/27/13 12:00:00) 2089
(06/27/13 13:00:00) 2247
(06/27/13 14:00:00) 2270
(06/27/13 15:00:00) 2275
(06/27/13 16:00:00) 2155
(06/27/13 17:00:00) 1639
(06/27/13 18:00:00) 1315
(06/27/13 19:00:00) 1099
(06/27/13 20:00:00) 1052
(06/27/13 21:00:00) 1099
(06/27/13 22:00:00) 965
(06/27/13 23:00:00) 961
(06/28/13 00:00:00) 765
(06/28/13 01:00:00) 830
(06/28/13 02:00:00) 874
(06/28/13 03:00:00) 845
(06/28/13 04:00:00) 1011
(06/28/13 05:00:00) 1160
(06/28/13 06:00:00) 1232
(06/28/13 07:00:00) 1310
(06/28/13 08:00:00) 1467
(06/28/13 09:00:00) 1639
(06/28/13 10:00:00) 1704
(06/28/13 11:00:00) 3704
(06/28/13 12:00:00) 7350
(06/28/13 13:00:00) 7629
(06/28/13 14:00:00) 7570
(06/28/13 15:00:00) 7276
(06/28/13 16:00:00) 7189
(06/28/13 17:00:00) 7139
(06/28/13 18:00:00) 7167
(06/28/13 19:00:00) 6871
(06/28/13 20:00:00) 6575
(06/28/13 21:00:00) 6112
(06/28/13 22:00:00) 5276
(06/28/13 23:00:00) 4407
(06/29/13 00:00:00) 3741
(06/29/13 01:00:00) 3427
(06/29/13 02:00:00) 3311
(06/29/13 03:00:00) 3096
(06/29/13 04:00:00) 3010
(06/29/13 05:00:00) 3301
(06/29/13 06:00:00) 3783
(06/29/13 07:00:00) 4578
(06/29/13 08:00:00) 5599
(06/29/13 09:00:00) 6590
(06/29/13 10:00:00) 6998
(06/29/13 11:00:00) 7323
(06/29/13 12:00:00) 7282
(06/29/13 13:00:00) 7009
(06/29/13 14:00:00) 6636
(06/29/13 15:00:00) 6407
(06/29/13 16:00:00) 6386
(06/29/13 17:00:00) 6505
(06/29/13 18:00:00) 3104
(06/29/13 19:00:00) 939
(06/29/13 20:00:00) 915
(06/29/13 21:00:00) 955
(06/29/13 22:00:00) 968
(06/29/13 23:00:00) 870
(06/30/13 00:00:00) 3504
(06/30/13 01:00:00) 3122
(06/30/13 02:00:00) 2874
(06/30/13 03:00:00) 2613
(06/30/13 04:00:00) 2905
(06/30/13 05:00:00) 2806
(06/30/13 06:00:00) 3244
(06/30/13 07:00:00) 3789
(06/30/13 08:00:00) 5015
(06/30/13 09:00:00) 6031
(06/30/13 10:00:00) 6841
(06/30/13 11:00:00) 7014
(06/30/13 12:00:00) 7265
(06/30/13 13:00:00) 7460
(06/30/13 14:00:00) 7275
(06/30/13 15:00:00) 7531
(06/30/13 16:00:00) 7013
(06/30/13 17:00:00) 6637
(06/30/13 18:00:00) 5770
(06/30/13 19:00:00) 5593
(06/30/13 20:00:00) 6524
(06/30/13 21:00:00) 5081
(06/30/13 22:00:00) 1131
(06/30/13 23:00:00) 949
This is a time series for a whole week on a hourly basis. Considering this data I need to predict using Holt-Winters the number of clicks that will be obtained for the next hour i.e. (06/28/13 00:00:00). I am trying to figure it out but am getting really confused. I will be thankful if someone can point me to the right direction.
EDIT:
I am using the Holt-Winters predict module as follows:
search_fit <- HoltWinters(z)
p = predict(search_fit,24)
But the problem is that the HOLT-WINTERS is not detecting any trend in the prediction. is it normal? Because there is a big change starting 06/28/13.
Following are my predicted values:
Time Series:
Start = c(15887, 1)
End = c(15887, 24)
Frequency = 24
fit
[1,] 927.6462
[2,] 935.2716
[3,] 1006.5636
[4,] 1066.4182
[5,] 1295.5852
[6,] 1442.9397
[7,] 1508.1693
[8,] 1590.9613
[9,] 1762.5033
[10,] 1789.1287
[11,] 1958.1083
[12,] 2049.1711
[13,] 2054.7757
[14,] 2168.1302
[15,] 2163.1514
[16,] 1979.5268
[17,] 1772.7355
[18,] 1483.0484
[19,] 1220.1946
[20,] 987.2366
[21,] 938.1745
[22,] 965.5915
[23,] 940.4669
[24,] 911.0089
and this is the prediction plot.
The trend component shows no variation. There is something I might be doing wrong while using the predict method of Holt-Winters.
Upvotes: 3
Views: 3241
Reputation: 3492
Try auto.arima or ets for automated time series See code here http://rpubs.com/newajay/timeseries
Upvotes: 0
Reputation: 22496
Here are some suggestions/things to try:
One reason you are not seeing HoltWinters
pick up a trend could be that the change you are referring to (on 6/28/13 in your data) is manifesting itself in the level component. The clicks have changed materially starting from noon on 6/28.
One note: HoltWinters()
will spit out the Smoothing parameters (alpha, beta, gamma). It will give you the slope b. If beta is 0, that only means that the trend does not change over the time series. It started with a slope b, and continues to be at the same slope.
Things to try
Try this:
> library(forecast)
> accuracy(search_fit)
Also a good idea to check the auto-correlations:
> acf(search_fit$residuals, lag.max=24)
Exponential smoothing and ARIMA models are the two most widely-used approaches to time series forecasting, and provide complementary approaches to the problem. While exponential smoothing models were based on a description of trend and seasonality in the data, ARIMA models aim to describe the autocorrelations in the data.
As a quick starting reference I find 1.Avril Coghlan's Little Book of R for Time series to be a great primer. Also, 2. Time Series Analysis with R - Part I is great, with a little more technical detail.
As and when you find the time, reading Prof. Rob Hyndman's book Forecasting Principles and Practice online is well worth the time, for anyone who's going to be doing Time Series analysis.
Be sure to try the forecast
package as well. Especially its auto.arima()
function is an incredible time saver.
Hope this helps.
Upvotes: 4