## create two state HMM with t distributions
state.names <- c("one","two")
transition <- c(0.035, 0.01)
location <- c(1, 2)
scale <- c(1, 1)
df <- c(4, 6)
hmm1 <- getHMM(list(a=transition, mu=location, sigma=scale, nu=df),
state.names)
## generate observation sequences from model
obs.lst <- list()
for(i in 1:50) obs.lst[[i]] <- sampleSeq(hmm1, 100)
## fit an HMM to the data (with fixed degrees of freedom)
hmm2 <- hmm.setup(obs.lst, state=c("one","two"), df=5)
hmm2.fit <- viterbiTraining(hmm2, obs.lst, max.iter=20, df=5, verbose=1)
## fit an HMM to the data, this time estimating the degrees of freedom
hmm3.fit <- viterbiTraining(hmm2, obs.lst, max.iter=20, verbose=1)
Run the code above in your browser using DataLab