Fit a K-regime Markov-switching model with a switching mean and a
switching variance, \(y_t \mid s_t = j \sim N(\mu_j,
\sigma_j^2)\), by EM with the Hamilton filter and Kim smoother. This
is the model MSwM::msmFit(lm(y ~ 1), k, sw = c(TRUE, TRUE))
fits, computed natively: the E- and M-steps reproduce MSwM's EM
(including its transition-matrix update, which normalises the summed
smoothed joint probabilities by the occupancy of the destination
regime, so its fixed point can differ from the exact maximum
likelihood estimate in the fourth decimal of the log-likelihood).
Instead of MSwM's random starts the EM runs from two deterministic
starts (regimes split by the quantiles of \(y\) and of
\(|y - median(y)|\)) and keeps the higher log-likelihood. No
external package is used.
Value
Named list with \(mu, sigma, transition,
smoothed_probabilities, loglik, n, k_regimes, method\). Regimes are
ordered by increasing mu. transition uses MSwM's
column convention: transition[j, i] is
\(Pr(s_t = j \mid s_{t-1} = i)\) (columns sum to 1).
smoothed_probabilities is n x K (observations 1..n).
loglik is the maximised log-likelihood (MSwM's
logLikel slot stores its negative).
