Type: | Package |
Title: | Hypothesis Testing for Markov Switching Models |
Date: | 2025-02-24 |
Version: | 0.1.5 |
Maintainer: | Gabriel Rodriguez Rondon <gabriel.rodriguezrondon@mail.mcgill.ca> |
Description: | Implementation of hypothesis testing procedures described in Hansen (1992) <doi:10.1002/jae.3950070506>, Carrasco, Hu, & Ploberger (2014) <doi:10.3982/ECTA8609>, Dufour & Luger (2017) <doi:10.1080/07474938.2017.1307548>, and Rodriguez Rondon & Dufour (2024) https://grodriguezrondon.com/files/RodriguezRondon_Dufour_2024_MonteCarlo_LikelihoodRatioTest_MarkovSwitchingModels_20241015.pdf that can be used to identify the number of regimes in Markov switching models. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
LazyData: | TRUE |
RoxygenNote: | 7.3.1 |
Encoding: | UTF-8 |
URL: | https://github.com/roga11/MSTest |
BugReports: | https://github.com/roga11/MSTest/issues |
Imports: | stats, rlang, nloptr, Rcpp (≥ 1.0.1), numDeriv, pracma, foreach, GenSA, pso, GA, graphics |
LinkingTo: | Rcpp, RcppArmadillo |
Depends: | R (≥ 4.0.0) |
SystemRequirements: | C++17 |
NeedsCompilation: | yes |
Packaged: | 2025-02-24 18:23:58 UTC; gabrielrodriguez |
Author: | Gabriel Rodriguez Rondon [cre, aut], Jean-Marie Dufour [aut] |
Repository: | CRAN |
Date/Publication: | 2025-02-24 18:40:07 UTC |
Testing Markov Switching Models
Description
This package implements hypothesis testing procedures that can be used to identify the number of regimes in a Markov-Switching model.
Author(s)
Gabriel Rodriguez Rondon, gabriel.rodriguezrondon@mail.mcgill.ca (Maintainer)
Jean-Marie Dufour, jean-marie.dufour@mcgill.ca
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..
Dufour, Jean-Marie, and Richard Luger. 2017. “Identification-robust moment-based tests for Markov switching in autoregressive models.” Econometric Reviews 36 (6-9): 713–727.
Kasahara, Hiroyuk, and Katsum Shimotsu. 2018. “Testing the number of regimes in Markov regime switching models.” arXiv preprint arXiv:1801.06862.
Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.
Hamilton, James D. 1989. “A new approach to the economic analysis of nonstationary time series and the business cycle.” Econometrica 57 (2): 357–384.
Hamilton, James D. 1994. "Time series analysis". Princeton university press.
Hansen, Bruce E. 1992. “The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.
Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.
Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. “MSTest: An R-package for Testing Markov-Switching Models.” Unpublished manuscript.
Qu, Zhongjun, and Fan Zhuo. 2021. “Likelihood Ratio-Based Tests for Markov Regime Switching.” The Review of Economic Studies 88 (2): 937–968.
AIC of a ARmdl
object
Description
This is a method for the function AIC()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
AIC(object, ..., k = 2)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
Value
AIC value.
AIC of a HMmdl
object
Description
This is a method for the function AIC()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
AIC(object, ..., k = 2)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
Value
AIC value.
AIC of a MSARmdl
object
Description
This is a method for the function AIC()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
AIC(object, ..., k = 2)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
Value
AIC value.
AIC of a MSVARmdl
object
Description
This is a method for the function AIC()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
AIC(object, ..., k = 2)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
Value
AIC value.
AIC of a Nmdl
object
Description
This is a method for the function AIC()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
AIC(object, ..., k = 2)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
Value
AIC value.
AIC of a VARmdl
object
Description
This is a method for the function AIC()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
AIC(object, ..., k = 2)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
Value
AIC value.
Autoregressive X Model
Description
This function estimates an ARX model with p
lags.
This can be used for the null hypothesis of a linear model against an
alternative hypothesis of a Markov switching autoregressive model with k
regimes.
Usage
ARXmdl(Y, p, Z, control = list())
Arguments
Y |
A |
p |
Integer determining the number of autoregressive lags. |
Z |
A |
control |
List with model options including:
|
Value
List of class ARmdl
(S3
object) with model attributes including:
y: a
(T-p x 1)
matrix of observations.X: a
(T-p x p + const)
matrix of lagged observations with a leading column of1
s ifconst=TRUE
or not ifconst=FALSE
.x: a
(T-p x p)
matrix of lagged observations.fitted: a
(T-p x 1)
matrix of fitted values.resid: a
(T-p x 1)
matrix of residuals.mu: estimated mean of the process.
beta: a
((1 + p + qz) x 1)
matrix of estimated coefficients.betaZ: a
(qz x q)
matrix of estimated exogenous regressor coefficients.intercept: estimate of intercept.
phi: estimates of autoregressive coefficients.
stdev: estimated standard deviation of the process.
sigma: estimated variance of the process.
theta: vector containing:
mu
,sigma
, andphi
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance with
1
and0
otherwise.theta_var_ind: vector indicating location of variance with
1
and0
otherwise. This is the same astheta_sig_ind
inARmdl
.theta_phi_ind: vector indicating location of autoregressive coefficients with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations after lag transformation (i.e.,
n = T-p
).p: number of autoregressive lags.
q: number of series. This is always
1
inARmdl
.k: number of regimes. This is always
1
inARmdl
.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.
See Also
Examples
set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n = 500,
mu = 5,
sigma = 2,
phi = c(0.5,0.2))
# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)
# Set options for model estimation
control <- list(const = TRUE,
getSE = TRUE)
# Estimate model
y_ar_mdl <- ARmdl(y_simu$y, p = 2, control)
y_ar_mdl
Autoregressive Model
Description
This function estimates an autoregresive model with p
lags. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a Markov switching autoregressive model with k
regimes.
Usage
ARmdl(Y, p, control = list())
Arguments
Y |
A |
p |
Integer determining the number of autoregressive lags. |
control |
List with model options including:
|
Value
List of class ARmdl
(S3
object) with model attributes including:
y: a
(T-p x 1)
matrix of observations.X: a
(T-p x p + const)
matrix of lagged observations with a leading column of1
s ifconst=TRUE
or not ifconst=FALSE
.x: a
(T-p x p)
matrix of lagged observations.fitted: a
(T-p x 1)
matrix of fitted values.resid: a
(T-p x 1)
matrix of residuals.mu: estimated mean of the process.
beta: a
((1 + p) x 1)
matrix of estimated coefficients.intercept: estimate of intercept.
phi: estimates of autoregressive coefficients.
stdev: estimated standard deviation of the process.
sigma: estimated variance of the process.
theta: vector containing:
mu
,sigma
, andphi
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance with
1
and0
otherwise.theta_var_ind: vector indicating location of variance with
1
and0
otherwise. This is the same astheta_sig_ind
inARmdl
.theta_phi_ind: vector indicating location of autoregressive coefficients with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations after lag transformation (i.e.,
n = T-p
).p: number of autoregressive lags.
q: number of series. This is always
1
inARmdl
.k: number of regimes. This is always
1
inARmdl
.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.
See Also
Examples
set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n = 500,
mu = 5,
sigma = 2,
phi = c(0.5,0.2))
# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)
# Set options for model estimation
control <- list(const = TRUE,
getSE = TRUE)
# Estimate model
y_ar_mdl <- ARmdl(y_simu$y, p = 2, control)
y_ar_mdl
BIC of a ARmdl
object
Description
This is a method for the function BIC()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
BIC(object, ...)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
Value
BIC value.
BIC of a HMmdl
object
Description
This is a method for the function BIC()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
BIC(object, ...)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
Value
BIC value.
BIC of a MSARmdl
object
Description
This is a method for the function BIC()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
BIC(object, ...)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
Value
BIC value.
BIC of a MSVARmdl
object
Description
This is a method for the function BIC()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
BIC(object, ...)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
Value
BIC value.
BIC of a Nmdl
object
Description
This is a method for the function BIC()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
BIC(object, ...)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
Value
BIC value.
BIC of a VARmdl
object
Description
This is a method for the function BIC()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
BIC(object, ...)
Arguments
object |
a fitted model object for which there exists a
|
... |
optionally more fitted model objects. |
Value
BIC value.
Carrasco, Hu, and Ploberger (2014) parameter stability test
Description
This function performs the CHP (2014) parameter stability test as outline in Carrasco, M., Hu, L. and Ploberger, W. (2014). Original source code can be found here.
Usage
CHPTest(Y, p, control = list())
Arguments
Y |
A ( |
p |
Integer determining the number of autoregressive lags. |
control |
List with test procedure options including:
|
Value
List of class CHPTest
(S3
object) with model attributes including:
mdl_h0: List with restricted model attributes. This will be of class
ARmdl
(S3
object). SeeARmdl
.supTS: supTS test statistic value.
expTS: expTS test statistic value.
supTS_N: A (
N x 1
) vector with simulated supTS test statistics under null hypothesis.expTS_N: A (
N x 1
) vector with simulated expTS test statistics under null hypothesis.pval_supTS: P-value for supTS version of parameter stability test.
pval_expTS: P-value for expTS version of parameter stability test.
supTS_cv: Vector with 90%, 95%, and 99% bootstrap critical values for supTS version of parameter stability test.
expTS_cv: Vector with 90%, 95%, and 99% bootstrap critical values for expTS version of parameter stability test.
control: List with test procedure options used.
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Examples
# load data used in Hamilton 1989
y84 <- as.matrix(hamilton84GNP$GNP_gr)
# Set test procedure options
control = list(N = 1000,
rho_b = 0.7,
msvar = FALSE)
# perform test with switch in mean only on Hamilton 1989 data
mdl_84_msmu <- CHPTest(y84, p = 4, control = control)
summary(mdl_84_msmu)
Bootstrap critical values for CHP 2014 parameter stability test
Description
This bootstrap procedure is described on pg. 771 of CHP 2014.
Usage
CHPbootCV(mdl, rho_b, N, msvar)
Arguments
mdl |
List containing model attributes (see |
rho_b |
Number determining bounds for distribution of |
N |
Number of bootstrap simulations. |
msvar |
Boolean indicator. If |
Value
Bootstrap critical values
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Monte Carlo moment-based test for Markov switching model
Description
This function performs the Local Monte Carlo moment-based test for Markov switching autoregressive models proposed in Dufour & Luger (2017).
Usage
DLMCTest(Y, p, control = list())
Arguments
Y |
Series to be tested |
p |
Number of autoregressive lags. |
control |
List with test procedure options including:
|
Value
List of class DLMCTest
(S3
object) with attributes including:
mdl_h0: List with restricted model attributes. This will be of class
ARmdl
ifp>0
orNmdl
otherwise (S3
objects). SeeARmdl
orNmdl
.theta: Value of nuisance parameters. Specifically, these are the consistent estimates of nuisance parameters as discussed in Dufour & Luger (2017) LMC procedure.
S0: A (
1 x 4
)) matrix containing the four moment-based test statistics defined in (11
) - (14
) in Dufour & Luger (2017).F0_min: Test statistic value for min version of Local Monte Carlo moment-based test.
F0_prod: Test statistic value for prod version of Local Monte Carlo moment-based test.
FN_min: A (
N x 1
) vector with simulated test statistics for min version of Local Monte Carlo moment-based test under null hypothesis.FN_prod: A (
N x 1
) vector with simulated test statistics for prod version of Local Monte Carlo moment-based test under null hypothesis.pval_min: P-value for min version of Local Monte Carlo moment-based test.
pval_prod: P-value for prod version of Local Monte Carlo moment-based test.
FN_min_cv: Vector with 90%, 95%, and 99% Monte Carlo critical values for min version of Local Monte Carlo moment-based test.
FN_prod_cv: Vector with 90%, 95%, and 99% Monte Carlo critical values for prod version of Local Monte Carlo moment-based test.
control: List with test procedure options used.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Examples
set.seed(1234)
# load data used in Hamilton 1989 and extended data used in CHP 2014
y84 <- as.matrix(hamilton84GNP$GNP_gr)
y10 <- as.matrix(chp10GNP$GNP_gr)
# Set test procedure options
lmc_control = list(N = 99,
simdist_N = 10000,
getSE = TRUE)
# perform test on Hamilton 1989 data
lmc_gnp84 <- DLMCTest(y84, p = 4, control = lmc_control)
summary(lmc_gnp84)
Maximized Monte Carlo moment-based test for Markov switching model
Description
This function performs the maximized Monte Carlo moment-based test for Markov switching autoregressive models proposed in Dufour & Luger (2017).
Usage
DLMMCTest(Y, p, control = list())
Arguments
Y |
Series to be tested |
p |
Number of autoregressive lags. |
control |
List with test procedure options including:
|
Value
List of class DLMCTest
(S3
object) with attributes including:
mdl_h0: List with restricted model attributes. This will be of class
ARmdl
ifp>0
orNmdl
otherwise (S3
objects). SeeARmdl
orNmdl
.theta_max_min: Value of nuisance parameters when min version of p-value is maximized as discussed in Dufour & Luger (2017) MMC procedure.
theta_max_prod: Value of nuisance parameters when prod version of p-value is maximized as discussed in Dufour & Luger (2017) MMC procedure.
theta_low: Lower bound on nuisance parameter values used when searching for maximum p-value.
theta_upp: Upper bound on nuisance parameter values used when searching for maximum p-value.
S0_min: A (
1 x 4
)) matrix containing the four moment-based test statistics defined in (11
) - (14
) in Dufour & Luger (2017) whentheta_min
is used.S0_prod: A (
1 x 4
)) matrix containing the four moment-based test statistics defined in (11
) - (14
) in Dufour & Luger (2017) whentheta_prod
is used.F0_min: Test statistic value for min version of Maximized Monte Carlo moment-based test.
F0_prod: Test statistic value for prod version of Maximized Monte Carlo moment-based test.
FN_min: A (
N x 1
) vector with simulated test statistics for min version of Maximized Monte Carlo moment-based test under null hypothesis.FN_prod: A (
N x 1
) vector with simulated test statistics for prod version of Maximized Monte Carlo moment-based test under null hypothesis.pval_min: Maximum p-value for min version of Maximized Monte Carlo moment-based test.
pval_prod: Maximum p-value for prod version of Local Monte Carlo moment-based test.
FN_min_cv: Vector with 90%, 95%, and 99% Monte Carlo critical values for min version of Local Monte Carlo moment-based test.
FN_prod_cv: Vector with 90%, 95%, and 99% Monte Carlo critical values for prod version of Local Monte Carlo moment-based test.
control: List with test procedure options used.
optim_min_output: List with optimization output for min version of Maximized Monte Carlo moment-based test.
optim_prod_output: List with optimization output for prod version of Maximized Monte Carlo moment-based test.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Examples
set.seed(1234)
# load data used in Hamilton 1989 and extended data used in CHP 2014
y84 <- as.matrix(hamilton84GNP$GNP_gr)
y10 <- as.matrix(chp10GNP$GNP_gr)
# Set test procedure options
mmc_control <- list(N = 99,
simdist_N = 10000,
getSE = TRUE,
eps = 0,
CI_union = TRUE,
lambda = 100,
stationary_ind = TRUE,
optim_type = "GenSA",
silence = FALSE,
threshold_stop = 1,
maxit = 200)
# perform test on Hamilton 1989 data
mmc_gnp84 <- DLMMCTest(y84, p = 4, control = mmc_control)
summary(mmc_gnp84)
MMC nuisance parameter bounds for Moment-based test
Description
This function is used to determine the lower and upper bounds for the MMC LRT parameter search.
Usage
DLMMC_bounds(mdl_h0, con)
Arguments
mdl_h0 |
List with restricted model properties. |
con |
List with control options provided to |
Value
List with theta_low
, vector of parameter lower bounds, and theta_upp
, vector of parameter upper bounds.
Moment-based MMC test p-value
Description
This functions is used by numerical optimization algorithms for find maximum p-value given parameter vector theta
.
Usage
DLMMCpval_fun(
theta,
y,
x,
params,
sim_stats,
pval_type,
stationary_ind,
lambda
)
Arguments
theta |
Value of nuisance parameters. Specifically, these are the consistent estimates of nuisance parameters as discussed in Dufour & Luger (2017) LMC procedure. |
y |
series being tested. |
x |
lagged values of series. |
params |
A ( |
sim_stats |
A ( |
pval_type |
String determining the type of method used to combine p-values. If set to "min" the min method of combining p-values is used as in Fisher 1932 and Pearson 1933. If set to "prod" the product of p-values is used as in Tippett 1931 and Wilkinson 1951. |
stationary_ind |
Boolean indicator determining if only stationary solutions should be considered if |
lambda |
Numeric value for penalty on stationary constraint not being met. Default is |
Value
Maximized Monte Carlo p-value.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Moment-based MMC test (negative) p-value
Description
This functions is used by numerical optimization algorithms for find negative of maximum p-value given parameter vector theta
.
Usage
DLMMCpval_fun_min(
theta,
y,
x,
params,
sim_stats,
pval_type,
stationary_ind,
lambda
)
Arguments
theta |
Value of nuisance parameters. Specifically, these are the consistent estimates of nuisance parameters as discussed in Dufour & Luger (2017) LMC procedure. |
y |
series being tested. |
x |
lagged values of series. |
params |
A ( |
sim_stats |
A ( |
pval_type |
String determining the type of method used to combine p-values. If set to "min" the min method of combining p-values is used as in Fisher 1932 and Pearson 1933. If set to "prod" the product of p-values is used as in Tippett 1931 and Wilkinson 1951. |
stationary_ind |
Boolean indicator determining if only stationary solutions should be considered if |
lambda |
Numeric value for penalty on stationary constraint not being met. Default is |
Value
Negative Maximized Monte Carlo p-value.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Maximization step of EM algorithm for Hidden Markov model
Description
This function performs the maximization step of the Expectation Maximization algorithm for Hidden Markov models.
Usage
EMaximization_HMmdl(theta, mdl, MSloglik_output, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
MSloglik_output |
List with output from |
k |
Integer determining the number of regimes. |
Value
List with new maximized parameters.
Maximization step of EM algorithm for Markov-switching ARX model
Description
This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching ARX model.
Usage
EMaximization_MSARXmdl(theta, mdl, MSloglik_output, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
MSloglik_output |
List with output from |
k |
Integer determining the number of regimes. |
Value
List with new maximized parameters.
Maximization step of EM algorithm for Markov-switching autoregressive model
Description
This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching autoregressive model.
Usage
EMaximization_MSARmdl(theta, mdl, MSloglik_output, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
MSloglik_output |
List with output from |
k |
Integer determining the number of regimes. |
Value
List with new maximized parameters.
Maximization step of EM algorithm for Markov-switching VARX model
Description
This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching VARX model.
Usage
EMaximization_MSVARXmdl(theta, mdl, MSloglik_output, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
MSloglik_output |
List with output from |
k |
Integer determining the number of regimes. |
Value
List with new maximized parameters.
Maximization step of EM algorithm for Markov-switching vector autoregressive model
Description
This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching vector autoregressive model.
Usage
EMaximization_MSVARmdl(theta, mdl, MSloglik_output, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
MSloglik_output |
List with output from |
k |
Integer determining the number of regimes. |
Value
List with new maximized parameters.
EM algorithm iteration for Hidden Markov model
Description
This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for a Hidden Markov model.
Usage
EMiter_HMmdl(mdl, EMest_output, k)
Arguments
mdl |
List with model attributes. |
EMest_output |
List with attributes from previous iteration. |
k |
Integer determining the number of regimes. |
Value
List with attributes from new iteration.
EM algorithm iteration for Markov-switching ARX model
Description
This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching ARX model.
Usage
EMiter_MSARXmdl(mdl, EMest_output, k)
Arguments
mdl |
List with model attributes. |
EMest_output |
List with attributes from previous iteration. |
k |
Integer determining the number of regimes. |
Value
List with attributes from new iteration.
EM algorithm iteration for Markov-switching autoregressive model
Description
This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching autoregressive model.
Usage
EMiter_MSARmdl(mdl, EMest_output, k)
Arguments
mdl |
List with model attributes. |
EMest_output |
List with attributes from previous iteration. |
k |
Integer determining the number of regimes. |
Value
List with attributes from new iteration.
EM algorithm iteration for Markov-switching VARX model
Description
This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching VARX model.
Usage
EMiter_MSVARXmdl(mdl, EMest_output, k)
Arguments
mdl |
List with model attributes. |
EMest_output |
List with attributes from previous iteration. |
k |
Integer determining the number of regimes. |
Value
List with attributes from new iteration.
EM algorithm iteration for Markov-switching vector autoregressive model
Description
This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching vector autoregressive model.
Usage
EMiter_MSVARmdl(mdl, EMest_output, k)
Arguments
mdl |
List with model attributes. |
EMest_output |
List with attributes from previous iteration. |
k |
Integer determining the number of regimes. |
Value
List with attributes from new iteration.
Hidden Markov model log-likelihood function
Description
This function computes the log-likelihood for a Hidden Markov model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.
Usage
ExpectationM_HMmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
List which includes log-likelihood value and smoothed probabilities of each regime.
Markov-switching ARX log-likelihood function
Description
This function computes the log-likelihood for a markov-switching autoregressive model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching ARX model.
Usage
ExpectationM_MSARXmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
List which includes log-likelihood and smoothed probabilities of each regime.
Markov-switching autoregressive log-likelihood function
Description
This function computes the log-likelihood for a markov-switching autoregressive model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.
Usage
ExpectationM_MSARmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
List which includes log-likelihood and smoothed probabilities of each regime.
Markov-switching VARX log-likelihood function
Description
This function computes the log-likelihood for a markov-switching VARX model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.
Usage
ExpectationM_MSVARXmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
List which includes log-likelihood and smoothed probabilities of each regime.
Markov-switching vector autoregressive log-likelihood function
Description
This function computes the log-likelihood for a markov-switching vector autoregressive model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.
Usage
ExpectationM_MSVARmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
List which includes log-likelihood and smoothed probabilities of each regime.
Hansen (1992) likelihood ratio test
Description
This function performs Hansen's likelihood ratio test as described in Hansen (1992). Original source code can be found here.
Usage
HLRTest(Y, p, control = list())
Arguments
Y |
A ( |
p |
Integer determining the number of autoregressive lags. |
control |
List with test procedure options including:
|
Value
List of class HLRTest
(S3
object) with model attributes including:
mdl_h0: List with restricted model attributes. This will be of class
ARmdl
(S3
object). SeeARmdl
.LR0: Likelihood ratio test statistic value.
LRN: A (
N x 1
) vector with simulated LRT statistics under null hypothesis.pval: P-value.
LR_cv: A (
nwband x 3
) matrix with 90%, 95%, and 99% critical values in each column respectively.coef: Vector of coefficients from restricted model and grid search that maximized standardized LRT.
control: List with test procedure options used.
References
Hansen, Bruce E. 1992. “The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.
Hansen, Bruce E. 1996. “Erratum: The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.
Examples
# --------------------------- Use simulated process ----------------------------
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n = 200,
mu = c(5,1),
sigma = c(1,1),
phi = c(0.5),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)
hlrt_control <- list(ix = 1,
gridsize = 7,
pgrid_from = 0.05,
pgrid_by = 0.05,
pgrid_to = 0.95,
mugrid_from = 0,
mugrid_by = 1)
hlrt <- HLRTest(y_ms_simu$y, p = 1, control = hlrt_control)
summary(hlrt)
HLR param search
Description
This function performs the parameter grid search needed for the likelihood ratio test described in Hansen (1992).
Usage
HLRparamSearch(gx, gp, gq, b, null, HLR_opt_ls)
Arguments
gx |
matrix/grid containing values for switching parameters in second regime. |
gp |
matrix/grid containing values for probability of going from regime 1 at ( |
gq |
matrix/grid containing values for probability of going from regime 2 at ( |
b |
vector of initial parameter values of restricted model. |
null |
vector with likelihood under the null hypothesis. |
HLR_opt_ls |
List with model properties and test controls defined in |
Value
List which contains:
cs: Vector with standardized LRT statistic for each grid point.
draws: List with a (
nwband+1 x N
matrix for each grid point. Each row of these matrices is a vector of simulated test statistics under the null hypothesis for a value of bandwidth .coefficients: A matrix with coefficients for each grid point.
Hidden Markov model
Description
This function estimates a Hidden Markov model with k
regimes.
Usage
HMmdl(Y, k, Z = NULL, control = list())
Arguments
Y |
a |
k |
integer determining the number of regimes to use in estimation. Must be greater than or equal to |
Z |
an otpional |
control |
List with model options including:
|
Value
List of class HMmdl
(S3
object) with model attributes including:
y: a
(T x q)
matrix of observations.fitted: a
(T x q)
matrix of fitted values.resid: a
(T x q)
matrix of residuals.mu: a
(k x q)
matrix of estimated means of each process.beta: if
q=1
, this is a((1 + qz) x k)
matrix of estimated coefficients. Ifq>1
, this is a list containingk
separate((1 + qz) x q)
matrix of estimated coefficients for each regime.betaZ: a
(qz x q)
matrix of estimated exogenous regressor coefficients.intercept: a
(k x q)
matrix of estimated intercept of each process. If Z is Null, this is the same as mu.stdev: If
q=1
, this is a(k x 1)
matrix with estimated standard. Ifq>1
, this is a List withk
(q x q)
matrices with estimated standard deviation on the diagonal.sigma: If
q=1
, this is a(k x 1)
matrix with variances. Ifq>1
, this is a List withk
(q x q)
estimated covariance matrix.theta: vector containing:
mu
andvech(sigma)
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance and covariances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise.theta_P_ind: vector indicating location of transition matrix elements with
1
and0
otherwise.n: number of observations (same as
T
).q: number of series.
k: number of regimes in estimated model.
P: a
(k x k)
transition matrix.pinf: a
(k x 1)
vector with limiting probabilities of each regime.St: a
(T x k)
vector with smoothed probabilities of each regime at each timet
.deltath: double with maximum absolute difference in vector
theta
between last iteration.iterations: number of EM iterations performed to achieve convergence (if less than
maxit
).theta_0: vector of initial values used.
init_used: number of different initial values used to get a finite solution. See description of input
maxit_converge
.msmu: Boolean. If
TRUE
model was estimated with switch in mean. IfFALSE
model was estimated with constant mean.msvar: Boolean. If
TRUE
model was estimated with switch in variance. IfFALSE
model was estimated with constant variance.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.trace: List with Lists of estimation output for each initial value used due to
use_diff_init > 1
.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..
Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.
Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.
See Also
Estimation of Hidden Markov model by EM Algorithm
Description
Estimate Hidden Markov model by EM algorithm. This function is used by HMmdl
which organizes the output and takes raw data as input.
Usage
HMmdl_em(theta_0, mdl, k, optim_options)
Arguments
theta_0 |
vector with initial values for parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
optim_options |
List with optimization options. |
Value
List with model results.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.
Hidden Markov model maximum likelihood estimation
Description
This function computes estimate a Hidden Markov model using MLE.
Usage
HMmdl_mle(theta_0, mdl_in, k, optim_options)
Arguments
theta_0 |
vector containing initial values to use in optimization |
mdl_in |
List with model properties (can be obtained from estimating linear model i.e., using |
k |
integer determining the number of regimes |
optim_options |
List containing
|
Value
List with model attributes
Monte Carlo Likelihood Ratio Test
Description
This function performs the Local Monte Carlo likelihood ratio test (LMC-LRT) proposed in Rodriguez-Rondon & Dufour (2024). As discussed in their work, this test can be applied in very general settings and can be used to compare varioous regimes under the null and under the alternative.
Usage
LMCLRTest(Y, p, k0, k1, Z = NULL, control = list())
Arguments
Y |
Series to be tested. Must be a ( |
p |
Number of autoregressive lags. Must be greater than or equal to 0. |
k0 |
Number of regimes under null hypothesis. Must be greater than or equal to 1. |
k1 |
Number of regimes under alternative hypothesis. Must be greater than |
Z |
Exogenous regressors. Optional input and default is NULL. When used, it should be a ( |
control |
List with test procedure options including:
|
Value
List of class LMCLRTest
(S3
object) with attributes including:
mdl_h0: List with restricted model attributes.
mdl_h1: List with unrestricted model attributes.
LRT_0: Value of test statistic from observed data.
LRN: A (
N x 1
) vector of test statistics from data simulated under the null hypothesis.pval: P-value of Local Monte Carlo Likelihood Ratio Test.
LRN_cv: Vector with 90%, 95%, and 99% Monte Carlo simulated critical values (from vector
LRN
). These are not asymptotic critical values.control: List with test procedure options used.
References
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
Examples
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n = 200,
mu = c(5,10),
sigma = c(1,4),
phi = c(0.5),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)
# ------ MS-AR example ----- #
# Set test procedure options
lmc_control = list(N = 19,
burnin = 100,
converge_check = NULL,
mdl_h0_control = list(const = TRUE,
getSE = TRUE),
mdl_h1_control = list(msmu = TRUE,
msvar = TRUE,
getSE = TRUE,
method = "EM",
use_diff_init = 1))
lmctest <- LMCLRTest(y_ms_simu$y, p = 1, k0 = 1 , k1 = 2, control = lmc_control)
summary(lmctest)
Likelihood Ratio Test Statistic Sample Distribution
Description
This function simulates the sample distribution under the null hypothesis.
Usage
LR_samp_dist(mdl_h0, k1, N, burnin, Z, mdl_h0_control, mdl_h1_control)
Arguments
mdl_h0 |
List with restricted model properties. |
k1 |
integer specifying the number of regimes under the alternative hypothesis. |
N |
integer specifying the number of replications. |
burnin |
integer specifying the number of observations to drop from beginning of simulation. |
mdl_h0_control |
List with controls/options used to estimate restricted model. |
mdl_h1_control |
List with controls/options used to estimate unrestricted model. |
Value
vector of simulated LRT statistics
References
Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.
Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
Monte Carlo Likelihood Ratio Test sample distribution (parallel version)
Description
This function simulates the sample distribution under the null hypothesis using a parallel pool.
Usage
LR_samp_dist_par(
mdl_h0,
k1,
N,
burnin,
Z,
mdl_h0_control,
mdl_h1_control,
workers
)
Arguments
mdl_h0 |
List with restricted model properties. |
k1 |
integer specifying the number of regimes under the alternative hypothesis. |
N |
integer specifying the number of replications. |
burnin |
integer specifying the number of observations to drop from beginning of simulation. |
mdl_h0_control |
List with controls/options used to estimate restricted model. |
mdl_h1_control |
List with controls/options used to estimate unrestricted model. |
workers |
Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open. |
Value
vector of simulated LRT statistics
References
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2023. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
Monte Carlo P-value
Description
This function computes the Monte Carlo P-value.
Usage
MCpval(test_stat, null_vec, type = "geq")
Arguments
test_stat |
Test statistic under the alternative (e.g. |
null_vec |
A ( |
type |
String determining type of test. options are: "geq" for right-tail test, "leq" for left-tail test, "abs" for absolute value test and "two-tail" for two-tail test. |
Value
MC p-value of test
References
Dufour, Jean-Marie 2006. "Monte Carlo tests with nuisance parameters: A general approach to finite-sample inference and nonstandard asymptotics". Journal of Econometrics, 133(2), 443-477.
Dufour, Jean-Marie, and Richard Luger. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models". Econometric Reviews, 36(6-9), 713-727.
Maximized Monte Carlo Likelihood Ratio Test
Description
This function performs the Maximized Monte Carlo likelihood ratio test (MMC-LRT) proposed in Rodriguez-Rondon & Dufour (2024).
Usage
MMCLRTest(Y, p, k0, k1, Z = NULL, control = list())
Arguments
Y |
Series to be tested. Must be a ( |
p |
Number of autoregressive lags. Must be greater than or equal to 0. |
k0 |
Number of regimes under null hypothesis. Must be greater than or equal to 1. |
k1 |
Number of regimes under alternative hypothesis. Must be greater than |
Z |
Exogenous regressors. Optional input and default is NULL. When used, it should be a ( |
control |
List with test procedure options including:
|
Value
List of class LMCLRTest
(S3
object) with attributes including:
mdl_h0: List with restricted model attributes.
mdl_h1: List with unrestricted model attributes.
LRT_0: Value of test statistic from observed data.
LRN: A (
N x 1
) vector of test statistics from data simulated under the null hypothesis.pval: P-value of Local Monte Carlo Likelihood Ratio Test.
LRN_cv: Vector with 90%, 95%, and 99% Monte Carlo simulated critical values (from vector
LRN
). These are not asymptotic critical values.control: List with test procedure options used.
References
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
Examples
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n = 200,
mu = c(5,10),
sigma = c(1,4),
phi = c(0.5),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)
# Set test procedure options
mmc_control = list(N = 19,
burnin = 100,
converge_check = NULL,
eps = 0.1,
CI_union = TRUE,
silence = FALSE,
threshold_stop = 0.05 + 1e-6,
type = "pso",
maxit = 100,
mdl_h0_control = list(const = TRUE,
getSE = TRUE),
mdl_h1_control = list(msmu = TRUE,
msvar = TRUE,
getSE = TRUE,
method = "EM",
use_diff_init = 1))
MMCtest <- MMCLRTest(y_ms_simu$y, p = 1 , k0 = 1 , k1 = 2, control = mmc_control)
summary(MMCtest)
Monte Carlo Likelihood Ratio Test P-value Function
Description
This function computes the Maximum Monte Carlo P-value.
Usage
MMCLRpval_fun(
theta_h0,
mdl_h0,
k1,
LT_h1,
N,
burnin,
workers,
lambda,
stationary_constraint,
thtol,
Z,
exog,
mdl_h0_control,
mdl_h1_control
)
Arguments
theta_h0 |
vector of parameter values under the null being considered. |
mdl_h0 |
List with restricted model properties. |
k1 |
integer determining the number of regimes under the alternative. |
LT_h1 |
double specifying maximum log likelihood under alternative. |
N |
integer specifying the number of replications. |
burnin |
integer specifying the number of observations to drop from beginning of simulation. |
workers |
Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open. |
lambda |
Double determining penalty on nonlinear constraint. |
stationary_constraint |
Boolean determining if only stationary solutions are considered (if |
thtol |
double determining the convergence criterion used during estimation. |
mdl_h0_control |
List with controls/options used to estimate restricted model. |
mdl_h1_control |
List with controls/options used to estimate unrestricted model. |
Value
MMC p-value
Monte Carlo Likelihood Ratio Test P-value Function
Description
This function computes the (negative) Maximum Monte Carlo P-value.
Usage
MMCLRpval_fun_min(
theta,
mdl_h0,
k1,
LT_h1,
N,
burnin,
workers,
lambda,
stationary_constraint,
thtol,
Z,
exog,
mdl_h0_control,
mdl_h1_control
)
Arguments
theta |
vector of parameter values being considered. |
mdl_h0 |
List with restricted model properties. |
k1 |
integer determining the number of regimes under the alternative. |
LT_h1 |
double specifying maximum log likelihood under alternative. |
N |
integer specifying the number of replications. |
burnin |
integer specifying the number of observations to drop from beginning of simulation. |
workers |
Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open. |
lambda |
Double determining penalty on nonlinear constraint. |
stationary_constraint |
Boolean determining if only stationary solutions are considered (if |
thtol |
double determining the convergence criterion used during estimation. |
mdl_h0_control |
List with controls/options used to estimate restricted model. |
mdl_h1_control |
List with controls/options used to estimate unrestricted model. |
Value
negative MMC p-value
MMC nuisance parameter bounds
Description
This function is used to determine the lower and upper bounds for the MMC LRT parameter search.
Usage
MMC_bounds(mdl_h0, con)
Arguments
mdl_h0 |
List with restricted model properties. |
con |
List with control options provided to MMC LRT procedure. |
Value
List with theta_low
, vector of parameter lower bounds, and theta_upp
, vector of parameter upper bounds.
References
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
Markov-switching autoregressive model
Description
This function estimates a Markov-switching autoregressive model
Usage
MSARXmdl(Y, p, k, Z, control = list())
Arguments
Y |
a |
p |
integer for the number of lags to use in estimation. Must be greater than or equal to |
k |
integer for the number of regimes to use in estimation. Must be greater than or equal to |
Z |
a |
control |
List with model options including:
|
Value
List of class MSARmdl
(S3
object) with model attributes including:
y: a
(T x 1)
matrix of observations.X: a
(T-p x p + const)
matrix of lagged observations with a leading column of1
s.x: a
(T-p x p)
matrix of lagged observations.fitted: a
(T x 1)
matrix of fitted values.resid: a
(T x 1)
matrix of residuals.intercept: a
(k x 1)
vector of estimated intercepts of each process.mu: a
(k x 1)
vector of estimated means of each process.beta: a
((1 + p + qz) x k)
matrix of estimated coefficients.betaZ: a
(qz x q)
matrix of estimated exogenous regressor coefficients.phi: estimates of autoregressive coefficients.
stdev: a
(k x 1)
vector of estimated standard deviation of each process.sigma: a
(k x 1)
estimated covariance matrix.theta: vector containing:
mu
andvech(sigma)
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise. This is the same astheta_sig_ind
inMSARmdl
.theta_P_ind: vector indicating location of transition matrix elements with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations (same as
T
).p: number of autoregressive lags.
q: number of series. This is always
1
inMSARmdl
.k: number of regimes in estimated model.
P: a
(k x k)
transition matrix.pinf: a
(k x 1)
vector with limiting probabilities of each regime.St: a
(T x k)
vector with smoothed probabilities of each regime at each timet
.deltath: double with maximum absolute difference in vector
theta
between last iteration.iterations: number of EM iterations performed to achieve convergence (if less than
maxit
).theta_0: vector of initial values used.
init_used: number of different initial values used to get a finite solution. See description of input
maxit_converge
.msmu: Boolean. If
TRUE
model was estimated with switch in mean. IfFALSE
model was estimated with constant mean.msvar: Boolean. If
TRUE
model was estimated with switch in variance. IfFALSE
model was estimated with constant variance.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.trace: List with Lists of estimation output for each initial value used due to
use_diff_init > 1
.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..
Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.
See Also
Examples
# --------------------------- Use simulated process ----------------------------
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n = 200,
mu = c(5,10),
sigma = c(1,4),
phi = c(0.5),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)
# Set options for model estimation
control <- list(msmu = TRUE,
msvar = TRUE,
method = "EM",
use_diff_init = 1)
# Estimate model
ms_mdl <- MSARmdl(y_ms_simu$y, p = 1, k = 2, control = control)
summary(ms_mdl)
Estimation of Markov-switching ARX model by EM Algorithm
Description
Estimate Markov-switching ARX model by EM algorithm. This function is used by MSARmdl
which organizes the output and takes raw data as input.
Usage
MSARXmdl_em(theta_0, mdl, k, optim_options)
Arguments
theta_0 |
vector with initial values for parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
optim_options |
List with optimization options. |
Value
List with model results.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.
Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.
Markov-switching autoregressive model
Description
This function estimates a Markov-switching autoregressive model
Usage
MSARmdl(Y, p, k, control = list())
Arguments
Y |
(T x 1) vector with observational data. |
p |
integer for the number of lags to use in estimation. Must be greater than or equal to |
k |
integer for the number of regimes to use in estimation. Must be greater than or equal to |
control |
List with model options including:
|
Value
List of class MSARmdl
(S3
object) with model attributes including:
y: a
(T x 1)
matrix of observations.X: a
(T-p x p + const)
matrix of lagged observations with a leading column of1
s.x: a
(T-p x p)
matrix of lagged observations.fitted: a
(T x 1)
matrix of fitted values.resid: a
(T x 1)
matrix of residuals.intercept: a
(k x 1)
vector of estimated intercepts of each process.mu: a
(k x 1)
vector of estimated means of each process.beta: a
((1 + p) x k)
matrix of estimated coefficients.phi: estimates of autoregressive coefficients.
stdev: a
(k x 1)
vector of estimated standard deviation of each process.sigma: a
(k x 1)
estimated covariance matrix.theta: vector containing:
mu
andvech(sigma)
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise. This is the same astheta_sig_ind
inMSARmdl
.theta_P_ind: vector indicating location of transition matrix elements with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations (same as
T
).p: number of autoregressive lags.
q: number of series. This is always
1
inMSARmdl
.k: number of regimes in estimated model.
P: a
(k x k)
transition matrix.pinf: a
(k x 1)
vector with limiting probabilities of each regime.St: a
(T x k)
vector with smoothed probabilities of each regime at each timet
.deltath: double with maximum absolute difference in vector
theta
between last iteration.iterations: number of EM iterations performed to achieve convergence (if less than
maxit
).theta_0: vector of initial values used.
init_used: number of different initial values used to get a finite solution. See description of input
maxit_converge
.msmu: Boolean. If
TRUE
model was estimated with switch in mean. IfFALSE
model was estimated with constant mean.msvar: Boolean. If
TRUE
model was estimated with switch in variance. IfFALSE
model was estimated with constant variance.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.trace: List with Lists of estimation output for each initial value used due to
use_diff_init > 1
.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..
Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.
See Also
Examples
# --------------------------- Use simulated process ----------------------------
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n = 200,
mu = c(5,10),
sigma = c(1,4),
phi = c(0.5),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)
# Set options for model estimation
control <- list(msmu = TRUE,
msvar = TRUE,
method = "EM",
use_diff_init = 1)
# Estimate model
ms_mdl <- MSARmdl(y_ms_simu$y, p = 1, k = 2, control = control)
summary(ms_mdl)
Estimation of Markov-switching autoregressive model by EM Algorithm
Description
Estimate Markov-switching autoregressive model by EM algorithm. This function is used by MSARmdl
which organizes the output and takes raw data as input.
Usage
MSARmdl_em(theta_0, mdl, k, optim_options)
Arguments
theta_0 |
vector with initial values for parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
optim_options |
List with optimization options. |
Value
List with model results.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.
Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.
Markov-switching autoregressive maximum likelihood estimation
Description
This function computes estimate a Markov-switching autoregressive model using MLE.
Usage
MSARmdl_mle(theta_0, mdl_in, k, optim_options)
Arguments
theta_0 |
vector containing initial values to use in optimization |
mdl_in |
List with model properties (can be obtained from estimating linear model i.e., using |
k |
integer determining the number of regimes |
optim_options |
List containing
|
Value
List with model attributes
Markov-switching vector autoregressive model
Description
This function estimates a Markov-switching vector autoregressive model
Usage
MSVARXmdl(Y, p, k, Z, control = list())
Arguments
Y |
( |
p |
integer for the number of lags to use in estimation. Must be greater than or equal to |
k |
integer for the number of regimes to use in estimation. Must be greater than or equal to |
Z |
a |
control |
List with optimization options including:
|
Value
List of class MSVARmdl
(S3
object) with model attributes including:
y: a
(T-p x q)
matrix of observations.X: a
(T-p x p*q + const)
matrix of lagged observations with a leading column of1
s.x: a
(T-p x p*q)
matrix of lagged observations.resid: a
(T-p x q)
matrix of residuals.fitted: a
(T x q)
matrix of fitted values.intercept: a
(k x q)
matrix of estimated intercepts of each process.mu: a
(k x q)
matrix of estimated means of each process.beta: a list containing
k
separate((1 + p + qz) x q)
matrix of estimated coefficients for each regime.betaZ: a
(qz x q)
matrix of estimated exogenous regressor coefficients.phi: estimates of autoregressive coefficients.
Fmat: Companion matrix containing autoregressive coefficients.
stdev: List with
k
(q x q)
matrices with estimated standard deviation on the diagonal.sigma: List with
k
(q x q)
matrices with estimated covariance matrix.theta: vector containing:
mu
andvech(sigma)
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance and covariances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise.theta_P_ind: vector indicating location of transition matrix elements with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations (same as
T
).p: number of autoregressive lags.
q: number of series.
k: number of regimes in estimated model.
P: a
(k x k)
transition matrix.pinf: a
(k x 1)
vector with limiting probabilities of each regime.St: a
(T x k)
vector with smoothed probabilities of each regime at each timet
.deltath: double with maximum absolute difference in vector
theta
between last iteration.iterations: number of EM iterations performed to achieve convergence (if less than
maxit
).theta_0: vector of initial values used.
init_used: number of different initial values used to get a finite solution. See description of input
maxit_converge
.msmu: Boolean. If
TRUE
model was estimated with switch in mean. IfFALSE
model was estimated with constant mean.msvar: Boolean. If
TRUE
model was estimated with switch in variance. IfFALSE
model was estimated with constant variance.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.trace: List with Lists of estimation output for each initial value used due to
use_diff_init > 1
.
List with model characteristics
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..
Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.
See Also
Examples
set.seed(123)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n = 200,
p = 1,
q = 2,
mu = rbind(c(5, -2),
c(10, 2)),
sigma = list(rbind(c(5.0, 1.5),
c(1.5, 1.0)),
rbind(c(7.0, 3.0),
c(3.0, 2.0))),
phi = rbind(c(0.50, 0.30),
c(0.20, 0.70)),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)
# Set options for model estimation
control <- list(msmu = TRUE,
msvar = TRUE,
method = "EM",
use_diff_init = 1)
# Estimate model
y_msvar_mdl <- MSVARmdl(y_msvar_simu$y, p = 1, k = 2, control = control)
summary(y_msvar_mdl)
Estimation of Markov-switching VARX model by EM Algorithm
Description
Estimate Markov-switching VARX model by EM algorithm. This function is used by MSVARmdl
which organizes the output and takes raw data as input.
Usage
MSVARXmdl_em(theta_0, mdl, k, optim_options)
Arguments
theta_0 |
vector with initial values for parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
optim_options |
List with optimization options. |
Value
List with model results.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.
Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.
Markov-switching vector autoregressive model
Description
This function estimates a Markov-switching vector autoregressive model
Usage
MSVARmdl(Y, p, k, control = list())
Arguments
Y |
( |
p |
integer for the number of lags to use in estimation. Must be greater than or equal to |
k |
integer for the number of regimes to use in estimation. Must be greater than or equal to |
control |
List with optimization options including:
|
Value
List of class MSVARmdl
(S3
object) with model attributes including:
y: a
(T-p x q)
matrix of observations.X: a
(T-p x p*q + const)
matrix of lagged observations with a leading column of1
s.x: a
(T-p x p*q)
matrix of lagged observations.fitted: a
(T x q)
matrix of fitted values.resid: a
(T-p x q)
matrix of residuals.intercept: a
(k x q)
matrix of estimated intercepts of each process.mu: a
(k x q)
matrix of estimated means of each process.beta: a list containing
k
separate((1 + p) x q)
matrix of estimated coefficients for each regime.phi: estimates of autoregressive coefficients.
Fmat: Companion matrix containing autoregressive coefficients.
stdev: List with
k
(q x q)
matrices with estimated standard deviation on the diagonal.sigma: List with
k
(q x q)
matrices with estimated covariance matrix.theta: vector containing:
mu
andvech(sigma)
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance and covariances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise.theta_P_ind: vector indicating location of transition matrix elements with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations (same as
T
).p: number of autoregressive lags.
q: number of series.
k: number of regimes in estimated model.
P: a
(k x k)
transition matrix.pinf: a
(k x 1)
vector with limiting probabilities of each regime.St: a
(T x k)
vector with smoothed probabilities of each regime at each timet
.deltath: double with maximum absolute difference in vector
theta
between last iteration.iterations: number of EM iterations performed to achieve convergence (if less than
maxit
).theta_0: vector of initial values used.
init_used: number of different initial values used to get a finite solution. See description of input
maxit_converge
.msmu: Boolean. If
TRUE
model was estimated with switch in mean. IfFALSE
model was estimated with constant mean.msvar: Boolean. If
TRUE
model was estimated with switch in variance. IfFALSE
model was estimated with constant variance.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.trace: List with Lists of estimation output for each initial value used due to
use_diff_init > 1
.
List with model characteristics
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..
Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.
See Also
Examples
set.seed(123)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n = 200,
p = 1,
q = 2,
mu = rbind(c(5, -2),
c(10, 2)),
sigma = list(rbind(c(5.0, 1.5),
c(1.5, 1.0)),
rbind(c(7.0, 3.0),
c(3.0, 2.0))),
phi = rbind(c(0.50, 0.30),
c(0.20, 0.70)),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)
# Set options for model estimation
control <- list(msmu = TRUE,
msvar = TRUE,
method = "EM",
use_diff_init = 1)
# Estimate model
y_msvar_mdl <- MSVARmdl(y_msvar_simu$y, p = 1, k = 2, control = control)
summary(y_msvar_mdl)
Estimation of Markov-switching vector autoregressive model by EM Algorithm
Description
Estimate Markov-switching vector autoregressive model by EM algorithm. This function is used by MSVARmdl
which organizes the output and takes raw data as input.
Usage
MSVARmdl_em(theta_0, mdl, k, optim_options)
Arguments
theta_0 |
vector with initial values for parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
optim_options |
List with optimization options. |
Value
List with model results.
References
Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.
Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.
Markov-switching vector autoregressive maximum likelihood estimation
Description
This function computes estimate a Markov-switching vector autoregressive model using MLE.
Usage
MSVARmdl_mle(theta_0, mdl_in, k, optim_options)
Arguments
theta_0 |
vector containing initial values to use in optimization |
mdl_in |
List with model properties (can be obtained from estimating linear model i.e., using |
k |
integer determining the number of regimes |
optim_options |
List containing
|
Value
List with model attributes
Normal distribution model
Description
This function estimates a univariate or multivariate normally distributed model. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a HMM with k
regimes.
Usage
Nmdl(Y, Z = NULL, control = list())
Arguments
Y |
a |
Z |
an otpional |
control |
List with model options including:
|
Value
List of class Nmdl
(S3
object) with model attributes including:
y: a
(T x q)
matrix of observations.fitted: a
(T x q)
matrix of fitted values.resid: a
(T x q)
matrix of residuals.mu: a
(1 x q)
vector of estimated means of each process.intercept: a
(1 x q)
vector of estimated intercept of each process. If Z is NULL, it is the same as mu.beta: a
((1 + p + qz) x q)
matrix of estimated coefficients.betaZ: a
(qz x q)
matrix of estimated exogenous regressor coefficients (If Z is provided).stdev: a
(q x 1)
vector of estimated standard deviation of each process.sigma: a
(q x q)
estimated covariance matrix.theta: vector containing:
mu
,betaZ
(if matrix Z is provided), andvech(sigma)
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance and covariances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise.n: number of observations (same as
T
).q: number of series.
k: number of regimes. This is always
1
inNmdl
.control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.
Examples
set.seed(1234)
# ----- Univariate ----- #
# Define DGP
mdl_norm <- list(n = 1000,
q = 1,
mu = as.matrix(5),
sigma = as.matrix(5.0))
# Simulate process using simuNorm() function
y_norm_simu <- simuNorm(mdl_norm)
# estimate parameters
y_norm_mdl <- Nmdl(y_norm_simu$y)
summary(y_norm_mdl)
# ----- Multivariate ----- #
# Define DGP
mdl_norm <- list(n = 1000,
q = 2,
mu = c(5, -2),
sigma = rbind(c(5.0, 1.5),
c(1.5, 1.0)))
# Simulate process using simuNorm() function
y_norm_simu <- simuNorm(mdl_norm)
# estimate parameters
y_norm_mdl <- Nmdl(y_norm_simu$y)
summary(y_norm_mdl)
US GNP data 1947Q2 - 2024Q2
Description
US GNP data 1947Q2 - 2024Q2
Usage
USGNP
Format
This data is used in Rodriguez-Rondon & Dufour (2024). The series ranges from 1947Q2 to 2024Q2.
- Date
Vector of dates
- GNP
US GNP series
- GNP_gr
log difference of US GNP series
Source
https://fred.stlouisfed.org/graph/?g=UKDQ
References
U.S. Bureau of Economic Analysis, Gross National Product [GNP], retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/GNP, September, 2024.
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
US Real GDP data 1947Q2 - 2024Q2
Description
US Real GDP data 1947Q2 - 2024Q2
Usage
USRGDP
Format
This data is used in Rodriguez-Rondon & Dufour (2024). The series ranges from 1947Q2 to 2024Q2.
- Date
Vector of dates
- RGDP
US Real GDP series
- RGDP_gr
log difference of US Real GDP series
Source
https://fred.stlouisfed.org/series/GDPC1
References
U.S. Bureau of Economic Analysis, Real Gross Domestic Product [GDPC1], retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/GDPC1, September, 2024.
Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.
Vector X autoregressive model
Description
This function estimates a vector autoregresive model with p
lags. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a Markov switching vector autoregressive model with k
regimes.
Usage
VARXmdl(Y, p, Z, control = list())
Arguments
Y |
a |
p |
integer determining the number of autoregressive lags. |
Z |
a |
control |
List with model options including:
|
Value
List of class VARmdl
(S3
object) with model attributes including:
y: a
(T-p x q)
matrix of observations.X: a
(T-p x p*q + const)
matrix of lagged observations with a leading column of1
s ifconst=TRUE
or not ifconst=FALSE
.x: a
(T-p x p*q)
matrix of lagged observations.fitted: a
(T-p x q)
matrix of fitted values.resid: a
(T-p x q)
matrix of residuals.mu: a
(1 x q)
vector of estimated means of each process.beta: a
((1 + p + qz) x q)
matrix of estimated coefficients.betaZ: a
(qz x q)
matrix of estimated exogenous regressor coefficients.intercept: estimate of intercepts.
phi: a
(q x p*q)
matrix of estimated autoregressive coefficients.Fmat: Companion matrix containing autoregressive coefficients.
stdev: a
(q x 1)
vector of estimated standard deviation of each process.sigma: a
(q x q)
estimated covariance matrix.theta: vector containing:
mu
,vech(sigma)
, andvec(t(phi))
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance and covariances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise.theta_phi_ind: vector indicating location of autoregressive coefficients with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations after lag transformation (i.e.,
n = T-p
).p: number of autoregressive lags.
q: number of series.
k: number of regimes. This is always
1
inVARmdl
.Fmat: matrix from companion form. Used to determine is process is stationary.
control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.
See Also
Examples
# ----- Bivariate VAR(1) process ----- #
set.seed(1234)
# Define DGP of VAR process
mdl_var <- list(n = 1000,
p = 1,
q = 2,
mu = c(5,-2),
sigma = rbind(c(5.0, 1.5),
c(1.5, 1.0)),
phi = rbind(c(0.50, 0.30),
c(0.20, 0.70)))
# Simulate process using simuVAR() function
y_simu <- simuVAR(mdl_var)
# Set options for model estimation
control <- list(const = TRUE,
getSE = TRUE)
# Estimate model
y_var_mdl <- VARmdl(y_simu$y, p = 2, control = control)
summary(y_var_mdl)
Vector autoregressive model
Description
This function estimates a vector autoregresive model with p
lags. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a Markov switching vector autoregressive model with k
regimes.
Usage
VARmdl(Y, p, control = list())
Arguments
Y |
a |
p |
integer determining the number of autoregressive lags. |
control |
List with model options including:
|
Value
List of class VARmdl
(S3
object) with model attributes including:
y: a
(T-p x q)
matrix of observations.X: a
(T-p x p*q + const)
matrix of lagged observations with a leading column of1
s ifconst=TRUE
or not ifconst=FALSE
.x: a
(T-p x p*q)
matrix of lagged observations.fitted: a
(T-p x q)
matrix of fitted values.resid: a
(T-p x q)
matrix of residuals.mu: a
(1 x q)
vector of estimated means of each process.beta: a
((1 + p) x q)
matrix of estimated coefficients. .intercept: estimate of intercepts.
phi: a
(q x p*q)
matrix of estimated autoregressive coefficients.Fmat: Companion matrix containing autoregressive coefficients.
stdev: a
(q x 1)
vector of estimated standard deviation of each process.sigma: a
(q x q)
estimated covariance matrix.theta: vector containing:
mu
,vech(sigma)
, andvec(t(phi))
.theta_mu_ind: vector indicating location of mean with
1
and0
otherwise.theta_sig_ind: vector indicating location of variance and covariances with
1
and0
otherwise.theta_var_ind: vector indicating location of variances with
1
and0
otherwise.theta_phi_ind: vector indicating location of autoregressive coefficients with
1
and0
otherwise.stationary: Boolean indicating if process is stationary if
TRUE
or non-stationary ifFALSE
.n: number of observations after lag transformation (i.e.,
n = T-p
).p: number of autoregressive lags.
q: number of series.
k: number of regimes. This is always
1
inVARmdl
.Fmat: matrix from companion form. Used to determine is process is stationary.
control: List with model options used.
logLike: log-likelihood.
AIC: Akaike information criterion.
BIC: Bayesian (Schwarz) information criterion.
Hess: Hessian matrix. Approximated using
hessian
and only returned ifgetSE=TRUE
.info_mat: Information matrix. Computed as the inverse of
-Hess
. If matrix is not PD then nearest PD matrix is obtained usingnearest_spd
. Only returned ifgetSE=TRUE
.nearPD_used: Boolean determining whether
nearPD
function was used oninfo_mat
ifTRUE
or not ifFALSE
. Only returned ifgetSE=TRUE
.theta_se: standard errors of parameters in
theta
. Only returned ifgetSE=TRUE
.
See Also
Examples
# ----- Bivariate VAR(1) process ----- #
set.seed(1234)
# Define DGP of VAR process
mdl_var <- list(n = 1000,
p = 1,
q = 2,
mu = c(5,-2),
sigma = rbind(c(5.0, 1.5),
c(1.5, 1.0)),
phi = rbind(c(0.50, 0.30),
c(0.20, 0.70)))
# Simulate process using simuVAR() function
y_simu <- simuVAR(mdl_var)
# Set options for model estimation
control <- list(const = TRUE,
getSE = TRUE)
# Estimate model
y_var_mdl <- VARmdl(y_simu$y, p = 2, control = control)
summary(y_var_mdl)
Approximate CDF distribution
Description
This function obtains the parameters in eq. 16 of the CDF distribution needed for combining moment-based test statistics.
Usage
approxDistDL(Tsize, simdist_N)
Arguments
Tsize |
Sample size. |
simdist_N |
Number of simulations to approximate CDF distribution. |
Value
A (2 x 4
) matrix with parameters of CDF distributions. The first row contains \gamma_0
for each moment and the second row contains \gamma_1
for each moment.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Loop for approxDistDL
Description
This function performs the loop in required in approxDistDL
.
Usage
approx_dist_loop(SN2)
Arguments
SN2 |
A ( |
Value
The test statistics from simulated data. Used for NLS to get params
needed to combine p-values.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Autoregressive transition matrix
Description
This function converts a transition matrix to the transition matrix consistent with a Markov-switching autoregressive model.
Usage
arP(P, k, ar)
Arguments
P |
original transition matrix. |
k |
integer determining the number of regimes. |
ar |
number of autoregressive lags. |
Value
transformed transition matrix.
Autoregressive moment grid
Description
This function creates a grid of mean and variance consistent with a Markov-switching autoregressive model.
Usage
argrid_MSARmdl(mu, sig, k, ar, msmu, msvar)
Arguments
mu |
vector ( |
sig |
vector ( |
k |
integer determining the number of regimes. |
ar |
number of autoregressive lags. |
msmu |
Boolean indicator. If |
msvar |
Boolean indicator. If |
Value
List with (M x ar+1
) matrix of means for each regime M
(where M = k^(ar+1)
) and each time t,... t-ar
, vector with variance for each regime M
, and vector indicating the corresponded 1,..., k
regime.
Vector autoregressive moment grid
Description
Creates grid of means and covariance matrices consistent with a Markov-switching vector autoregressive model.
Usage
argrid_MSVARmdl(mu, sigma, k, ar, msmu, msvar)
Arguments
mu |
a ( |
sigma |
list with |
k |
integer determining the number of regimes. |
ar |
number of autoregressive lags. |
msmu |
Boolean indicator. If |
msvar |
Boolean indicator. If |
Value
List with M regime specific (q x k
) matrices of means, List with M
regime specific covariance matrices, and vector indicating the corresponded 1,..., k
regime.
Markov-switching autoregressive model residuals
Description
This function computes residuals of a Markov-switching autoregressive model.
Usage
calcResid_MSARXmdl(mdl, mu, k)
Arguments
mdl |
List containing relevant parameters. |
mu |
Vector with mean in each regime. |
k |
number of regimes. Must be greater than or equal to |
Value
A (TxM
) matrix of residuals in each regime M
where M=k^(ar+1)
.
Markov-switching autoregressive model residuals
Description
This function computes residuals of a Markov-switching autoregressive model.
Usage
calcResid_MSARmdl(mdl, mu, k)
Arguments
mdl |
List containing relevant parameters. |
mu |
Vector with mean in each regime. |
k |
number of regimes. Must be greater than or equal to |
Value
A (TxM
) matrix of residuals in each regime M
where M=k^(ar+1)
.
Markov-switching VARX model residuals
Description
This function computes residuals of a Markov-switching VARX model.
Usage
calcResid_MSVARXmdl(mdl, mu, k)
Arguments
mdl |
List containing relevant parameters. |
mu |
Vector with mean in each regime. |
k |
Number of regimes. Must be greater than or equal to |
Value
List with M
(Txq
) matrices of residuals in each regime M
where M=k^(ar+1)
.
Markov-switching vector autoregressive model residuals
Description
This function computes residuals of a Markov-switching vector autoregressive model.
Usage
calcResid_MSVARmdl(mdl, mu, k)
Arguments
mdl |
List containing relevant parameters. |
mu |
Vector with mean in each regime. |
k |
Number of regimes. Must be greater than or equal to |
Value
List with M
(Txq
) matrices of residuals in each regime M
where M=k^(ar+1)
.
Moment-based test statistics
Description
This function computes the four moment-based test statistics (eq. 11
- 14
) discussed in Dufour & Luger 2017.
Usage
calc_DLmoments(ehat)
Arguments
ehat |
A ( |
Value
Vector containing the four test statistics.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Test statistic for switch in mean only
Description
This function computes part of the test statistic given by
eq. 2.5 of CHP 2014 when the alternative has switching mean only. The output
is used in chpStat
which computes the full test statistics.
Usage
calc_mu2t(mdl, rho, ltmt)
Arguments
mdl |
List containing model attributes (see |
rho |
Number determining value of |
ltmt |
List containing derivatives output from |
Value
Part of test statistic given rho
and hv
value.
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Test statistic for switch in mean and variance
Description
This function computes part of the test statistic given by
eq. 2.5 of CHP 2014 when the alternative has switching mean and variance.
The output is used in chpStat
which computes the full test
statistics.
Usage
calc_mu2t_mv(mdl, rho, ltmt, hv)
Arguments
mdl |
List containing model attributes (see |
rho |
Number determining value of |
ltmt |
List containing derivatives output from |
hv |
Number determining value of |
Value
Part of test statistic given rho
and hv
value.
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Carrasco, Hu, & Ploberger 2010 GNP data
Description
Carrasco, Hu, & Ploberger 2010 GNP data
Usage
chp10GNP
Format
This data is the extension of the GNP series used in CHP (2014), Econometrica. This series ranges from 1951Q2 to 2010Q4.
- Date
Vector of dates
- GNP
US GNP series
- GNP_gr
log difference of US GNP series
Source
https://www.econometricsociety.org/content/supplement-optimal-test-markov-switching-parameters
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Derivative matrix
Description
This function organizes the first and second derivatives of the log-likelihood.
Usage
chpDmat(mdl, msvar)
Arguments
mdl |
List containing output from |
msvar |
Boolean indicator. If |
Value
List containing relevant first and second derivatives of log-likelihood function.
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Test statistic for CHP 2014 parameter stability test
Description
This function computes the supTS and expTS test-statistics proposed in CHP 2014.
Usage
chpStat(mdl, rho_b, ltmt, msvar)
Arguments
mdl |
List containing model attributes (see |
rho_b |
Number determining bounds for distribution of |
ltmt |
List containing derivatives output from |
msvar |
Boolean indicator. If |
Value
A (2 x 1
) vector with supTS test statistic as first element and expTS test-statistics as second element.
References
Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.
Parameter vector & likelihood function used by HLRTest()
Description
This function combines parameters of restricted model
with parameters of unrestricted model and then computes the likelihood using
marklike()
.
Usage
clike(b, HLR_opt_ls)
Arguments
b |
vector of parameters from restricted model. |
HLR_opt_ls |
List with model properties and test controls defined in |
Value
Value of likelihood at each period t
.
coef of a ARmdl
object
Description
This is a method for the function coef()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
coef(object, ...)
Arguments
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Value
vector of coefficients.
coef of a HMmdl
object
Description
This is a method for the function coef()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
coef(object, ...)
Arguments
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Value
vector of coefficients.
coef of a MSARmdl
object
Description
This is a method for the function coef()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
coef(object, ...)
Arguments
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Value
vector of coefficients.
coef of a MSVARmdl
object
Description
This is a method for the function coef()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
coef(object, ...)
Arguments
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Value
vector of coefficients.
coef of a Nmdl
object
Description
This is a method for the function coef()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
coef(object, ...)
Arguments
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Value
vector of coefficients.
coef of a VARmdl
object
Description
This is a method for the function coef()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
coef(object, ...)
Arguments
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Value
vector of coefficients.
Combine p-values
Description
This function is used to combine the four moment-based p-values as in eq. 17
and 18
of Dufour & Luger 2017.
Usage
combine_stat(stats, params, type)
Arguments
stats |
A ( |
params |
A ( |
type |
String determining the type of method used to combine p-values. If set to "min" the min method of combining p-values is used as in Fisher 1932 and Pearson 1933. If set to "prod" the product of p-values is used as in Tippett 1931 and Wilkinson 1951. |
Value
A (N x 1
) vector with test statistics. The last element is the test statistic from observed data.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Tippett, L. 1931. "The Method of Statistics". London: Williams & Norgate.
Wilkinson, B. 1951. "A statistical consideration in psychological research." Psychology Bulletin 48:156–158.
Pearson, K. 1933. "On a method of determining whether a sample of size n supposed to have been drawn from a parent population having a known probability integral has probably been drawn at random". Biometrika 25:379–410.
Fisher, R. 1932. "Statistical Methods for Research Workers." Edinburgh: Oliver and Boyd.
Companion Matrix
Description
This function converts the (q x 1
) vector of constants and (q x qp
) matrix of autoregressive coefficients into (qp x qp
) matrix belonging to the companion form
Usage
companionMat(phi, p, q)
Arguments
phi |
matrix of dimension ( |
p |
integer for number of autoregressive lags. |
q |
integer for number of series. |
Value
matrix of dimension (qp x qp
) of companion form.
Computes test stat using new parameter vectors
Description
This function computes the LRT statistic.
Usage
compu_tstat(theta_h0, mdl_h0, LT_h1, p, q, k0, exog)
Arguments
theta_h0 |
estimated parameter values for restricted model. |
mdl_h0 |
List with restricted model properties. |
LT_h1 |
Double specifying maximum log likelihood under alternative. |
p |
integer specifying the number of autoregressive lags. |
q |
integer specifying the number of series. |
k0 |
integer specifying the number of regimes under the null hypothesis. |
Value
LRT statistic
Covariance to correlation matrix
Description
This function takes an (n x n
) covariance matrix and returns the associated (n x n
) correlation matrix.
Usage
cov2corr(cov_mat)
Arguments
cov_mat |
A ( |
Value
A (n x n
) correlation matrix.
Covariance vech to matrix
Description
This function undoes the half-vectorization of a covariance matrix.
Usage
covar_unvech(sig, n)
Arguments
sig |
A (n+1)*n/2 vector. |
n |
Integer determining shape of the original matrix. |
Value
A (n x n
) covariance matrix.
Covariance vech function
Description
This function returns the half-vectorization of an input matrix as a column vector.
Usage
covar_vech(mat)
Arguments
mat |
A ( |
Value
A (n+1)*n/2
column vector.
Gradient of likelihood function.
Description
this function computes the score vector.
Usage
dmclike(th, HLR_opt_ls)
Arguments
th |
vector of parameter values. |
HLR_opt_ls |
List with model properties and test controls defined in |
Value
vector with gradient of likelihood function for each parameter. Used in HLRpramSearch()
.
Estimate model for likelihood ratio test
Description
This function is used by the Monte Carlo testing procedures to estimate restricted and unrestricted models.
Usage
estimMdl(Y, p, q, k, Z = NULL, control = list())
Arguments
Y |
Series to be tested. Must be a ( |
p |
integer specifying the number of autoregressive lags. |
q |
integer specifying the number of series. |
k |
integer specifying the number of regimes. |
Z |
exogeneous regressors. Defualt is NULL. |
control |
List with control options for model estimation. For default values, see description of model being estimated. |
Value
List with estimated model properties.
fitted values of a ARmdl
object
Description
This is a method for the function fitted()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
fitted(object, ...)
Arguments
object |
an object for which the extraction of model fitted values is meaningful. |
... |
other arguments. |
Value
matrix with fitted values
fitted values of a HMmdl
object
Description
This is a method for the function fitted()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
fitted(object, ...)
Arguments
object |
an object for which the extraction of model fitted values is meaningful. |
... |
other arguments. |
Value
matrix with fitted values
fitted values of a MSARmdl
object
Description
This is a method for the function fitted()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
fitted(object, ...)
Arguments
object |
an object for which the extraction of model fitted values is meaningful. |
... |
other arguments. |
Value
matrix with fitted values
fitted values of a MSVARmdl
object
Description
This is a method for the function fitted()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
fitted(object, ...)
Arguments
object |
an object for which the extraction of model fitted values is meaningful. |
... |
other arguments. |
Value
matrix with fitted values
fitted values of a Nmdl
object
Description
This is a method for the function fitted()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
fitted(object, ...)
Arguments
object |
an object for which the extraction of model fitted values is meaningful. |
... |
other arguments. |
Value
matrix with fitted values
fitted values of a VARmdl
object
Description
This is a method for the function fitted()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
fitted(object, ...)
Arguments
object |
an object for which the extraction of model fitted values is meaningful. |
... |
other arguments. |
Value
matrix with fitted values
Hessian matrix
Description
This function is used to obtain a numerical approximation of a Hessian matrix.
Usage
getHessian(mdl)
Arguments
mdl |
List with model properties. |
Value
Hessian matrix.
Hessian matrix of autoregressive model
Description
This function is used to obtain a numerical approximation of a Hessian matrix for an autoregressive model.
Usage
## S3 method for class 'ARmdl'
getHessian(mdl)
Arguments
mdl |
List with model properties. |
Value
Hessian matrix.
Hessian matrix of Hidden Markov model
Description
This function is used to obtain a numerical approximation of a Hessian matrix for a Hidden Markov model.
Usage
## S3 method for class 'HMmdl'
getHessian(mdl)
Arguments
mdl |
List with model properties. |
Value
Hessian matrix.
Hessian matrix of Markov-switching autoregressive model
Description
This function is used to obtain a numerical approximation of a Hessian matrix for a Markov-switching autoregressive model.
Usage
## S3 method for class 'MSARmdl'
getHessian(mdl)
Arguments
mdl |
List with model properties. |
Value
Hessian matrix.
Hessian matrix of Markov-switching vector autoregressive model
Description
This function is used to obtain a numerical approximation of a Hessian matrix for a Markov-switching vector autoregressive model.
Usage
## S3 method for class 'MSVARmdl'
getHessian(mdl)
Arguments
mdl |
List with model properties. |
Value
Hessian matrix.
Hessian matrix of normal model
Description
This function is used to obtain a numerical approximation of a Hessian matrix for a normally distributed model.
Usage
## S3 method for class 'Nmdl'
getHessian(mdl)
Arguments
mdl |
List with model properties. |
Value
Hessian matrix.
Hessian matrix of vector autoregressive model
Description
This function is used to obtain a numerical approximation of a Hessian matrix for a vector autoregressive model.
Usage
## S3 method for class 'VARmdl'
getHessian(mdl)
Arguments
mdl |
List with model properties. |
Value
Hessian matrix.
Hamilton 1984 & Hansen 1992 GNP data
Description
Hamilton 1984 & Hansen 1992 GNP data
Usage
hamilton84GNP
Format
This data set is used in Hansen (1992) to test the US GNP model proposed by Hamilton (1989). This series ranges from 1951Q2 to 1984Q4.
- Date
Vector of dates
- GNP
US GNP series
- GNP_gr
US GNP log difference
Source
https://www.ssc.wisc.edu/~bhansen/progs/jae_92.html
References
Hansen, Bruce E. 1992. “The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.
Hamilton, James D. 1989. “A new approach to the economic analysis of nonstationary time series and the business cycle.” Econometrica 57 (2): 357–384.
Initial values for Hidden Markov model
Description
This function generates a random parameter vector to be used as initial values for a Hidden Markov model.
Usage
initVals_HMmdl(mdl, k)
Arguments
mdl |
List with parameter values of simple (one-regime) model. This includes:
|
k |
Number of regimes. |
Value
Vector of initial parameter values.
Initial values for Markov-switching ARX model
Description
This function generates a random parameter vector to be used as initial values for a Markov-switching ARX model.
Usage
initVals_MSARXmdl(mdl, k)
Arguments
mdl |
List with parameter values of simple (one-regime) autoregressive model. This includes:
|
k |
Number of regimes. |
Value
Vector of initial parameter values.
Initial values for Markov-switching autoregressive model
Description
This function generates a random parameter vector to be used as initial values for a Markov-switching autoregressive model.
Usage
initVals_MSARmdl(mdl, k)
Arguments
mdl |
List with parameter values of simple (one-regime) autoregressive model. This includes:
|
k |
Number of regimes. |
Value
Vector of initial parameter values.
Initial values for Markov-switching VARX model
Description
This function generates a random parameter vector to be used as initial values for a Markov-switching VARX model.
Usage
initVals_MSVARXmdl(mdl, k)
Arguments
mdl |
List with parameter values of simple (one-regime) VARX model. This includes:
|
k |
Number of regimes. |
Value
Vector of initial parameter values.
Initial values for Markov-switching vector autoregressive model
Description
This function generates a random parameter vector to be used as initial values for a Markov-switching vector autoregressive model.
Usage
initVals_MSVARmdl(mdl, k)
Arguments
mdl |
List with parameter values of simple (one-regime) vector autoregressive model. This includes:
|
k |
Number of regimes. |
Value
Vector of initial parameter values.
Intercept from mu for MSARmdl
Description
This function computes the intercept for each regime k for an Markov switching AR model
Usage
interMSARmdl(mdl)
Arguments
mdl |
List with model properties |
Value
a (k x 1)
vector of intercepts
Intercept from mu for MSVARmdl
Description
This function computes the intercept for each regime k for an Markov switching VAR model
Usage
interMSVARmdl(mdl)
Arguments
mdl |
List with model properties |
Value
a (k x q)
vector of intercepts
Ergodic (limiting) probabilities of states
Description
Takes a transition matrix and returns the limiting probabilities.
Usage
limP(P)
Arguments
P |
Matrix with transition probabilities. |
Value
A (k x 1
) vector of limiting probabilities.
Log likelihood for autoregressive model
Description
This function is used to compute the log-likelihood for an autoregressive model.
Usage
## S3 method for class 'ARmdl'
logLik(object, ...)
Arguments
object |
any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted. |
... |
some methods for this generic function require additional arguments. |
Value
Log-likelihood value.
Log likelihood for Hidden Markov model
Description
This function is used to compute the log-likelihood for a Hidden Markov model.
Usage
## S3 method for class 'HMmdl'
logLik(object, ...)
Arguments
object |
any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted. |
... |
some methods for this generic function require additional arguments. |
Value
Log-likelihood value.
Log likelihood for Markov-switching autoregressive model
Description
This function is used to compute the log-likelihood for a Markov-switching autoregressive model.
Usage
## S3 method for class 'MSARmdl'
logLik(object, ...)
Arguments
object |
any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted. |
... |
some methods for this generic function require additional arguments. |
Value
Log-likelihood value.
Log likelihood for Markov-switching vector autoregressive model
Description
This function is used to compute the log-likelihood for a Markov-switching vector autoregressive model.
Usage
## S3 method for class 'MSVARmdl'
logLik(object, ...)
Arguments
object |
any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted. |
... |
some methods for this generic function require additional arguments. |
Value
Log-likelihood value.
Log likelihood for Normal model
Description
This function is used to compute the log-likelihood for a normally distributed model.
Usage
## S3 method for class 'Nmdl'
logLik(object, ...)
Arguments
object |
any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted. |
... |
some methods for this generic function require additional arguments. |
Value
Log-likelihood value.
Log likelihood for vector autoregressive model
Description
This function is used to compute the log-likelihood for a vector autoregressive model.
Usage
## S3 method for class 'VARmdl'
logLik(object, ...)
Arguments
object |
any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted. |
... |
some methods for this generic function require additional arguments. |
Value
Log-likelihood value.
ARX log-likelihood objective function
Description
This function computes the log-likelihood for an autoregressive model with exogenous regressors.
Usage
logLike_ARXmdl(theta, mdl)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
Value
Log-likelihood value.
Autoregressive log-likelihood objective function
Description
This function computes the log-likelihood for an autoregressive model.
Usage
logLike_ARmdl(theta, mdl)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
Value
Log-likelihood value.
Hidden Markov model log-likelihood function
Description
This function computes the log-likelihood for a markov-switching autoregressive model.
Usage
logLike_HMmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
Log-likelihood value.
Hidden Markov model log-likelihood function (minimization version)
Description
This function computes the (negative) log-likelihood for a markov-switching autoregressive model.
Usage
logLike_HMmdl_min(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
integer determining the number of regimes. |
Value
Negative log-likelihood value.
Markov-switching ARX log-likelihood objective function
Description
This function computes the log-likelihood for a markov-switching ARX model.
Usage
logLike_MSARXmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
Log-likelihood value.
Markov-switching ARX log-likelihood objective function (minimization version)
Description
This function computes the (negative) log-likelihood for a markov-switching ARX model.
Usage
logLike_MSARXmdl_min(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
integer determining the number of regimes. |
Value
Negative log-likelihood value.
Markov-switching autoregressive log-likelihood objective function
Description
This function computes the log-likelihood for a markov-switching autoregressive model.
Usage
logLike_MSARmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
Log-likelihood value.
Markov-switching autoregressive log-likelihood objective function (minimization version)
Description
This function computes the (negative) log-likelihood for a markov-switching autoregressive model.
Usage
logLike_MSARmdl_min(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
integer determining the number of regimes. |
Value
Negative log-likelihood value.
Markov-switching VARX log-likelihood objective function
Description
This function computes the log-likelihood for a markov-switching VARX model.
Usage
logLike_MSVARXmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
Log-likelihood value.
Markov-switching VARX log-likelihood objective function (minimization version)
Description
This function computes the (negative) log-likelihood for a markov-switching VARX model
Usage
logLike_MSVARXmdl_min(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
Negative log-likelihood value.
Markov-switching vector autoregressive log-likelihood objective function
Description
This function computes the log-likelihood for a markov-switching vector autoregressive model.
Usage
logLike_MSVARmdl(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
Log-likelihood value.
Markov-switching vector autoregressive log-likelihood objective function (minimization version)
Description
This function computes the (negative) log-likelihood for a markov-switching vector autoregressive model
Usage
logLike_MSVARmdl_min(theta, mdl, k)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
k |
Integer determining the number of regimes. |
Value
Negative log-likelihood value.
Normal log-likelihood objective function
Description
This function computes the log-likelihood for a normally distributed model.
Usage
logLike_Nmdl(theta, mdl)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
Value
Log-likelihood value.
VARX log-likelihood objective function
Description
This function computes the log-likelihood for a VARX model.
Usage
logLike_VARXmdl(theta, mdl)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
Value
Log-likelihood value.
Vector autoregressive log-likelihood objective function
Description
This function computes the log-likelihood for a vector autoregressive model.
Usage
logLike_VARmdl(theta, mdl)
Arguments
theta |
Vector of model parameters. |
mdl |
List with model attributes. |
Value
Log-likelihood value.
Likelihood function used by HLRTest()
Description
this function computes the sum Markov likelihood
Usage
marklike(ths, HLR_opt_ls)
Arguments
ths |
vector of parameter values. |
HLR_opt_ls |
List with model properties and test controls defined in |
Value
Vector of likelihood values.
Sum of likelihood used by HLRTest()
Description
This function computes the sum of the likelihood.
Usage
mclike(th, HLR_opt_ls)
Arguments
th |
vector of parameter values. |
HLR_opt_ls |
List with model properties and test controls defined in |
Value
Sum of likelihood.
Change model List with new parameters
Description
This function is used by the MMC LRT procedure. It makes a copy of the restricted model under the null hypothesis and changes the parameters used to simulate the process under the null with values being considered in the search/optimization.
Usage
mdledit(mdl_h0, theta_h0, p, q, k0, exog)
Arguments
mdl_h0 |
List with restricted model properties. |
theta_h0 |
vector of parameter values under null being considered. |
p |
integer specifying the number of autoregressive lags. |
q |
integer specifying the number of series. |
k0 |
integer specifying the number of regimes. |
Value
List with model properties
Nobs of a ARmdl
object
Description
This is a method for the function nobs()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
nobs(object, ...)
Arguments
object |
a fitted model object. |
... |
further arguments to be passed to methods. |
Value
Number of time series observations.
Nobs of a HMmdl
object
Description
This is a method for the function nobs()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
nobs(object, ...)
Arguments
object |
a fitted model object. |
... |
further arguments to be passed to methods. |
Value
Number of time series observations.
Nobs of a MSARmdl
object
Description
This is a method for the function nobs()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
nobs(object, ...)
Arguments
object |
a fitted model object. |
... |
further arguments to be passed to methods. |
Value
Number of time series observations.
Nobs of a MSVARmdl
object
Description
This is a method for the function nobs()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
nobs(object, ...)
Arguments
object |
a fitted model object. |
... |
further arguments to be passed to methods. |
Value
Number of time series observations.
Nobs of a Nmdl
object
Description
This is a method for the function nobs()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
nobs(object, ...)
Arguments
object |
a fitted model object. |
... |
further arguments to be passed to methods. |
Value
Number of time series observations.
Nobs of a VARmdl
object
Description
This is a method for the function nobs()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
nobs(object, ...)
Arguments
object |
a fitted model object. |
... |
further arguments to be passed to methods. |
Value
Number of time series observations.
Parameter list for Markov-switching ARX model
Description
This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for univariate Markov-switching functions.
Usage
paramList_MSARXmdl(theta, p, k, qz, msmu, msvar)
Arguments
theta |
Vector of parameters. |
p |
Number of autoregressive lags. |
k |
Number of regimes. |
qz |
Number of exogenous variables. |
msmu |
Boolean indicating if the mean switches with regime. |
msvar |
Boolean indicating if the variance switches with regime. |
Value
List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.
Parameter list for Markov-switching autoregressive model
Description
This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for univariate Markov-switching functions.
Usage
paramList_MSARmdl(theta, p, k, msmu, msvar)
Arguments
theta |
Vector of parameters. |
p |
Number of autoregressive lags. |
k |
Number of regimes. |
msmu |
Boolean indicating if the mean switches with regime. |
msvar |
Boolean indicating if the variance switches with regime. |
Value
List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.
Parameter list for Markov-switching VARX model
Description
This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for multivariate Markov-switching functions.
Usage
paramList_MSVARXmdl(theta, q, p, k, qz, msmu, msvar)
Arguments
theta |
Vector of parameters. |
q |
Number of time series. |
p |
Number of autoregressive lags. |
k |
Number of regimes. |
qz |
Number of exogenous variables. |
msmu |
Boolean indicating if the mean switches with regime. |
msvar |
Boolean indicating if the variance switches with regime. |
Value
List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.
Parameter list for Markov-switching vector autoregressive model
Description
This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for multivariate Markov-switching functions.
Usage
paramList_MSVARmdl(theta, q, p, k, msmu, msvar)
Arguments
theta |
Vector of parameters. |
q |
Number of time series. |
p |
Number of autoregressive lags. |
k |
Number of regimes. |
msmu |
Boolean indicating if the mean switches with regime. |
msvar |
Boolean indicating if the variance switches with regime. |
Value
List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.
Plot of a ARmdl
object
Description
This is a method for the function plot()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The ARmdl
object is returned invisibly.
Plot of a HMmdl
object
Description
This is a method for the function plot()
for objects of the class HMmdl
.
Usage
## S3 method for class 'Hmmdl'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The Hmmdl
object is returned invisibly.
Plot of a MSARmdl
object
Description
This is a method for the function plot()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The MSARmdl
object is returned invisibly.
Plot of a MSVARmdl
object
Description
This is a method for the function plot()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The MSVARmdl
object is returned invisibly.
Plot of a Nmdl
object
Description
This is a method for the function plot()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The Nmdl
object is returned invisibly.
Plot of a VARmdl
object
Description
This is a method for the function plot()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The VARmdl
object is returned invisibly.
Plot of a simuAR
object
Description
This is a method for the function plot()
for objects of the class simuAR
.
Usage
## S3 method for class 'simuAR'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuAR
object is returned invisibly.
Plot of a simuARX
object
Description
This is a method for the function plot()
for objects of the class simuAR
.
Usage
## S3 method for class 'simuARX'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuARX
object is returned invisibly.
Plot of a simuHMM
object
Description
This is a method for the function plot()
for objects of the class simuHMM
.
Usage
## S3 method for class 'simuHMM'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuHMM
object is returned invisibly.
Plot of a simuMSAR
object
Description
This is a method for the function plot()
for objects of the class simuMSAR
.
Usage
## S3 method for class 'simuMSAR'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuMSAR
object is returned invisibly.
Plot of a simuMSARX
object
Description
This is a method for the function plot()
for objects of the class simuMSAR
.
Usage
## S3 method for class 'simuMSARX'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuMSARX
object is returned invisibly.
Plot of a simuMSVAR
object
Description
This is a method for the function plot()
for objects of the class simuMSVAR
.
Usage
## S3 method for class 'simuMSVAR'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuMSVAR
object is returned invisibly.
Plot of a simuMSVARX
object
Description
This is a method for the function plot()
for objects of the class simuMSVAR
.
Usage
## S3 method for class 'simuMSVARX'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuMSVARX
object is returned invisibly.
Plot of a simuNorm
object
Description
This is a method for the function plot()
for objects of the class simuNorm
.
Usage
## S3 method for class 'simuNorm'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuNorm
object is returned invisibly.
Plot of a simuVAR
object
Description
This is a method for the function plot()
for objects of the class simuVAR
.
Usage
## S3 method for class 'simuVAR'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuVAR
object is returned invisibly.
Plot of a simuVARX
object
Description
This is a method for the function plot()
for objects of the class simuVAR
.
Usage
## S3 method for class 'simuVARX'
plot(x, ...)
Arguments
x |
the coordinates of points in the plot. Alternatively, a
single plotting structure, function or any R object with a
|
... |
arguments to be passed to methods, such as
graphical parameters (see
|
Value
The simuVARX
object is returned invisibly.
Predict for a ARmdl
object
Description
This is a method for the function predict()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
predict(object, ..., h = 10)
Arguments
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
h |
max number of prediction periods |
Value
a (h x q)
matrix with predicted value values.
Predict for a HMmdl
object
Description
This is a method for the function predict()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
predict(object, ..., h = 10)
Arguments
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
h |
max number of prediction periods |
Value
a (h x q)
matrix with predicted value values.
Predict for a MSARmdl
object
Description
This is a method for the function predict()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
predict(object, ..., h = 10)
Arguments
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
h |
max number of prediction periods |
Value
a (h x q)
matrix with predicted value values.
Predict for a MSVARmdl
object
Description
This is a method for the function predict()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
predict(object, ..., h = 10)
Arguments
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
h |
max number of prediction periods |
Value
a (h x q)
matrix with predicted value values.
Predict for a Nmdl
object
Description
This is a method for the function predict()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
predict(object, ..., h = 10)
Arguments
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
h |
max number of prediction periods |
Value
a (h x q)
matrix with predicted value values.
Predict for a VARmdl
object
Description
This is a method for the function predict()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
predict(object, ..., h = 10)
Arguments
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
h |
max number of prediction periods |
Value
a (h x q)
matrix with predicted value values.
Print summary of an ARmdl
object
Description
This is a method for the function print()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The ARmdl
object is returned invisibly.
Print summary of a BootLRTest
object
Description
This is a method for the function print()
for objects of the class BootLRTest
.
Usage
## S3 method for class 'BootLRTest'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The BootLRTest
object is returned invisibly.
Print summary of a CHPTest
object
Description
This is a method for the function print()
for objects of the class CHPTest
.
Usage
## S3 method for class 'CHPTest'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The CHPTest
object is returned invisibly.
Print summary of a DLMCTest
object
Description
This is a method for the function print()
for objects of the class DLMCTest
.
Usage
## S3 method for class 'DLMCTest'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The DLMCTest
object is returned invisibly.
Print summary of a DLMMCTest
object
Description
This is a method for the function print()
for objects of the class DLMMCTest
.
Usage
## S3 method for class 'DLMMCTest'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The DLMMCTest
object is returned invisibly.
Print summary of a CHPTest
object
Description
This is a method for the function print()
for objects of the class CHPTest
.
Usage
## S3 method for class 'HLRTest'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The CHPTest
object is returned invisibly.
Print summary of a HMmdl
object
Description
This is a method for the function print()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The HMmdl
object is returned invisibly.
Print summary of a LMCLRTest
object
Description
This is a method for the function print()
for objects of the class LMCLRTest
.
Usage
## S3 method for class 'LMCLRTest'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The LMCLRTest
object is returned invisibly.
Print summary of a MMCLRTest
object
Description
This is a method for the function print()
for objects of the class MMCLRTest
.
Usage
## S3 method for class 'MMCLRTest'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The MMCLRTest
object is returned invisibly.
Print summary of a MSARmdl
object
Description
This is a method for the function print()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The MSARmdl
object is returned invisibly.
Print summary of a MSVARmdl
object
Description
This is a method for the function print()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The MSVARmdl
object is returned invisibly.
Print summary of a Nmdl
object
Description
This is a method for the function print()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The Nmdl
object is returned invisibly.
Print summary of an VARmdl
object
Description
This is a method for the function print()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
print(x, digits = getOption("digits"), ...)
Arguments
x |
an object used to select a method. |
digits |
minimal number of significant digits, see
|
... |
further arguments passed to or from other methods. |
Value
The VARmdl
object is returned invisibly.
Random Transition Matrix
Description
This function creates a random transition matrix.
Usage
randP(k)
Arguments
k |
Number of regimes. Must be greater than or equal to |
Value
Transition matrix with randomly generated entries.
Standard normal errors using box Muller
Description
This function generates uncorrelated standard normal processes using box Muller method.
Usage
randSN(n, q)
Arguments
n |
Integer determining the length of the process to be simulated |
q |
Integer determining the number of processes to be simulated |
Value
A (T x q
) matrix of standard normal distributed errors
residuals of a ARmdl
object
Description
This is a method for the function residuals()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
residuals(object, ...)
Arguments
object |
an object for which the extraction of model residuals is meaningful. |
... |
other arguments. |
Value
vector of residuals.
residuals of a HMmdl
object
Description
This is a method for the function residuals()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
residuals(object, ...)
Arguments
object |
an object for which the extraction of model residuals is meaningful. |
... |
other arguments. |
Value
vector of residuals.
residuals of a MSARmdl
object
Description
This is a method for the function residuals()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
residuals(object, ...)
Arguments
object |
an object for which the extraction of model residuals is meaningful. |
... |
other arguments. |
Value
vector of residuals.
residuals of a MSVARmdl
object
Description
This is a method for the function residuals()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
residuals(object, ...)
Arguments
object |
an object for which the extraction of model residuals is meaningful. |
... |
other arguments. |
Value
vector of residuals.
residuals of a Nmdl
object
Description
This is a method for the function residuals()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
residuals(object, ...)
Arguments
object |
an object for which the extraction of model residuals is meaningful. |
... |
other arguments. |
Value
vector of residuals.
residuals of a VARmdl
object
Description
This is a method for the function residuals()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
residuals(object, ...)
Arguments
object |
an object for which the extraction of model residuals is meaningful. |
... |
other arguments. |
Value
vector of residuals.
Simulated moment-based test statistics
Description
This function computes the four moment-based test statistics (eq. 11
- 14
) discussed in Dufour & Luger 2017 for N
different simulated series.
Usage
sim_DLmoments(Tsize, N)
Arguments
Tsize |
Length of sample size for simulation. |
N |
Number of simulated samples. |
Value
A (N x 4
) matrix with N
different simulated moment-based test statistics.
References
Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.
Simulate autoregressive process
Description
This function simulates an autoregresive process.
Usage
simuAR(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated autoregressive series and its DGP parameters.
Examples
set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n = 500,
mu = 5,
sigma = 2,
phi = c(0.5,0.2))
# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)
plot(y_simu)
Simulate autoregressive X process
Description
This function simulates an autoregresive X process.
Usage
simuARX(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated autoregressive series and its DGP parameters.
Examples
set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n = 500,
mu = 5,
sigma = 2,
phi = c(0.5,0.2))
# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)
plot(y_simu)
Simulate autoregressive process with exogenous regressors
Description
This function simulates an ARX process.
Usage
simuARX_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated autoregressive series and its DGP parameters.
Simulate autoregressive process
Description
This function simulates an autoregresive process.
Usage
simuAR_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated autoregressive series and its DGP parameters.
Simulate Hidden Markov model with normally distributed errors
Description
This function simulates a Hidden Markov Model process.
Usage
simuHMM(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated series and its DGP parameters.
Examples
set.seed(1234)
# ----- Univariate ----- #
# Define DGP
mdl_hmm <- list(n = 1000,
q = 1,
mu = as.matrix(c(5,
-2)),
sigma = list(as.matrix(5.0),
as.matrix(7.0)),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuHMM() function
y_hmm_simu <- simuHMM(mdl_hmm)
plot(y_hmm_simu)
# ----- Multivariate ----- #
# Define DGP
mdl_hmm <- list(n = 1000,
q = 2,
mu = rbind(c(5, -2),
c(10, 2)),
sigma = list(rbind(c(5.0, 1.5),
c(1.5, 1.0)),
rbind(c(7.0, 3.0),
c(3.0, 2.0))),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuHMM() function
y_hmm_simu <- simuHMM(mdl_hmm)
plot(y_hmm_simu)
Simulate Hidden Markov model with normally distributed errors
Description
This function simulates a Hidden Markov Model process.
Usage
simuHMM_cpp(mdl_h0, burnin = 100L, exog = FALSE)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
exog |
bool determining if there are exogenous variables ( |
Value
List with simulated series and its DGP parameters.
Simulate Markov-switching autoregressive process
Description
This function simulates a Markov-switching autoregressive process.
Usage
simuMSAR(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated Markov-switching autoregressive process and its DGP properties.
Examples
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n = 500,
mu = c(5,10),
sigma = c(1,2),
phi = c(0.5, 0.2),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)
plot(y_ms_simu)
Simulate Markov-switching ARX process
Description
This function simulates a Markov-switching autoregressive process.
Usage
simuMSARX(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated Markov-switching autoregressive process and its DGP properties.
Examples
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n = 500,
mu = c(5,10),
sigma = c(1,2),
phi = c(0.5, 0.2),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)
plot(y_ms_simu)
Simulate Markov-switching ARX process
Description
This function simulates a Markov-switching ARX process.
Usage
simuMSARX_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated Markov-switching autoregressive process and its DGP properties.
Simulate Markov-switching autoregressive process
Description
This function simulates a Markov-switching autoregressive process.
Usage
simuMSAR_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated Markov-switching autoregressive process and its DGP properties.
Simulate Markov-switching vector autoregressive process
Description
This function simulates a Markov-switching vector autoregressive process.
Usage
simuMSVAR(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Examples
set.seed(1234)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n = 1000,
p = 1,
q = 2,
mu = rbind(c(5, -2),
c(10, 2)),
sigma = list(rbind(c(5.0, 1.5),
c(1.5, 1.0)),
rbind(c(7.0, 3.0),
c(3.0, 2.0))),
phi = rbind(c(0.50, 0.30),
c(0.20, 0.70)),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)
plot(y_msvar_simu)
Simulate Markov-switching VARX process
Description
This function simulates a Markov-switching VARX process.
Usage
simuMSVARX(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Examples
set.seed(1234)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n = 1000,
p = 1,
q = 2,
mu = rbind(c(5, -2),
c(10, 2)),
sigma = list(rbind(c(5.0, 1.5),
c(1.5, 1.0)),
rbind(c(7.0, 3.0),
c(3.0, 2.0))),
phi = rbind(c(0.50, 0.30),
c(0.20, 0.70)),
k = 2,
P = rbind(c(0.90, 0.10),
c(0.10, 0.90)))
# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)
plot(y_msvar_simu)
Simulate Markov-switching VARX process
Description
This function simulates a Markov-switching VARX process.
Usage
simuMSVARX_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Simulate Markov-switching vector autoregressive process
Description
This function simulates a Markov-switching vector autoregressive process.
Usage
simuMSVAR_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Likelihood ratio test statistic sample distribution
Description
This function is used by Monte Carlo Likelihood ratio testing procedures to simulate processes under the null hypothesis.
Usage
simuMdl(mdl_h0, p, q, k, burnin, exog)
Arguments
mdl_h0 |
List with restricted model properties. |
p |
integer specifying the number of autoregressive lags. |
q |
integer specifying the number of series. |
k |
integer specifying the number of regimes. |
burnin |
integer specifying the number of observations to drop from beginning of simulation. |
Value
List with simulated process properties.
Simulate normally distributed process
Description
This function simulates a normally distributed process.
Usage
simuNorm(mdl_h0, burnin = 0)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated series and its DGP parameters.
Examples
set.seed(1234)
# Define DGP
mdl_norm <- list(n = 1000,
q = 2,
mu = c(5, -2),
sigma = rbind(c(5.0, 1.5),
c(1.5, 1.0)))
# Simulate process using simuNorm() function
y_norm_simu <- simuNorm(mdl_norm)
plot(y_norm_simu)
Simulate normally distributed process
Description
This function simulates a normally distributed process.
Usage
simuNorm_cpp(mdl_h0, burnin = 0L, exog = FALSE)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
exog |
bool determining if there are exogenous variables ( |
Value
List with simulated series and its DGP parameters.
Simulate VAR process
Description
This function simulates a vector autoregresive process.
Usage
simuVAR(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Simulate VAR process
Description
This function simulates a vector autoregresive process.
Usage
simuVARX(mdl_h0, burnin = 100)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Simulate VARX process
Description
This function simulates a VARX process.
Usage
simuVARX_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Simulate VAR process
Description
This function simulates a vector autoregresive process.
Usage
simuVAR_cpp(mdl_h0, burnin = 100L)
Arguments
mdl_h0 |
List containing the following DGP parameters
|
burnin |
Number of simulated observations to remove from beginning. Default is |
Value
List with simulated vector autoregressive series and its DGP parameters.
Summary of an ARmdl
object
Description
This is a method for the function summary()
for objects of the class ARmdl
.
Usage
## S3 method for class 'ARmdl'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The ARmdl
object is returned invisibly.
Summary of a BootLRTest
object
Description
This is a method for the function summary()
for objects of the class BootLRTest
.
Usage
## S3 method for class 'BootLRTest'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The BootLRTest
object is returned invisibly.
Summary of a CHPTest
object
Description
This is a method for the function summary()
for objects of the class CHPTest
.
Usage
## S3 method for class 'CHPTest'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The CHPTest
object is returned invisibly.
summaryummary of a DLMCTest
object
Description
This is a method for the function summary()
for objects of the class DLMCTest
.
Usage
## S3 method for class 'DLMCTest'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The DLMCTest
object is returned invisibly.
Summary of a DLMMCTest
object
Description
This is a method for the function summary()
for objects of the class DLMMCTest
.
Usage
## S3 method for class 'DLMMCTest'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The DLMMCTest
object is returned invisibly.
Summary of a CHPTest
object
Description
This is a method for the function summary()
for objects of the class CHPTest
.
Usage
## S3 method for class 'HLRTest'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The CHPTest
object is returned invisibly.
Summary of a HMmdl
object
Description
This is a method for the function summary()
for objects of the class HMmdl
.
Usage
## S3 method for class 'HMmdl'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The HMmdl
object is returned invisibly.
Summary of a LMCLRTest
object
Description
This is a method for the function summary()
for objects of the class LMCLRTest
.
Usage
## S3 method for class 'LMCLRTest'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The LMCLRTest
object is returned invisibly.
Summary of a MMCLRTest
object
Description
This is a method for the function summary()
for objects of the class MMCLRTest
.
Usage
## S3 method for class 'MMCLRTest'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The MMCLRTest
object is returned invisibly.
Summary of a MSARmdl
object
Description
This is a method for the function summary()
for objects of the class MSARmdl
.
Usage
## S3 method for class 'MSARmdl'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The MSARmdl
object is returned invisibly.
Summary of a MSVARmdl
object
Description
This is a method for the function summary()
for objects of the class MSVARmdl
.
Usage
## S3 method for class 'MSVARmdl'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The MSVARmdl
object is returned invisibly.
Summary of a Nmdl
object
Description
This is a method for the function summary()
for objects of the class Nmdl
.
Usage
## S3 method for class 'Nmdl'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The Nmdl
object is returned invisibly.
Summary of an VARmdl
object
Description
This is a method for the function summary()
for objects of the class VARmdl
.
Usage
## S3 method for class 'VARmdl'
summary(object, digits = getOption("digits"), ...)
Arguments
object |
an object for which a summary is desired. |
digits |
integer, used for number formatting with
|
... |
additional arguments affecting the summary produced. |
Value
The VARmdl
object is returned invisibly.
Theta standard errors
Description
This function computes the standard errors of the parameters in vector theta. This is done using an approximation of the Hessian matrix (using hessian
and nearPD
if info_mat
is not PD).
Usage
thetaSE(mdl)
Arguments
mdl |
List with model properties |
Value
List provided as input with additional attributes HESS
,theta_se
, info_mat
, and nearPD_used
.
Lagged Time Series Data
Description
This function takes a (T x 1
) vector Y
and returns the (T-p x 1
) vector y
and the (T-p x p
) matrix of lagged observations.
Usage
ts_lagged(Y, p)
Arguments
Y |
Vector with time series observations. |
p |
integer for the number of lags to use in estimation. Must be greater than or equal to |
Value
List with vector y
(vector of lagged Y
) and matrix X
of lagged observations.