HMMFit | R Documentation |
This function returns an HMMFitClass object which contains the results of the Baum-Welch algorithm for the user's data
HMMFit(obs, dis="NORMAL", nStates=2, asymptCov=FALSE, ...)
obs |
A vector, a matrix, a data frame, a list of vectors or a list of matrices of observations. See section obs parameter. |
dis |
Distribution name. In 'NORMAL', 'DISCRETE' or 'MIXTURE'. Default 'NORMAL'. |
nStates |
Number of hidden states. Default 2. |
asymptCov |
A boolean. asymptCov=TRUE if the asymptotic covariance matrix is computed. Default FALSE. |
... |
Other parameters. See Details. |
Typical usages are:
HMMFit(obs, dis="NORMAL", nStates=, ..., asymptCov=FALSE)
HMMFit(obs, dis="DISCRETE", nStates=, levels=NULL, ..., asymptCov=FALSE)
HMMFit(obs, dis="MIXTURE", nStates=, nMixt=, ..., asymptCov=FALSE)
The differents arguments are:
A vector, a matrix, a data frame, a list of vectors or a list of matrices of observations. See section obs parameter.
Distribution name. In 'NORMAL', 'DISCRETE' or 'MIXTURE'. Default 'NORMAL'.
Number of hidden states. Default 2.
Number of mixtures of normal distributions if dis ='MIXTURE'
A character vector of all different levels of 'obs'. By Default (levels=NULL), this vector is computed from 'obs'.
A boolean. asymptCov=TRUE if the asymptotic covariance matrix is computed. Default FALSE.
optional parameter:
A list of control parameters for the Baum-Welch algorithm. See control parameter
a ‘HMMFitClass’ object with the following elements:
A HMMClass object with the fitted values of the model. See HMMSet.
Log-likelihood
BIC criterium
Number of iterations of the Baum-Welch algorithm
last relative variation of the LLH function
Asymptotic covariance matrix of independant parameters. NULL if not computed.
the observations.
The call object of the function call
If you fit the model with only one sample, obs is
either a vector (for univariate distributions) or a matrix (for multivariate distributions) or a data frame.
In the two last cases, the number of columns of obs defines the dimension of observations.
If you fit the model with more than one sample, obs is a list of samples. Each element of obs is then a vector
(for univariate distributions) or a matrix (for multivariate distributions). The samples do not need to have the same length.
For discrete distributions, obs can be a vector (or a list of vectors) of any type of R factor objects.
Kind of initialisation ='KMEANS' (for univariate or multivariate normal distributions), 'RANDOM' or 'USER'. Default 'RANDOM', see Random Initialization
Maximum number of iterations for the Baum-Welch algorithm. Default 500
Tolerance of the relative log-likehood augmentation. Default 1e-6
=0, no details, =1 iterations are displayed. Default 0
Number of random initialisations. Default 5
Number of maximum iterations of the Baum-Welch algorithm in the random initialisation phase. Default 5
An HMMClass object used to initialize the parameters of the Baum-Welch algorithm. Default NULL.
if initPoint != NULL, init is set to "USER"
'initProb' and 'transMat' parameters are uniformly drawn.
For univariate normal distributions, empirical mean m
and variance \sigma^2
of all the samples are computed.
Then for every states,
an initial value of the 'mean' parameter is uniformly drawn between m - 3\,\sigma
and m - 3\,\sigma
and an initial value of the 'var'
parameter is uniformly drawn between \frac{1}{2}\,\sigma^2
and 3\,\sigma^2
.
For multivariate normal distributions, the same procedure is applied for each component of the mean vectors.
The initial covariance matrix is diagonal, and each initial variance is computed as for univariate models.
For mixtures of univariate normal distributions, initial values for 'mean' and 'var' parameters are computed
the same way than for normal distributions. The initial value of 'proportion' parameter is uniformly drawn.
For mixtures of multivariate normal distributions, the same procedure is applied for each component of the mean vectors,
all the covariance matrices are diagonal and each initial variance is computed as for univariate models. The initial value
of 'proportion' parameter is also uniformly drawn.
For discrete distributions, the initial values of 'proba' parameters are uniformly drawn.
Of course, the initial values of the parameters 'initProba', 'proba', 'proportion' and 'transMat' are standardized to
ensure that they can represent probabilities vectors or transition matrices.
The asymptotic covariance matrix of estimates is computed using the Lystig and Hugues's algorithm.See asymptoticCov.
The summary and print.summary methods display the results.
Bilmes Jeff A. (1997) A Gentle Tutorial of the EM Algorithm and its Application to Parameter Estimation for Gaussian Mixture and Hidden Markov Models http://ssli.ee.washington.edu/people/bilmes/mypapers/em.ps.gz
# Fit a 3 states 1D-gaussian model
data(n1d_3s)
HMMFit(obs_n1d_3s, nStates=3)
# Fit a 3 states gaussian HMM for obs_n1d_3s
# with iterations printing and kmeans initialization
Res_n1d_3s <- HMMFit(obs=obs_n1d_3s, nStates=3,
control=list(verbose=1, init="KMEANS"),
asymptCov=TRUE)
summary(Res_n1d_3s)
# Fit a 2 states 3D-gaussian model
data(n3d_2s)
summary(HMMFit(obs_n3d_2s, asymptCov=TRUE))
# Fit a 2 states mixture of 3 normal distributions HMM
# for data_mixture
data(data_mixture)
ResMixture <- HMMFit(data_mixture, nStates=2, nMixt=3,
dis="MIXTURE")
# Fit a 3 states discrete HMM for weather data
data(weather)
ResWeather <- HMMFit(weather, dis='DISCRETE', nStates=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.