Page 1 of 1

Switching model workbook, example 9.3

Posted: Tue Dec 06, 2016 12:32 am
by n141
Dear Tom Doan,

Is it possible to use the nfix option in example 9.3 of the workbook? This example estimates a Markov switching autoregressive model using Bayesian MCMC. If so, can you please indicate where the changes are required?

Best regards.

Re: Switching model workbook, example 9.3

Posted: Tue Dec 06, 2016 10:42 am
by TomDoan
You can. This is designed for handling a situation where the regimes are "independent" (no common coefficients, no common variance):
do i=1,nstates
      cmom(smpl=(MSRegime==i),equation=MSRegEqn) gstart gend
      compute betas(i)=%ranmvpostcmom($
         %cmom,1.0/sigsqv(i),hprior,bprior)
      if %MSRegARIsUnstable(%xsubvec(betas(i),2,3))
         goto redrawbeta
   end do i
so it just does separate samples on the data from each regime. If you have common coefficients, you need to sample the entire set of regression coefficients together. That's a regression of the form
switchingreg.png
switchingreg.png (1.35 KiB) Viewed 51321 times
which would have to be done using weighted least squares to allow for the regime-specific variances. Alternatively, you can do the fixed and regime-specific coefficients in different blocks. That will involve subtracting off the fixed coefficient part from the dependent variable in doing the regime-specific draws above, and adding a separate draw of weighted-least squares on the dependent variable minus the regime-specific part to get a draw for the fixed coefficients. (That's what is done in the EM algorithm).
switchingregblocks.png
switchingregblocks.png (3.66 KiB) Viewed 51321 times

Re: Switching model workbook, example 9.3

Posted: Thu Dec 08, 2016 3:11 pm
by n141
Dear Tom Doan,

Thank you for the suggestion. Can you please help me with the code for this section?

Best regards.

Re: Switching model workbook, example 9.3

Posted: Thu Dec 08, 2016 9:50 pm
by TomDoan
Sure. Show me what you have.

Re: Switching model workbook, example 9.3

Posted: Wed Dec 14, 2016 11:50 pm
by n141
Dear Tom Doan,

Sorry for replying late. I am a new RATS user and it is taking a while to figure it out. Since you pointed towards EM algorithm and it is a Bayesian MCMC, can the code be like the following:

Code: Select all

if MSRegNSwitch>0 {
   @MSRegFixResids MSRegU gstart gend
   do i=1,nstates
      set wt gstart gend = qhat=MSEMMarginal(MSEMpt_sm(t)),qhat(i)
      cmom(smpl=(MSRegime==i),weight=wt,equation=MSRegEqnSwitch,depvar) gstart gend
      compute betas(i)=%ranmvpostcmom(%cmom,1.0/sigsqv(i),hprior,bprior)   
   end do i
}
*
if MSRegNFix>0 {
   compute cmomEM=%zeros(MSRegNFix+1,MSRegNFix+1)
   do i=1,nstates
      gset iregime gstart gend = i
      @MSRegSwitchResids(regime=iregime) MSRegU gstart gend
      set wt gstart gend = qhat=MSEMMarginal(MSEMpt_sm(t)),qhat(i)
      cmom(weight=wt,spread=sigsqv(i),equation=MSRegEqnFix,depvar) gstart gend
      compute cmomEM=cmomEM+%cmom
   end do i
   compute gammas=%ranmvpostcmom(%cmom,1.0/sigsqv(i),hprior,bprior)   
}
Best regards.

Re: Switching model workbook, example 9.3

Posted: Thu Dec 15, 2016 9:42 am
by TomDoan
Close. One thing to note is that there needs to be a separate prior mean and precision for each of the N+1 regressions. The switch regressions are all the same size, and you can use a common prior for all of those if you're not trying to make the regime "labeling" depend upon the behavior of those. (If, say, the hope is that the regimes switch based upon variance instead). The fixed regression is a completely different size and so will need its own prior.

The main difference between EM and the corresponding Gibbs sampler is that EM probabilistically weights the regimes, while the Gibbs sampler treats them as "known" (at the currently sampled values). So you need to get rid of the wt series and rely only on the SMPL options. And in drawing the gammas, you've already taken into account the sigma's when forming the cross product matrix, so you use 1.0 as the equation precision:

compute gammas=%ranmvpostcmom(%cmom,1.0,hprior(needs to change),bprior(needs to change))

Re: Switching model workbook, example 9.3

Posted: Mon Dec 26, 2016 9:23 pm
by n141
Dear Tom Doan,

Would regime dependent time trend make any sense in the Markov switching specification?

Best regards.

Re: Switching model workbook, example 9.3

Posted: Mon Dec 26, 2016 9:54 pm
by TomDoan
Lam's model has a regime-dependent trend rate. However, it's quite a bit more complicated than even the (related) Hamilton model. I'm not sure how one would do a regime-dependent trend directly since the different trends would separate too much as you got later into the entry range.

LAM, P.-S. (1990): “The Hamilton model with a general autoregressive component: estimation and comparison with other models of economic time series", Journal of Monetary Economics, 26(3), 409–432.

Re: Switching model workbook, example 9.3

Posted: Tue Aug 08, 2017 2:13 am
by gabri_london
Dear Tom,
I have worked in the past with ARCH, SWARCH and MSVAR models. In the UG manual (version 8 page 365) I read that is not possible to combine MS specification of the mean M ( Hamilton type model) state dependent models with MS specification of the "I" intercept state dependent model. However, I noticed that the specification switch = , the mh (mean variance) is among the allowed ones. To this regard, I have the following questions:
Would it be possible to combine a MSAR (univariate) model (or MSregression) with a Switching variance model? If so, could you please kindly provide references?
Would it be possible to combine MSAR (or MSregression) with an ARCH/GARCH specification?
And for sake of completeness, would it be possible to combine MSAR (or MSregression) with SWARCH?
Thank you in advance for your attention and help.
Gabriella

Re: Switching model workbook, example 9.3

Posted: Tue Aug 08, 2017 9:48 am
by TomDoan
gabri_london wrote:Dear Tom,
I have worked in the past with ARCH, SWARCH and MSVAR models. In the UG manual (version 8 page 365) I read that is not possible to combine MS specification of the mean M ( Hamilton type model) state dependent models with MS specification of the "I" intercept state dependent model. However, I noticed that the specification switch = , the mh (mean variance) is among the allowed ones. To this regard, I have the following questions:
Would it be possible to combine a MSAR (univariate) model (or MSregression) with a Switching variance model? If so, could you please kindly provide references?
I'm not sure what you mean. @MSRegression has the SWITCH=[C]/CH/H option. @MSVARSETUP (for MS-AR's) also allows for switching variances in all the mean model switches.
gabri_london wrote: Would it be possible to combine MSAR (or MSregression) with an ARCH/GARCH specification?
You can. It's not simple, because even if the GARCH process is fixed, the dependence of the variance on past regimes through the residuals doesn't have a finite cutoff.
gabri_london wrote: And for sake of completeness, would it be possible to combine MSAR (or MSregression) with SWARCH?
Yes.

Re: Switching model workbook, example 9.3

Posted: Thu Aug 10, 2017 5:10 am
by gabri_london
Thank you Tom, very much appreciated.
Gabriella