Welcome back to practical time series analysis. We've been looking at forecasting in these lectures. We know how to do simple exponential smoothing, and now we'll move on to Holt Winters. This will allow us to deal with time series that exhibit some sort of trend, time series that are rising or falling or sometimes rising and sometimes falling. After this lecture, you'll be able to use the r command Holt winters to produce a forecast for one of these time series that exhibit a trend. And we always like you to be able to explain these fundamental tools to a friend or colleague in very simple terms. Here's our formula for a simple exponential smoothing. We put hats on things that we're estimating. And so X with a subscript, n+1 represents some sort of estimation. This is our forecast of what we think will be happening in the next time period. We build that as some sort of a weighted average of new information. The state of the system in time n, together with older historical information, and we think about these levels that we're creating as smoothed averages. There's a geometric series hiding inside of this formula here which motivates it. But if you don't want to worry about that, just think of it as a weighted average, some component which is new and some component which is, you could say, historical. So when we deal with these formulas, we have a few different notational things to keep in mind. Levels will always be associated in these lectures with the parameter alpha. Trend, rising and falling, will be associated with the parameter beta. And seasonal components will have a gamma to them. We'll look at for a motivating sample here, a data set on the volume of money. Money is actually more complicated than one might think, until you start studying it. But, let's just say how much money is circulating at a given time. The source here is the Australian Bureau of Statistics, and I obtained these data from the time series data library. There are a lot of really terrific data sets there, and you can go and explore them. This I'm sure looks like total gibberish if this is your first lecture, and you've never done r before. But at this point by week 5, most of us can look at this and it's almost transparent. We will say, get rid of all the old variables so we have a clean slate. We'll read in money.data with the r command read.table, we've encountered that before. I've taken, I've downloaded the data set and I stored it in a file called Volume-of-money-abs-definition.m, a little bit of an awkward name. I inherited that from the website.txt. It was a text file so I just clicked on it, and went in and got rid of some of the notational information at the top of the file, so that we only had now data to deal with. So, we'll create a time series object with a TS command as we've done before. We will start it off in February 1960, so we can cut 1960 the year together with the second data point. Frequency is 12. The plotting commands are, they should be instinctual. At this point, we're going to plot our time series. It's always good to get some good intuition going. We'll run our autocorrelation function and our partial autocorrelation function, and we'll think through our usual idea that we can perhaps identify an auto-regressive time series or a moving average time series or something which is a mixture, depending upon how things are tapering off or abruptly cutting off. Here's our trend. It's increasing. It does look to have some sort of very easy functional approach here. I wouldn't necessarily just fit an exponential to this. I certainly would not fit a straight line. It seems like things increase at times and stall at other times. So this is a nice candidate for the kind of forecasting that we're going to do rather than let's say, straight modeling. The autocorrelation function is what you would probably guess given time series that exhibits a trend like this. The autocorrelation is falling off rather gradually because of course, near neighbors have a good deal of information about where you are at the time series. The partial has that one lonely spike there. If you were modeling, you might immediately think that you could do a first order auto-regressive model. But again, that's putting a lot of, you're making that one auto-regressive coefficient do an awful lot of work. Instead of forming a formal mathematical model as we say, we'll do some forecasting instead. Quick reminder, we'll get a new level, a new smoothed average value as a weighted average of alpha times some new information, the new state of the system plus one minus Alpha times our old averaged value. Then you can see that exhibited in this formula right here. That's when we were just doing simple exponential smoothing. To get to double, we'll increase the complexity just a little bit. We're going to build a forecast as the level, the smoothed average value plus some trends data. We'll take a look at how the system is rising or falling. Expressed notationally, we'll say X item plus one looks like level time at time n, plus trend at time n. I'll see how we unpack these two terms. Level at time n is going to be alpha times new information. No surprise there. Plus one minus alpha. And now we're going to include our old level, but we're going to try to bring in the trend in our smoothed average here. So if the series just rose or fell, we'll try to bring that in. So level at time n is alpha Xn, and then one minus alpha times previous level and the previous trend. So we're going to build trends now and again, the geometric series is hiding behind this. We're going to build trends now based upon a smoothed average of past trends. We're trying to suppress the effect of too much noise at any one step in our forecast. So off we go. Trend to time n, we'll treat that as a weighted average. This probably looks pretty intuitive to you at this point. Beta, it's a new piece of notation, but there you go. So, beta times new trend and one minus beta times old trend. So the old trend once we have a little induction, we know our trends as we move along. This will be a smooth average on the trends. How would you define your new trend? The new trend will be the change in levels. So trend to time n then is a weighted average of new information and historical information. The call is rather simple. Holt Winters is our command. We'll feed it our time series right here. The alpha and beta parameters will let Holt Winters figure out optimal values there. We're turning off, we're suppressing seasonality, so we'll say gamma is equal to false. We could write our own code to do this. We've seen how in past lectures, and I certainly would not stop you. But at a certain point, we'd like to get some work done, and we've got the call here and we'll just go ahead and use it. The optimal value for alpha and beta would be, take a look at that alpha value. You can see pretty quickly that the alpha value is rather close to one. So, where's that going to put the emphasis in the trend piece? We've got alpha times new plus one minus alpha times historical. So this is going to put a fair amount of weight on the new data point. The beta, the perimeter accommodating our trend is really rather small. So if you remember how we constructed that, this is going to put more weight on the historical piece and less weight on the new piece. And the seen as telling us that gamma's false. Coefficients are where you go for your new forecast. We can read our new forecasted output, or system state and our new forecast the trend. These pictures shows how we're doing. I realize especially if you're viewing this on a cell phone that it's very hard to see in any detail what's going on in this picture. So, I've zoomed in for you on the years 1982 1985, and there's something sort of interesting if you take a look at what's going on here. Let's look at a piece where we see that we have a decent forecast guide, and it looks like on a piece which is nearly linear, that the forecast is matching what the series actually did pretty well. But look what happens when the series, this time series of course is shown in black here. Look what happens when the series makes a more abrupt jump up. As the trend goes from an around 45 degrees to what would you call that, 60, 70 degrees? As the trend kicks up, it takes the forecasts just a little while to become aware of that so to speak, and you'll see the forecast moving in the same direction as previous. But then it does realize that this last little bit of trend is not just a little bit of noise, but rather something that's more persistent. And it accommodates that in how it calculates the forecasts. You can see something similar happening here, where we were moving along with a decently constant trend, the time series took a dive down, and it took the forecasts a couple of time periods to realize the new information to incorporate that new information. But it did, and then we moved on. At this point, if you have a time series that exhibits some trend, you might think about using Holt Winters in order to do your forecasting. You know how to use Holt Winters now, it's really rather a simple call. And you should be able to explain to a friend or colleague that Holt Winters when we do double exponential smoothing is a way to accommodate new information, and also take advantage of historical information when forming a forecast.