Threshold Switching Models | Switching Models in Econometrics
From the series: Switching Models in Econometrics
This is the second video in a two-part series that shows how to model time series data in the presence of regime shifts in MATLAB® in this video, we use Threshold Switching Models from the Econometrics Toolbox™ to model inflation data across different inflationary regimes.
Highlights:
- Import Consumer Price Index data and visualize monthly U.S. inflation rate
- Set up ARIMA or vector auto-regressive sub models to describe the data in each of the inflationary, normal, and deflationary regimes
- Create a deterministic switching mechanism between different inflation states using threshold transition functionality in the Econometrics Toolbox
- Assemble the switching model using built-in functionality in the Econometrics Toolbox to switch between the sub models in different regimes
- Estimate model parameters, simulate the model over multiple paths and time periods, and forecast model means from current data
Published: 20 Jan 2022
Hello. My name is Bill Mueller. I'm a developer for Econometrics Toolbox and MathWorks here to talk about switching models in Econometrics. This is the second part of a two part series on switching models. The second part deals with threshold switching models.
In the first part of this series, we talked about switching models in general as describing data that shifts among discrete states. Switching models consist of a vector of sub models, where each sub model describes the statistical characteristics of an individual state. The model also contains a switching mechanism to direct transitions from one state to the next. Markov switching models and threshold switching models share this description. And their implementation, as we'll see, is much the same.
The essential difference is that, in a Markov switching model, the transitions are nondeterministic, governed by the transition probabilities in a Markov chain. In a threshold switching model, the transitions are deterministic, governed by the movements of an observable variable. Threshold transitions require both a designated threshold variable and a set of distinct thresholds on the level of that variable. The idea is that when the variable crosses the threshold, it triggers a state change.
Examples of threshold variables are things like inflation rates and exchange rates, which when they move outside of a normal range, can trigger government intervention with a new set of rules, and correspondingly, new model parameters. Let's look at some inflationary data in MATLAB.
Here, we have a live script which we'll use to execute a series of MATLAB commands to look at some data that might be described by a threshold switching model. We'll then talk about the simple steps for constructing a threshold switching model in MATLAB. And finally, we'll talk about estimating the parameters for the model from the data to get a good description of the data, and then go on to do typical things like simulation and forecasting using our estimated model.
So the first thing we're going to do is load some historical macroeconomic data here. And if we do that and take a look in the MATLAB command window, we see that a number of different data tables have been loaded, including this monthly data table. If I double click here to look at it in the Data Browser, we can see that it consists of a series of monthly observations beginning in 1947 of a number of different macroeconomic time series. We're going to be interested in this one, the consumer price index, which is used to compute inflation rates.
So to extract that consumer price index series from the table, we use dot indexing and obtain this single series. And then we're going to compute an inflation rate, in this case by finding a percentage difference of the consumer price index relative to the value of the index in the previous month. So this is one way to compute an inflation rate. There are various ways to do it, just as there are various ways to compute the consumer price index. But we'll use this data to take a look at how to construct a switching model.
The second thing we're going to do is convert the dates that get loaded, these monthly dates throughout the year, into a date time vector as we did in the previous presentation, remembering that date times are the preferred container in MATLAB for anything involving times and dates. If you're going to go on and do any kind of calculations with the times and dates, or as we're going to do here, if you're going to create plots and you want to have a nice display of the dates on one of the axes, then date times are good containers.
So we convert the dates to date times using the date time command. And then we're going to plot those dates versus the inflation rate that we just computed. Finally, we'll issue this recession plot command, which will overlay the historical recession periods onto the plot. And we get a plot that looks something like this.
We can see that our inflation rate has a range between about 0 and 2%, with a certain period, say, here after World War II where we actually see a negative inflation rates, deflation. And otherwise, a steady increase in the inflation rate over the 60s and 70s, with somewhat increased volatility during the recessions, and some sharp upward spikes in the inflation rate during these recession periods.
Now, this data is a good candidate for something that might be described by a switching model, because the Federal Reserve tracks inflation rates like this and looks for periods where the inflation rate is either too low or too high. And after observing deviations from a normal inflation rate, after a lag, say, of maybe a few months, the Federal Reserve might issue new rules and guidelines on things like interest rates, et cetera, to try and meet their price stability goals and employment goals.
And when the Fed does something like that, the economic environment changes, and the statistical description of the data in the new economic environment might be different than what it was in the previous environment. So we could imagine a switching model that, say, has different states for deflationary periods, normal periods, and high inflationary periods, which we'd want to divide by different threshold levels on this particular variable, and then use those times when the inflation rate crosses a threshold to indicate a change of state.
Now, to build a threshold switching model, this is going to look completely parallel to what we did with the Markov switching models. If you're dealing with a univariate series like we are here with the inflation rates, you'll want to construct yourself models with the ARIMA model constructor. If, on the other hand, you want to build a multivariate model and describe the interactions among a number of different series, you can create multivariate switching models with VARM submodels. We talked about this in some detail in the previous presentation. We'll see another example of constructing some ARIMA models in just a moment here.
Once you've constructed the sub models, the second component of a switching model is the switch itself. In this case, instead of a Markov chain, we're going to create something called a threshold transition object. And a threshold transition object is essentially just a series of levels that describe when a threshold variable will change state. So if we describe, say, discrete levels at zero and one, and we introduce as a threshold variable or inflation rate, we can see that there's going to be these three separate states or regimes of that particular variable given this set of levels.
We'll also see that it's possible to describe what are called smooth transitions, or continuous transitions, where instead of having abrupt changes of state when the threshold variable crosses one of the thresholds, we have a mixing of states, an actual mixing of models, as the variable gradually or less gradually crosses these different thresholds. So let's take a look at how do we construct the switch for these models.
The basic command is simply called threshold. And in its simplest form, you give threshold a series of levels. By default, it'll create a discrete threshold transition object here with the levels that you specified. And once you've done that, you can use methods in the threshold class to do things like extract data from the threshold transition objects or plot the threshold transition objects.
If you go back here to the command window, and again in our econ econ folder in your MATLAB installation, we see a list of all of our class directories here. Here's the threshold class. If we open that up, we see that we have not only the threshold constructor but these other commands for querying and plotting what's in the threshold transition object.
If we use the ttplot command to plot this simple threshold transition object, and optionally give it this parameter value argument where we say we'd like to overlay this data, this data is a possible transition variable or threshold variable that we'd like to use to activate the transitions for these levels, we can create a plot. We get something like this. And we see our discrete levels at zero and one with an overlay of our designated threshold variable.
You can use the very same command, the threshold command, give it the same discrete levels here, but give it a different type. So the default type for the threshold constructor is discrete levels. But there are a number of optional continuous transitions that you can specify, like the logistic type here. And when you specify a continuous type, you're required to give rates for the different transitions.
So the idea with a continuous transition is that if you give it a higher rate, like 10 at level zero, you get a quicker transition. If you give it a lower rate, like five at level one, you get a slower transition, like this. And we won't look here in any detail at these smooth transition models. But again, what happens here is if your threshold transitions are smooth, and you then designate a threshold variable like this, when the threshold variable gets near one of the transitions, instead of transitioning abruptly from one state to the next, one sub model to the next at the specific levels, you get a mixing of models near the transition area, with the mixing level described in this color bar here to the right.
So again, I'm not going to look at a smooth transition model for our inflation rates. We'll look at a discrete transition model. But these are available if you want to create smooth transition switching models. Now, I'd like to point out something about these threshold variables before we go on and actually put together the pieces of a threshold switching model. The threshold variables that you saw overlaid on those threshold transition plots are not actually a part of the model itself.
So the idea is that you create a threshold transition model with certain specified transition levels, either discrete or continuous, without any mention of what the threshold variable might be. That makes the models very flexible. You can use different threshold variables with the same threshold levels and have them activate the model in different ways. You don't actually need to say what the threshold variable will be when you specify the model. You have different options for that.
And the two main options for specifying threshold variables when you want to do something like estimating, simulating, or forecasting the model once you've already constructed it. The two options are exogenous threshold variables or endogenous threshold variables. So exogenous means coming from outside of the model. If you want to use a threshold variable to activate the model that's not one of the series that you're actually modeling, this would be called an exogenous switching model.
An example of that might be, suppose you're trying to describe trade data. You have a series that describe the quantities of goods exchanged between two countries. And you want to make a model of those series. You understand that there's a change in the environment when things like exchange rates go outside of certain limits. So you might use the exchange rate as the exogenous threshold variable to activate the changes of state as the exchange rate crosses certain levels.
But the Exchange rate would not be a part of the model itself. The model would be modeling the quantities of goods variables that you have in your particular model. Alternatively, your threshold variable might come from within the model itself, as in the case we're looking at here with inflation rates. So we're going to create a threshold switching model of the inflation rate.
And we're going to use a lagged version of the inflation rate as our threshold variable, the idea being that if the inflation rate goes outside of the normal bounds, then after a period of maybe several months, a lag period, that might trigger a change of state in the model, which we then want to incorporate into our model of the inflation rate going forward like that.
This is the default for all of the methods in the tsVAR class for constructing these thresholds switching models. If you do not specify an exogenous threshold variable, it's assumed that the switching variable is coming from within the model. We call these self exciting models. And by default, it's just the variable being modeled at a lag of one. You have lots of options to change that. Change the number of lags, change the variable that's causing the switching. But by default-- and we'll be looking closely at the default cases here in this presentation-- the default is to use the endogenous or self exciting switching with a lag of one.
OK. So how do you put the pieces together here and build a switching model? It's a three step process that's exactly the same as what we did for Markov switching models. First of all, you create each of your individual submodels for each of the states using either the ARIMA or VARM constructor. Second, you create the switch that'll govern how the model transitions from state to state. And in this case, it'll be one of these threshold transition objects. Again, no mention of the particular threshold variable that's going to trigger the switching, but just designating the switching levels.
And then we glue this all together with the tsVAR constructor in a way that you'll see is completely parallel to what we did with the msVAR constructor. And I'll say here, just to highlight that this is by design that the way that you work with the Markov's switching models and the way that you work with the threshold switching models is very parallel. The interfaces for the different methods for constructing the models, estimating the models, and so forth are very much alike.
And this gives you a lot of flexibility when you're working with data that you wish to describe with a switching model to go back and forth and look at different kinds of switching models on the same data. Because the commands are so similar, you can do a lot of exploration of different models and see which one best describes your data. The parallel interfaces between the Markov switching models and the threshold switching models make this very easy to do.
So this should look familiar. We first create the switch here. We'll just create a discrete switch with two levels. There are a number of optional parameter value arguments you can include. Like here will give names to the different states. We create our three sub models. In this case, I'll create three AR1 models with different variances, different AR structures here. Not claiming here that this is any kind of good description of our inflation rate data. We'll look at how to get good parameter values to describe our data in a moment here, when we look at estimation.
But just to show you the construction process, just assume that you have values for these different statistical characteristics of the sub models, either because you analyzed the data already or you're inputting these as what if kind of scenarios, and seeing how the model changes forecasts and so forth. Or maybe you got some of these parameters from economic theory. Whatever. Suppose you have all of these parameters and can create a fully specified set of submodels here.
Then we glue it all together with this tsVAR constructor by giving it the switch, and the series of sub models, and whatever optional parameter value arguments you want to give, like a name for the series. And this creates this tsVAR model object here with all of the information that you've included about the switch and the sub models combined into the single object.
Once you have a fully specified and constructed tsVAR object, you can start using the tsVAR methods to take a look at it. For example, the simulate method. If we give it now our fully constructed model above and ask to simulate for 100 time steps, we'll give some pre sample data here. Since it's an AR1 model, we'll give one value of pre sample data to initiate the AR terms and have all the simulations start from this same starting point.
If you run the Simulate command, you get the simulated data as an output. And optionally, as a third output, you get the state path during the simulation. And if we plot these two outputs, we get something like this. Here's a plot of our threshold switching model that we just specified. And here's a plot of the state path during the simulation among the three different states in our model.
Now of course, because this is a simulation and it's going to have randomly generated variant innovations specified by the variances that we gave up above, if I run the simulation the second time, we get a different simulation path, a different state path, and so forth. But once you have a fully specified model, you can start using the methods for simulation and forecasting on these thresholds switching models.
The first thing we're going to want to do, though, is take a look at how do we estimate the parameters in our switching model so that we get a good fit to the particular data set that we want to work with. And we'll use the estimation method for doing that. So let's take a look at these different methods that come in the tsVAR class for estimation, simulation, and forecasting.
Starting with estimation. We're going to construct a not fully specified tsVAR model. So here's a tsVAR model, just like we did above, where we specify the switch and the submodels. But in this case, we include NaN values, not a number values, for certain parameters. And this will tell the estimation algorithm that these are the parameters that we wish to estimate.
And we talked in the previous presentation that if you give a lot of different NaN values and you have a small amount of data, you might get poor estimates of the parameters. That goes without saying. Or if the model you're specifying, the sub models, the structure of the sub models, does not describe the data well, you'll also get poor estimates. Or you might-- the estimation algorithm might have trouble converging, and so on and so forth.
The best advice for doing estimation on any of these kinds of models is keep the models simple and parsimonious to begin with. Here, we'll just look at simple AR1 models. And if you have parameters that you can specify beforehand, that helps the estimator. By having fewer parameters to estimate here, we're going to specify the constant terms. All we're saying is that the mean in the first model's going to be negative, the second one zero, the third one positive. The autoregressive coefficients that we estimate will actually determine the means.
But by specifying these constants beforehand, we reduce the number of parameters that we're estimating. So if this is a reasonable or a simple model that might describe the different states or regimes, we'll be trying to estimate here just three model parameters, plus the two levels for the threshold transitions here.
When we put it all together with the tsVAR constructor, just like we did above for a fully specified model, we can optionally say that we'd like to estimate the covariance matrix here. In this case, it'll just be a variance, because it's a univariate model. And it'll just have a single value. So you can say NaN here and say, I'd also like to estimate the innovation's variance in the model when I do this.
So this is the model that we would like to estimate. You create that first. And then to kick start the estimation algorithm, you need some initial values. It's a little bit simpler in the threshold switching case than it was in the Markov case. In the Markov switching models, we had to specify a fully specified Markov switching model with initial values to kick start that expectation maximization algorithm that was used there.
It's a different optimization algorithm for estimating threshold switching models. And in this case, all you need to specify is initial values for the threshold levels. So we create this threshold transition object, say, starting values for our levels might be zero. A cut off between inflation and deflation. And one somewhere in the middle of our typical inflation rates. And that just gives the optimize or kick start that allows it to get started. We'll see that it will then search the log likelihood surface for this model until it finds optimal values for those actual threshold levels.
And you use the Estimate command by putting in the partially specified model that you'd like to estimate, the initial value of the threshold transition object, and then the data itself. Again, many optional parameter values that you can use here to fine tune the optimization routine. Things like convergence tolerances and so forth. Here, I'll just turn on this iteration plot so we can see the progress of the estimation.
And when we do this, we see that over a little more than 20 iterations, the log likelihood of the data increases monotonically until, at some point, it stops changing within a default tolerance, which you can change, and converges to a final estimated model. What values of the parameters best describe our inflation rate data? As for the Markov switching models, we have a summarize method. You can summarize our estimated model, which was the output from our estimation coming in here. This is what we're summarizing.
And we got a display that looks like this. So you can see that the levels that were estimated to describe this data with a two level switching model were this negative value a little bit below zero, and then a positive value a little bit below one. We get these statistics for things like information criteria. If you want to compare one model fit to another, one type of model versus another type of model. Again, if you're exploring different models to describe your data, this kind of fit information is very useful.
And finally, a table of the estimated parameters themselves with the statistics, like the standard errors and so forth. So once we have an estimated model, presumably if we simulate it, it will look a little bit more like our original data. That's the whole idea, that we want the estimated model to have the same statistical characteristics as the original data, so that if we simulate it, we should get something that mimics what the original data did.
So here, let's take our Simulation command, but this time run it on the estimated model for, say, 500 steps. And if we do that, we can apply if it looks like this. And indeed, it looks like we've got inflation rates for this particular path that are in the similar range to what we saw in the original data, between zero and two with some deflationary periods in here.
And if we run the simulation command multiple times, again inputting the estimated model, running it for the same number of time steps, but now asking for 50 different simulation paths all starting at the same initial value here for the autoregressive terms, plot them all, we get a plot that essentially shows us that there's not a great difference from simulation to simulation. The uniform density here in the displays of the different plots shows us that, pretty consistently from one path to another, we get data that looks like the single simulation that we did above.
Of course, the purpose of this is that now, if you compute statistics from these paths, you can generate a distribution of statistics instead of single statistics, and do Monte Carlo analysis on your model and the simulations. Finally, let's take a look at forecasting. Once again, by design, the forecast method looks entirely parallel to what we saw for the Markov switching models, where if you input the estimated model and the data that you'd like to forecast from and give a forecast horizon, in this case, 120 months or 10 years, you can generate two different kinds of forecasts, depending on how many output arguments you ask for here.
If you just ask for a single output argument, you'll get the optimal point forecasts for the mean of the data. That's minimum mean squared error forecasts there. If you ask for two outputs, the forecast method switches to doing simulation based forecasts and generates a number of different simulations of the data going forward. By default, I think it's 100. You can switch that to however many you want.
Takes an average of the simulations in order to generate the forecast mean. So we'll do that, in this case because I wanted to show you that if you ask for the two outputs, get the second output. You can use the second output, which is the estimated variance of the forecasts, to create here on lines 86 and 87 the confidence intervals, the 95% confidence intervals here, using the estimated variance. And when you plot the simulated forecasts mean together with the forecast intervals, you not only get a point forecast, but you get an interval forecast here with a 95% confidence interval.
So that's the basics of how to think about threshold switching models, how to construct them, how to estimate them, and then how to use your estimated model to start doing some analysis of things using simulations and forecasting. There are lots of different options here using different kinds of threshold variables as I described. Whether you want to use exogenous variables or self exciting endogenous variables, how you want those to activate the model. Lots of options through the parameter value pairs that we haven't explored here in this presentation.
But if you'd like to see how to do that and learn a little bit more about these models, I encourage you to look at our documentation where there are lots of great examples showing how each of these different parameter options works. Lots of examples that take you through different scenarios to achieve different outcomes with your models, et cetera. Take a look at our documentation and you can learn a lot more about these thresholds switching models.