Okay.
So in this lecture we are going to continue our econometrics example with Varma.
The next step is to define which columns we care about, which are GDP growth and term spread.
If you decide to difference the term spread, you could change this to use that column instead.
The next step is to get rid of the first row of the data.
Since we use different thing on GDPR, the first row will have missing values.
The next step is to split our data into train and test.
I've chosen an testicles 12, but you can feel free to try other values if you like.
The next step is to declare train ATX ancestry checks.
As we've done before.
The next step is through scalar data using the standard scalar.
Note that we are overwriting the old values which we won't be using anyway.
The next step is to also overwrite the old values in Def one since we don't need them anymore.
The next step is to plot the achieve of GDP growth.
Okay.
So based on GDP growth alone, the ECF seems to suggest a small Q value.
By the way, note that these plots are not exactly what you need in order to determine PACU.
Since they do not consider cross terms.
So we're only using these as a very rough guide.
Just to give you some idea.
In practice, the easiest way to do model selection is just to do a grid search and pick the best value
based on the criteria you care about.
The next step is to check the PKF.
So again, the piece have seems to suggest a small p value as well.
The next step is to pull out the ACF for the term spread.
Note that the act suggests that the signal has a cyclical pattern, which is what we observed.
The next step is to check the passive.
So this time a note that quite a few legs are significant, up to a pretty high order.
Okay.
So the next step is to check for stationery.
So we'll start with GDP growth.
Okay.
So recall that the p value is the second element in this tuple.
Since it's very small, we can conclude that this time series is stationary.
The next step is to perform the ADF tests on the term spread.
So again, we get a small p value, but not as small as before.
However, even with the 1% significance threshold, we would consider this stationary.
So it's probably not necessary.
It's a difference.
The next step is to set P and Q.
Note that I've chosen these values somewhat arbitrarily.
I've chosen a high value for P since the PSA for the term spread suggests that a large P.
The next step is to fit our VMAX model, which is the same as before.
So notice that this model trains a bit faster than before, but still not what we would consider fast.
The next step is to call get forecast to get the forecasts for and test timestamps.
The next step is to store the train and test predictions in our DataFrame and to plot the results.
Since this code is the same as before, I won't explain it again.
Okay.
So notice that both the train and test fit are not particularly good, at least compared to the previous
example.
It seems to have the most trouble predicting the extreme values even in the train set.
This makes sense since we've seen the same kind of behavior in stock prices.
However, note that the prediction does seem to go in the same direction as the true value.
One way to check whether or not this forecast is useful is to compare it with the naive forecast that
is comparing it with predicting the last known train value.
In this case, without actually plugging in numbers, it would seem that our model is better.
The next step is to plot the predictions for the term spread.
Since this is the same code as before, I won't explain it again.
So in this case, notice that the train predictions are pretty good, but may maybe lagging by one step.
This kind of behavior is typical when you have a trend with noise, but note that for the test predictions
we still see a similar thing.
However, this is not a case of lagging behind by one step because remember that the model doesn't know
anything about the values in the tests.
In this case, the model really is forecasting this curve, only having seen the train set.
So it's interesting that the model is able to capture the pattern despite it being off by a step or
two.
In the next block, we're going to compute the R squared for both the train and test set for each column.
Okay.
So as expected, the trainer squared for GDP growth is pretty low and the tests are squared is even
lower.
However, note that it is above zero, meaning that it's still better than predicting the average test
value for the term spread.
The trainer scored is high, which makes sense because of the strong correlation with lags we saw in
the ECF.
However, the test R-squared is low.
The next step is to try some other models such as Var and a Remo.
So we'll start with creating a var object.
The next step is to call the select order function.
We can see that if we were to use the AIC, we would select a league order of ten, which is 2.5 years.
The next step is to fit our model.
The next step is to get the flag order of our model, which we know is ten.
Recall that we need this value in order to select the right number of rows for the prior time series.
The next step is to grab the prior time series from the train set and then we call forecast to predict
and test the time steps ahead.
The next step is to store and plot our predictions for GDP.
So from my point of view, it's difficult to tell whether this is better or worse than what we had before.
But it doesn't look particularly bad.
The next step is to store and plot our predictions for term spread.
So in this case, we can see that our forecast is much worse than before.
When we look at the end sample predictions, we can tell that they definitely just lag the previous
value.
The next step is to compute the R squared for the GDP for both train and test.
So for the VAR model, we see that for both train and test the r squared is worse.
This means that var does not be varma, at least for GDP.
With the hyper parameters we used.
The next step is to compute the R squared for the term spread for both train and test.
So again, we see that for both train and test, the R squared is worse.
Again, we can conclude that Varma is better than var, at least for the orders we selected.
The final step in this lecture is to check our remote baseline.
Since this code is essentially the same as before, I won't explain it again.
Note that we are using the same PNG Q as our Varma model.
For a more fair comparison.
So this time we see that Arima does not outperform Varma.
The R squared is worse for both train and test for both GDP and term spread.
In this case, we've seen that Varma is useful and that there could be some predictive value in looking
across the two time series.