statsmodels.tsa.regime_switching.markov_autoregression.MarkovAutoregression¶
-
class statsmodels.tsa.regime_switching.markov_autoregression.MarkovAutoregression(endog, k_regimes, order, trend=
'c'
, exog=None
, exog_tvtp=None
, switching_ar=True
, switching_trend=True
, switching_exog=False
, switching_variance=False
, dates=None
, freq=None
, missing='none'
)[source]¶ Markov switching regression model
- Parameters:¶
- endogarray_like
The endogenous variable.
- k_regimes
int
The number of regimes.
- order
int
The order of the autoregressive lag polynomial.
- trend{‘n’, ‘c’, ‘t’, ‘ct’}
Whether or not to include a trend. To include an constant, time trend, or both, set trend=’c’, trend=’t’, or trend=’ct’. For no trend, set trend=’n’. Default is a constant.
- exogarray_like,
optional
Array of exogenous regressors, shaped nobs x k.
- exog_tvtparray_like,
optional
Array of exogenous or lagged variables to use in calculating time-varying transition probabilities (TVTP). TVTP is only used if this variable is provided. If an intercept is desired, a column of ones must be explicitly included in this array.
- switching_arbool or iterable,
optional
If a boolean, sets whether or not all autoregressive coefficients are switching across regimes. If an iterable, should be of length equal to order, where each element is a boolean describing whether the corresponding coefficient is switching. Default is True.
- switching_trendbool or iterable,
optional
If a boolean, sets whether or not all trend coefficients are switching across regimes. If an iterable, should be of length equal to the number of trend variables, where each element is a boolean describing whether the corresponding coefficient is switching. Default is True.
- switching_exogbool or iterable,
optional
If a boolean, sets whether or not all regression coefficients are switching across regimes. If an iterable, should be of length equal to the number of exogenous variables, where each element is a boolean describing whether the corresponding coefficient is switching. Default is True.
- switching_variancebool,
optional
Whether or not there is regime-specific heteroskedasticity, i.e. whether or not the error term has a switching variance. Default is False.
- Attributes:¶
endog_names
Names of endogenous variables.
exog_names
The names of the exogenous variables.
k_params
(int) Number of parameters in the model
param_names
(list of str) List of human readable parameter names (for parameters
start_params
(array) Starting parameters for maximum likelihood estimation.
Notes
This model is new and API stability is not guaranteed, although changes will be made in a backwards compatible way if possible.
The model can be written as:
\[\begin{split}y_t = a_{S_t} + x_t' \beta_{S_t} + \phi_{1, S_t} (y_{t-1} - a_{S_{t-1}} - x_{t-1}' \beta_{S_{t-1}}) + \dots + \phi_{p, S_t} (y_{t-p} - a_{S_{t-p}} - x_{t-p}' \beta_{S_{t-p}}) + \varepsilon_t \\ \varepsilon_t \sim N(0, \sigma_{S_t}^2)\end{split}\]i.e. the model is an autoregression with where the autoregressive coefficients, the mean of the process (possibly including trend or regression effects) and the variance of the error term may be switching across regimes.
The trend is accommodated by prepending columns to the exog array. Thus if trend=’c’, the passed exog array should not already have a column of ones.
See the notebook Markov switching autoregression for an overview.
References
Kim, Chang-Jin, and Charles R. Nelson. 1999. “State-Space Models with Regime Switching: Classical and Gibbs-Sampling Approaches with Applications”. MIT Press Books. The MIT Press.
Methods
filter
(params[, transformed, cov_type, ...])Apply the Hamilton filter
fit
([start_params, transformed, cov_type, ...])Fits the model by maximum likelihood via Hamilton filter.
from_formula
(formula, data[, subset, drop_cols])Create a Model from a formula and dataframe.
hessian
(params[, transformed])Hessian matrix of the likelihood function, evaluated at the given parameters
information
(params)Fisher information matrix of model.
initial_probabilities
(params[, ...])Retrieve initial probabilities
Initialize (possibly re-initialize) a Model instance.
initialize_known
(probabilities[, tol])Set initialization of regime probabilities to use known values
Set initialization of regime probabilities to be steady-state values
loglike
(params[, transformed])Loglikelihood evaluation
loglikeobs
(params[, transformed])Loglikelihood evaluation for each period
predict
(params[, start, end, probabilities, ...])In-sample prediction and out-of-sample forecasting
predict_conditional
(params)In-sample prediction, conditional on the current and previous regime
regime_transition_matrix
(params[, exog_tvtp])Construct the left-stochastic transition matrix
score
(params[, transformed])Compute the score function at params.
score_obs
(params[, transformed])Compute the score per observation, evaluated at params
smooth
(params[, transformed, cov_type, ...])Apply the Kim smoother and Hamilton filter
transform_params
(unconstrained)Transform unconstrained parameters used by the optimizer to constrained parameters used in likelihood evaluation
untransform_params
(constrained)Transform constrained parameters used in likelihood evaluation to unconstrained parameters used by the optimizer
Properties
Names of endogenous variables.
The names of the exogenous variables.
(int) Number of parameters in the model
(list of str) List of human readable parameter names (for parameters actually included in the model).
(array) Starting parameters for maximum likelihood estimation.