HMMFit {RHmm}R Documentation

Fit a Hidden Markov Model

Description

This function returns an HMMFitClass object which contains the results of the Baum-Welch algorithm for the user's data

Usage

    HMMFit(obs, dis="NORMAL", nStates=,  ...)
    HMMFit(obs, dis="DISCRETE", nStates=,  ...)
    HMMFit(obs, dis="MIXTURE", nStates=, nMixt=, ...)

Arguments

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 = 'NORMAL', 'DISCRETE' or 'MIXTURE'. Default 'NORMAL'.
nStates Number of hidden states. Default 2.
nMixt Number of mixtures of normal distributions if dis ='MIXTURE'
... optional parameter:
control
A list of control parameters for the Baum-Welch algorithm. See control parameter

Value

a HMMFitClass object:

HMM A HMMClass object with the fitted values of the model
LLH log-likelihood
BIC BIC criterium
nIter Number of iterations of the Baum-Welch algorithm
relVariation last relative variation of the LLH function
asymptVar an HMMClass object with asymtotic variance of the parameters. See asymptotic variance
call The call object of the function call

obs parameter

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.

control parameter

init
Kind of initialisation ='KMEANS' (for univariate or multivariate normal distributions), 'RANDOM' or 'USER'. Default 'RANDOM', see Random Initialization
iter
Maximum number of iterations for the Baum-Welch algorithm. Default 500
tol
Tolerance of the relative log-likehood augmentation. Default 1e-6
verbose
=0, no details, =1 iterations are displayed. Default 0
nInit
Number of random initialisations. Default 5
nIterInit
Number of maximum iterations of the Baum-Welch algorithm in the random initialisation phase. Default 5
initPoint
An HMMClass object used to initialize the parameters of the Baum-Welch algorithm. Default NULL.
if initPoint != NULL, init is set to "USER"

Random initialization

'initProb' and 'transMat' parameters are uniformly drawn.

For univariate normal distributions, empirical mean m and variance s^2 of all the samples are computed. Then for every states, an initial value of the 'mean' parameter is uniformly drawn between m - 3s and m + 3s and an initial value of the 'var' parameter is uniformly drawn between 0.5 s^2 and 3 s^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.

asymptotic variance

The asymptotic variance of estimates is computed using finite difference approximation.
The summary and print.summary methods display the results.

References

Jeff A. Bilmes (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

Ingmar Visser, Maartje E. J. Raijmakers and Peter C. M. Molenaar (2000) Confidence intervals for hidden Markov model parameters, British Journal of Mathematical and Statistical Psychology, 53, 317-327.

Examples

    data(geyser)
    obs <- geyser$duration
    #Fits an 2 states gaussian model for geyser duration
    ResGeyser1 <- HMMFit(obs)
    # fit a 3 states gaussian HMM for geyser duration
    # with iterations printing and kmeans initialization
    ResGeyser2 <- HMMFit(obs, nStates=3, paramBW=list(verbose=1, init="KMEANS"))
    # fit a 2 states of a mixture of 3 normal distributions
    # for data_mixture
    data(data_mixture)
    ResMixture <- HMMFit(data_mixture, nStates=2, nMixt=3, dis="MIXTURE")
    summary(ResMixture)
    # geyser data - 3 states HMM with bivariate normal distribution
    ResGeyser<-HMMFit(obs=as.matrix(geyser), nStates=3)
    # multiple samples discrete observations
    data(weather)
    ResDiscrete <- HMMFit(obs=weather, nStates=3, dis="DISCRETE")

[Package RHmm version 1.0.1 Index]