Welcome back to a practical time series analysis.
In these lectures, we're looking at forecasting.
We're trying to say interesting and important things
about how we think our system is going to behave in the future,
based upon how it's been behaving in the past.
We're moving our methodology now to incorporate trend rising or falling,
and also now seasonality.
We expect that there's some sort of persistent pattern that has a cycle to it.
After this lecture, you'll be able to use the Holtwinters methodology.
Not just routine calls but actually understand that methodology fairly deeply to
produce a forecast when your data of course has trend seasonality,
like this data set here.
We're looking at a classic data set,
and you can see that there is a yearly cycle.
Some people reserve the word cycle for a more technical term or technical application.
We'll use a little more loosely and say,
look we've got a cycle going on here.
There's a length of time over which a certain pattern is repeating itself.
We have an annual cycle going on so let little m,
that's the notation we're developing to talk about how many seasons are in a cycle.
We'll let Little em equal 12.
The top here is exhibiting multiplicative seasonality,
and the bottom additive after we'd take Logs as we discussed in the last lecture.
The methodology asks you to smooth the level,
smooth the trend, smooth the season,
and use that to update your forecast.
The updating process is rather simple especially in the additive case where you'll
take your forecast h steps into the future as level,
this is let's say the last available level
we're going to go h steps into the future and we have
a trend smoothed trend so take h times that smooth trend, h times the number.
H is the number steps,
trend is basically your step size.
The seasonal term has this sub-script here that says come to time period or time n,
look h into the future.
That's what we want to do with our prediction,
but now accommodate the fact that your time series is
seasonal by looking at the seasonal coefficient that
we have seen how to develop by n + h - m. If you're looking in 1961,
for instance march of 1961,
would have n + h,
h in that case would be 15.
We'll pull it back by m. We'll take 15 and subtract off
12 to give us the seasonal coefficient for the generic Match.
Multiplicative seasonality is much the same.
Remember additive seasonality essentially says
that to get your new data you're going to add a certain amount.
If you know your January sales of canoes and you'd like the June sales of canoe's,
you'll add 10,000 or whatever the appropriate number is in your factory.
If you're dealing with multiplicative seasonality.
Maybe you feel that June sales are triple or quadruple the January sales,
so you have a multiplier of Three or four.
The call couldn't be more simple.
We'll use Holtwinters as our command and we'll take logs of our dataset.
Inside here, Airpassengers is your basic data set.
We'll take logs and then we'll apply the Holtwinter's routine.
We store this in Airpassengers that h_w,
and the results if you start interrogating your data structure look like.
We've got Alpha Beta and Gamma talking about level, trend, and seasonality.
We can see the numbers that the routine is calculating as what is
optimal in our current dataset.
We also need our coefficients.
We need the last smoothed level,
the last smoothed trend,
and we need our seasonality terms.
I don't know if it's intuitive to you but
which month of the year do you think would have the greatest ridership,
and where do you see the greatest seasonality coefficient.
Again which month of the year do you think would have the smallest ridership.
These may be intuitive to you,
these numbers right here.
Let's see if we can make a prediction for January 1961.
Remember our data set goes up to December 1960.
This is asking us to look one month into the future.
This is our generic formula up here.
This is our roadmap for proceeding.
There are 12 years worth of data,
12 months in a year,
so our basic dataset has 144 elements.
We're looking for the 145th element in our time series.
We'll take the less smooth level.
We're looking onetime step into the future so h = 1,
and we'll multiply that by the trend and then we go get
the seasonal coefficient for January.
This was last computed if you look at the time series and this location right here,
145 minus 12 is 133.
We just go back and read the numbers and we can pull out these values rather easily.
This is your generic January right here and we make this forecast for our future.
How about August?
August is the eighth month of the year.
We'll take our level,
get eight times the trend going,
and now we look back in our seasonality coefficients and grab
out the August coefficient and we wind up with this.
Again, remember that these are log data.
Suppose you'd like to look even further into the future.
You keep doing these computations yourself if you like
these calculationsm but I find it easy to pull out the forecast library.
You may have to download this,
but we will produce Airpassengers.hw just as we did before.
This is just a reminder right here,
and we make the very simple call forecast.holtwinters.
We'll do it on the output of the Holtwinter's routine,
and it'll give us a multitude of information here.
In particular it's going to give us point forecasts and you can see that
our January and our August 1961 forecasts were just fine.
In the readings, we'll actually get into 1962 as well.
We'll get a little further into the future.
The forecasts are given as point forecasts.
We also have interval estimates.
If you're comfortable with an 80 percent level of confidence,
you can say that your forecast is the actual future result.
We have 80 percent confidence it will be in this band right here.
If you need to be 95 percent confident,
of course you're going to have to look a little further up and down,
but we can get a 95 percent confidence interval from the routine as well.
If you plot your Holtwinter's forecast structure,
and do the most obvious thing just invoke the plot command on it.
Then you'll see that we have a time series looking like this.
This is the log data.
If you notice over here we've got a dark line.
It's a rather thick line well there it is.
A dark line which is our point forecasts.
Those shadows around, they're actually two different shades of gray there.
We get an 80 percent and a 95 percent confidence interval around each point forecast.
That's going to give you this gray cloud
here around your point forecasts for your interval estimates.
At this point you should feel rather comfortable invoking Holtwinters to
do a forecast for a dataset that's exhibiting seasonality and trend.