% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_hmm.R
\name{fit_hmm}
\alias{fit_hmm}
\title{Fit Regime-Switching Regression (HMM)}
\usage{
fit_hmm(formula, data, nstates = 2, seed = 42, maxiter = 100, tol = 1e-6)
}
\arguments{
\item{formula}{an object of class \code{\link[stats]{formula}}.}

\item{data}{a data frame containing the variables in the formula.}

\item{nstates}{integer; number of hidden states (default: 2).}

\item{seed}{integer; random seed for reproducibility (default: 42).}

\item{maxiter}{integer; maximum EM iterations (default: 100).}

\item{tol}{numeric; convergence tolerance (default: 1e-6).}
}
\value{
An object of class \code{"ArvindFit"}, a list containing the
same standard fields as \code{\link[=fit_rw1]{fit_rw1()}}, plus:
\describe{
\item{nstates}{integer; number of hidden states.}
\item{states}{integer vector; Viterbi-decoded state sequence.}
\item{trans_probs}{matrix; estimated transition probability matrix.}
\item{state_betas}{list of numeric vectors; state-specific coefficients.}
\item{state_sigmas}{numeric vector; state-specific standard deviations.}
}
}
\description{
Fits a hidden Markov model with state-dependent coefficients and
Arvind-distributed errors. The EM algorithm with forward-backward
recursions is used for parameter estimation, and the Viterbi algorithm
decodes the most likely state sequence.
}
\examples{
dat <- simulate_arvind_data(n = 50, seed = 1)
m5 <- fit_hmm(Y ~ X1 + X2 + X3, dat, nstates = 2, seed = 42)
m5$states

}
\seealso{
\code{\link[=diagnostics_arvind]{diagnostics_arvind()}}, \code{\link[=forecast_arvind]{forecast_arvind()}}, \code{\link[=cv_arvind]{cv_arvind()}}
}
