3
$\begingroup$

I'd like to use exponential smoothing to forecast the following data. The data is daily based. Because of some policy reasons, every $29^\text{th}$, $30^\text{th}$ and $31^\text{th}$ of each month, the data will drop to just hundreds.

  1. Do I need to take out the two/three days at the end of each month since they are not following the same pattern with other days of each month?
  2. If I use Holtwinter() to do the triple exponential smoothing, R will show error message: time series has no or less than 2 periods.
  3. If I remove the two days at the end of each month, the time range would be 3/12/1998 to 3/28/1998, 4/1/1998 to 4/28/1998, 5/1/1998 to 5/28/1998. How can I run R since the data are not in the complete month period?
18000   3/12/1998
61000   3/13/1998
59000   3/14/1998
59000   3/15/1998
66000   3/16/1998
38000   3/17/1998
37000   3/18/1998
20000   3/19/1998
72000   3/20/1998
44000   3/21/1998
37000   3/22/1998
33000   3/23/1998
28000   3/24/1998
54000   3/25/1998
24000   3/26/1998
66000   3/27/1998
52000   3/28/1998
280     3/29/1998
200     3/30/1998
400     3/31/1998
186000  4/1/1998
31000   4/2/1998
82000   4/3/1998
39000   4/4/1998
58000   4/5/1998
26000   4/6/1998
41000   4/7/1998
37000   4/8/1998
19000   4/9/1998
65000   4/10/1998
54000   4/11/1998
55000   4/12/1998
56000   4/13/1998
40000   4/14/1998
34000   4/15/1998
27000   4/16/1998
72000   4/17/1998
56000   4/18/1998
56000   4/19/1998
60000   4/20/1998
39000   4/21/1998
43000   4/22/1998
22000   4/23/1998
63000   4/24/1998
35000   4/25/1998
36000   4/26/1998
34000   4/27/1998
43000   4/28/1998
300     4/29/1998
250     4/30/1998
133000  5/1/1998
28000   5/2/1998
63000   5/3/1998
65000   5/4/1998
33000   5/5/1998
29000   5/6/1998
21000   5/7/1998
75000   5/8/1998
34000   5/9/1998
77000   5/10/1998
54000   5/11/1998
32000   5/12/1998
26000   5/13/1998
19000   5/14/1998
64000   5/15/1998
54000   5/16/1998
64000   5/17/1998
58000   5/18/1998
29000   5/19/1998
29000   5/20/1998
16000   5/21/1998
62000   5/22/1998
32000   5/23/1998
38000   5/24/1998
29000   5/25/1998
38000   5/26/1998
36000   5/27/1998
34000   5/28/1998
160     5/29/1998
150     5/30/1998
$\endgroup$
  • $\begingroup$ Try a model with multiple seasonalities. For example, tbats() in the forecast R package. $\endgroup$ – power Feb 3 '13 at 16:08
2
$\begingroup$

You have a couple of options.

  1. Try it anyway: Let the imperfect data stay and see what the forecast turns up.
  2. Delete the values for the end of the month, and try to forecast.

For Option #1, I really like Prof. Hyndman's forecast package. I use its ets and forecast options always as a starting point. If you are digging deeper, then be sure to look into auto.arima() as well.

For your data, I made it into a csv file.

df = read.csv('data/so_timeseries_q.csv')

#if you want the Date in a POSIX-friendly format
dte <- as.Date(df$Date, format='%m/%d/%y')
# as.POSIXlt(x="1998-03-12")$yday
#> 70
# Add one for zero-offset ---> 71

#make it a ts object
tsdata <- ts(df$Value, freq=365, start=c(1998,71))

#now plot the ets forecast
plot(forecast(ets(tsdata),10 ))

Which produces: enter image description here

Caveat: ets can't really handle frequency greater than 24. But for doing a purely Time Series analysis, you don't have to tell it whether it is daily or hourly or any other regular time interval (so long as it is metronomic). ** The x-axis shows the fraction of the year.

Option 2: R can handle missing values, if you use the xts or zoo packages. This vignette is a good place to start. So basically, you'd drop those end-of-the-month values, and run forecast methods.

Hope that gets you moving forward.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks Ram. If I delete the data and use number instead of date: from 1,2,3,`` to 73, does that work? $\endgroup$ – user20287 Feb 1 '13 at 23:21
  • $\begingroup$ @user20287 No, you should not renumber if you are deleting the (missing/wrong) values. Remember that you have to let the model know that you have some data points missing. If you read the vignette you'll see examples of how missing values are handled. Also, welcome to StatExchange. You have made your comment an answer. You can delete that and use comments for clarifications. $\endgroup$ – Ram Feb 2 '13 at 0:58
1
$\begingroup$

There are a few anomalies (besides the end of the month activity ) that need to be neutralized as you form a useful model. A useful model in this case would use day-of-the-week indicators. The Actual, Fit and Forecast enter image description here . The cleansed series enter image description here . The equation enter image description here The forecasts for the next 21 days enter image description here. Simple tools that assume a model form and ignore the isolation of unusual values and identifiable parameter changes often are ineffective in characterizing time series data.

Note that with longer data sets it is possible to automatically detect the effect of particualar days of the month and also particular weeks of the month while including patterns of response around each type of holiday/event.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.