Skip to contents

The EM algorithm finds the maximum-likelihood estimates of a HMM.

Usage

em(HM,X)

Arguments

HM

A HMM object

X

Data

tol

tolerance of percentage change between likelihoods from different iterations

maxiter

the maximum number of iteration the algorithm will run

Value

HMM Returns an updated HMM object

Details

Is an iterative method to find a local maximum likelihood or a maximum poosteriori estimates of parametersin a statistical model, where the model depends on hidden variables. The EM alternates between performing an expectation step, which creates a function for the expectation of the log-likelihood evaluated using the current estimate for the parameters, and a maximization step, which computes the parameters, which maximize the expected log-likelihood found in the E step. This is then iterated. The numbers of iteration the user want to do, are dependent on the tol and maxiter parameters. Maxiter is the maximum number of iterations the user will allow the algorithm to run and tol is minimal percentage change in likelihood the algorithm need to see before running another iterations. By using these two parameters, the user can control how long the algorithm should run.

Note that if the user are using a distribution other then normal or poisson in the model, then the initial values need to be picked carefully. As numerical maximization is used to fine the optimal parameter, which can have problem with ill chosen starting parameters.

Examples

 X <- earthquakes$n
delta = c(0.5,0.5)
trans=matrix(c(0.9,0.1,0.1,0.9),2,2)
HM = HMM(initial_dist = delta,transmission = trans,  
        emis_names = c("dpois","dpois"),parameterlist = list(list(lambda=10),list(lambda=30)) )
em(HM=HM,X=X)
#> [1] "Number of iterations: 35"
#> [1] "This is a Hidden Markov model with 2 hidden states."
#> [1] "It has the initial distirbution of:"
#> [1] 1.000000e+00 3.270886e-93
#> [1] "It has the transmision matrix:"
#>            [,1]      [,2]
#> [1,] 0.92837388 0.1190377
#> [2,] 0.07162612 0.8809623
#> [1] "State 1  has the emission function dpois with parameters lambda = 15.4203141191078"
#> [1] "State 2  has the emission function dpois with parameters lambda = 26.0170570907938"