Skip to contents

A S3 class that can be used to define a hidden markov model, which can then be used by the ther functions in this package.

Usage

HMM(initial_dist,transmission , emis_names, parameterlist)

Arguments

initial_dist

numerical vector of the stationary distribution

transmission

numerical matrix containing the transmission probabilities

emis_names

vector of names for emission functions

parameterlist

list of list, where each list containing the parameters needed in the corresponding emission function

state_names

vector of names for each state

parm1

vector of parameters

parm2

vector of parameters

Value

A HMM class object

Details

The user will have to define parameters behind this model. This would be the initial distribution, transmission matrix and the distribution of each hidden state with its parameters. The distribution will come as a vector of strings, where each string is the name of the density function to be used for that hidden state. If only one string is defined, then that one will be used as the distribtuion for all the hidden states.

The user has two ways to define what parameters the density functions will use. If the density only need up to two different parameters, then the variables parm1 and parm2 can be used. They can either be a vector where each value will be a parameter in the corresponding distribution or if the same value should be a parameter in each of the distribution then a single value will work.

Alternativly the user can also give the parameters in a list of lists, where the internal list each contain all the parameters needed for the corresponding distribution.

The class has its own print function, which will print out the parameter for the HHM. The user can use their own density function, if R does not have then one they want to use. However then it will be required that the function is defined in the current environment. To ensure this it may be necessary for the users custom function to be defined in the same environment as the HMM function.

Here it is important to note that if the user specify their own distribution function, then it is necessary for the quantile parameter to be called x.

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 = "dpois",parameterlist = list(list(lambda=10),
list(lambda=30)) )
HM
#> [1] "This is a Hidden Markov model with 2 hidden states."
#> [1] "It has the initial distirbution of:"
#> [1] 0.5 0.5
#> [1] "It has the transmision matrix:"
#>      [,1] [,2]
#> [1,]  0.9  0.1
#> [2,]  0.1  0.9
#> [1] "State 1  has the emission function dpois with parameters lambda = 10"
#> [1] "State 2  has the emission function dpois with parameters lambda = 30"