Markvov Switching regression model
res=ms_reg(endo,exo_com,exo_idio,MS_M,MS_M_V,MS_var_opt,arg1, ,argn)
endo=
- either: (T x K) string matrix of endogenous variables
- or: a list containing all the endogenous variables in any of the following form:
* a time series
* a real matrix
* a string representing such objects
* the string 'const' (for the constant variable)
exo_com=
- (T x K) string matrix of non switching exogenous variables
- or: a list containing all the non switching exogenous variables in any of the following form:
* a time series
* a real matrix
* a string representing such objects
* the string 'const' (for the constant variable)
- or: a list starting with the keyword 'diff' (as different) and containing thereafter as many elements as the number of endogenous variables; each element collects the names of the exogenous variables for the corresponding endogenous variable or their values
exo_idio =
- (T x K) string matrix of switching exogenous variables
- or: a list containing all the switching exogenous variables in any of the following form:
* a time series
* a real matrix
* a string representing such objects
* the string 'const' (for the constant variable)
- or: a list starting with the keyword 'diff' (as different) and containing thereafter as many elements as the number of endogenous variables; each element collects the names of the exogenous variables for the corresponding endogenous variable or their values
MS_M = a scalar equal the # of states
MS_V= a scalar:
- 1 if the variance of the residuals is the same for all states
- MS_M if the variance of the residuals differs among the states
MS_var_opt = a scalar:
- 1 if the variance of residuals is heteroskedastic
- 2 if the variance of residuals is homoskedastic
- 3 if the variance of residuals is unconstrained
arg1, argn = optional arguments which can be:
- 'datation=xx' where xx is the name of a series used as an a priori datation (default: no a priori datation)
- 'transf=xx' where xx is either 'dem' if the user wants all series to be demeaned or 'stu' if the user wants all series to be studentized (default: no transformation)
- 'gdelta=xx' where xx is a number used to calculate the numerical derivative of the log-likelihood (default 1e-4)
- 'hdelta=xx' where xx is a number used to calculate the numerical hessian (default 1e-5)
- 'prt=xx' where xx='nothing', 'final', 'all' or ['initial';'final'] if the user wants to print nothing, only the final results or the final and the initial results
- 'noprint' if the user wants to print nothing (equivalent to 'prt=nothing')
- the string 'dropna' if the user wants to remove the NA values from the data
- 'init_beta_id = xxx' where xxx is a vector of starting values for the switching exogenous variables
- 'init_beta_co = xxx' where xxx is a vector of starting values for the non switching exogenous variables
- 'init_prob' = xxx' where xxx is a matrix of starting values for the transition probabilities
- 'init_var' = xxx' where xxx is a matrix of starting values for the variances
- 'notstat' if the user does not want to calculate the Student statistics of the parameters
- 'optfunc=optim' if the user wants to use the optim optimisation function (default: optimg)
- 'opt_nelmead=crit,nitermax' with crit the value of the convergence criterion in the Nelder-Meade optimisation function and nitermax the maximum number of iterations (default = 'opt_nelmead=2*%eps,1000')
- 'opt_optim=opts' where opts are options for optim that can be entered after the starting value of the parameters (default = 'opt_optim=,''ar'',1e6,1e6'')
- 'opt_convg=val' where val is the threshold on gradient norm (default = 'opt_convg=1e-5')
res = a results tlist with:
- res('meth') = 'ms regression'
- res('typmod') = model numbered type
- res('y') = a (T x K) matrix of original endogenous variables
- res('ymat') = (T*K x 1) matrix of stacked endogenous variables
- res('xmat') = (T*K x sum(n_x)) matrix of switching exogenous variables
- res('zmat') = (T*K x sum(n_z)) matrix of non switching exogenous variables
- res('switching V') = a scalar:
* 1 if the variance does not switch with the states
* M if the variance switches with the states
- res('var_opt') = a scalar:
* 1 if the variance of residuals is heteroskedastic
* 2 if the variance of residuals is homoskedastic
* 3 if the variance of residuals is unconstrained
- res('nobs') = the # if observations
- res('nendo') = the # of endogenous variables
- res('nb_states') = the # of states
- res('coeff') = the (np x 1) vector of parameters
- res('llike') = the log-likekihood
- res('grad') = the gradient at the solution
- res('yhat') = the adjusted y
- res('filtered resid') = the filtered residuals of the regression
- res('dll') = the degrees of freedom
- res('prob_st') = the (M x 1) vector of egodic state probabilities
- res('ptrans') = the (M x M) matrix of transition probabilities
- res('sigma') = the (M*M_V x M) variance-covariance matrix of the residuals
- res('beta_id') = the (1 x sum(n_x)*M) vector of switching parameters
- res('beta_co') = the (1 x sum(n_z)) vector of non switching parameters
- res('inv_sigma') = the (K x K) inverse of the variance matrix
- res('det_inv_sigma') = the determinant of the inverse of the variance matrix
- res('filtered probs') = the (T x M) vector of filtered probabilities
- res('smoothed probs') = the (T x M) vector of smoothed probabilities
- res('n_x') = the (K x 1) vector of the numbers of switching exogenous variables for each endogenous variable
- res('n_z') = the (K x 1) vector of the numbers of non switching exogenous variables for each endogenous variable
- res('stderr') = the (np x 1) vector of coefficients standard errors
- res('hes. delta') = the numerical increment for the calculation of the hessian matrix
- res('tstat') = the (np x 1) vector of associated t-stats
- res('pvalue') = the (np x 1) vector of associated p-values
- res('covbeta') = the (np x np) variance-covariance matrix of the parameters
- res('corbeta') = the (np x np) correlation matrix of the parameters
- res('ptrans_tstat') = the (M x 1) vector of t-stats for the transition probabilities
- res('beta_id_tstat') = the (1 x n_x*K*M) vector of t-stats for switching parameters
- res('beta_co_tstat') = the (1 x n_z*K) vector of t-stats for non switching parameters
- res('sigma_tstat') = the (M*M_V x M) matrix of t-stats for the variance-covariance matrix of the residuals
- res('ptrans_pvalue') = the (M x M) matrix of t-stats for transition probabilities
- res('beta_id_pvalue') = the (1 x n_x*K*M) vector of t-stats for switching parameters
- res('beta_co_pvalue') = the (1 x n_z*K) vector of t-stats for non switching parameters
- res('sigma_pvalue') = the (M*M_V x M) matrix of t-stats for the variance-covariance matrix of the residuals
- res('smoothed resid') = the smoothed residuals of the regression
- res('namey') = the (ny x 1) vector of names of the endogenous variables
- res('namex_id') = the (n_x x 1) vector of names of the swicthing exogenous variables
- res('namex_co') = the (n_x x 1) vector of names of the non swicthing exogenous variables
- res('apriori') = a scalar
. 0 if there is no a priori datation
. 1 if there is an a priori datation
- res('prests') = a boolean indicating whether there are ts in the regression
- res('prests') = a boolean indicating whether there are ts in the regression
- res('datation') = the a priori datation if any
- res('namedat') = the name of the series used for an a priori datation if any
- res('dropna') = boolean indicating if NAs have been dropped
- res('bounds') = if there is a timeseries in the forecast, the bounds of the regression
- res('nonna') = vector indicating position of non-NAs
load('C:\SCI\macros\grocer\db\us_revu.dat') bounds('1967m4','2004m2') nb_states=2 switch_var=2 var_opt=3 r=ms_reg('100*(log(us_revu)-lagts(2,log(us_revu)))',['100*(lagts(1,log(us_revu))-lagts(3,log(us_revu)))';... '100*(lagts(2,log(us_revu))-lagts(4,log(us_revu)))';'100*(lagts(3,log(us_revu))-lagts(5,log(us_revu)))'],'const',nb_states,switch_var,var_opt,'transf=stud', 'prt=initial;final') // This example is taken from function ms_reg_d. The endogenous variable is '100*(log(us_revu)-lagts(2,log(us_revu)))'. The non switching exogenous variables are '100*(lagts(1,log(us_revu))-lagts(3,log(us_revu)))', '100*(lagts(2,log(us_revu))-lagts(4,log(us_revu)))' and '100*(lagts(3,log(us_revu))-lagts(5,log(us_revu)))'. The switching exogenous variables is here the constant. There are 2 states, the variances are switching (switch_var=2) and the var-cov matrix is unrestricted(var_opt=3). Two optional arguments have been given: 'transf= stud' which means that variables are studentuzed before estimation and 'prt=initial;final' which means that sarting values and final results are both printed. load(GROCERDIR+'\data\anas.dat') r=ms_reg(['delts(log(construc))';'delts(log(ipi))';'delts(log(helpwanted))';'delts(log(revu))'],... list('diff','lagts(delts(log(construc)))','lagts(delts(log(ipi)))','lagts(delts(log(helpwanted)))','lagts(delts(log(revu)))'),'const',2,2,1) // This example takes the 4 variables from the 'anas' database, and estimates a MS model where all variables, once differentiated, follow an AR(1)+constant. The non switching variables are the autoregressive parts of the AR. Since they are obviously different for each endogenous variable, 2nd argument is a list with first element the keyword 'diff', and the name of the lagged variables as 2nd to 5th elements. For each regression, the constant is supposed to switch. Since it is the same variable for each regression, 3rd argument in the function is simply 'const'.The # of states is set to 2 (4th argument), the variances are supposed to swicth (5th is set to 2, the number of states), the variance matrix is heteroskedstik. load(GROCERDIR+'\data\anas.dat') r=ms_reg(['delts(log(construc))';'delts(log(ipi))';'delts(log(helpwanted))';'delts(log(revu))'],... list('diff','lagts(delts(log(construc)))','lagts(delts(log(ipi)))',[],'lagts(delts(log(revu)))'),list('diff','const','const',['const';'lagts(delts(log(helpwanted)))'],'const'),2,2,1) // This example is the same as second one, except for the autoregressive coefficient for variable 'delts(log(helpwanted))' which is now supposed to switch from one state to another: this imposes to define the third argument as a list, starting with the keyword 'diff' and with the exogenous variables for each regression entered as 2nd to 5th element of the list. | ![]() | ![]() |