Diagnosing Markov-Switching VAR Estimation Failures
Summary
The note addresses a non-finite initial-value error when estimating a Markov-switching vector autoregression in R. One answer suggests that the model may require stationary input and recommends removing trends, for example by subtracting a mean or a fitted linear trend. It explains the failure as a likelihood calculation that cannot initialize when the data do not meet the model’s assumptions, while acknowledging uncertainty about the diagnosis.
A second answer offers another possible explanation: the sample may be too short for the model and its optimization procedure. It reports that duplicating the short sample allowed the example to run, but that is not evidence that the resulting estimates are statistically reliable. The exchange therefore highlights two diagnostics—stationarity and sample adequacy—rather than establishing a definitive cause. Detrending choices should be grounded in the data and theory, and neither artificial duplication nor a successful optimizer run validates a regime model.
Key ideas
- Check whether the input series is stationary before fitting a Markov-switching VAR.
- Consider removing a mean or trend when justified by the data and research question.
- A non-finite initial likelihood can reflect violated assumptions or unsuitable inputs.
- A very short sample may be inadequate for estimating a regime-switching model.
- Duplicating observations may make an algorithm run but does not establish reliable inference.
Tags
Full text
# Error when trying to estimate a Markov-switching Var model in R
# Error when trying to estimate a Markov-switching Var model in R
I'm trying to estimate a Markov-switching VAR in R using the command msvar. These are the first 10 entries of my two time series. I have 798. When I try to run this I get an Error message
```
a <- c(1.998513, 1.995302, 2.030693, 2.122130, 2.236770, 2.314639, 2.365214, 2.455784, 2.530696, 2.596537)
b <- c(0.6421369, 0.6341437, 0.6494933, 0.6760939, 0.7113511, 0.7173038, 0.7250545, 0.7812490, 0.7874657, 0.8275209)
x <- matrix (NA,10,2)
x[,1] <- a
x[,2] <- b
time.seriesx <- ts(x)
markov.switchingx <- msvar(time.seriesx, p = 2, h = 2, niterblkopt = 10)
```
The error message I get is the following:
> Error in optim(par = c(beta0.it), fn = llf.msar, Y = Yregmat, X = Xregmat, : initial value in 'vmmin' is not finite
Anyone who could help me? Thanks
## Answer by Anatoly Makarevich (score 2)
https://quant.stackexchange.com/a/33234
For anyone looking for an answer to a similar question as the OP:
MS-VAR works only for stationary time series (as far as I understand). You need to de-trend your time series: either by subracting the mean, subtracting the linear trend, the moving average, a smoothed curve, etc - whatever works best for your current problem or is backed by theory.
The errors the code gives are very cryptic, but the basic idea is that the log-loss function (for ML estimation of the parameters) in your case was uninitialized because the model assumptions didn't hold.
The following R code does you what you want, it seems. I have only recently started working with MS-VAR models, so take this with a grain of salt, however this is at least an actual answer... (Subtracting linear trend gives a much more understandable Regime variable than just subtracting the mean).
```
library("MSBVAR")
a <- c(1.998513, 1.995302, 2.030693, 2.122130, 2.236770, 2.314639, 2.365214, 2.455784, 2.530696, 2.596537, 2.647573, 2.735317, 2.705269, 2.699783, 2.659748, 2.641353, 2.641825, 2.613648, 2.627755, 2.627383)
b <- c(0.6421369, 0.6341437, 0.6494933, 0.6760939, 0.7113511, 0.7173038, 0.7250545, 0.7812490, 0.7874657, 0.8275209, 0.9079720, 0.9455602, 0.9426856, 0.9234943, 0.9072791, 0.9194827, 0.9021116, 0.8971606, 0.9047334, 0.8965786)
library("pracma")
xa = detrend(a) #a - mean(a) #detrend this
xb = detrend(b) #b - mean(b) #detrend this
x <- matrix (NA,20,2)
x[,1] <- xa
x[,2] <- xb
ts_x <- ts(x)
set.seed(1)
m_x <- msvar(ts_x, p = 2, h = 2, niterblkopt = 10)
fp <- ts(m_x$fp)
plot(ts_x)
plot(fp)
```
## Answer by Richi Wa (score 1)
https://quant.stackexchange.com/a/24660
I think your time series is too short. Yours has lenght 10 and you estimate with parameter `niterblkopt = 10`.
E.g. if you have a time series twice as long then it works:
```
library(MSBVAR)
a <- c(1.998513, 1.995302, 2.030693, 2.122130, 2.236770, 2.314639, 2.365214, 2.455784, 2.530696, 2.596537)
b <- c(0.6421369, 0.6341437, 0.6494933, 0.6760939, 0.7113511, 0.7173038, 0.7250545, 0.7812490, 0.7874657, 0.8275209)
x <- matrix (NA,10,2)
x[,1] <- a
x[,2] <- b
x = rbind(x,x)
time.seriesx <- ts(x)
markov.switchingx <- msvar(time.seriesx, p = 2, h = 2, niterblkopt = 10)
```
Can you use more data? It seems that there is too little data for the model - or at least for the algorithm.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.