Is there any detailed materials that can help explain how to set up HMM on R Studio?

  • 1
    $\begingroup$ have you seen here? $\endgroup$ Commented Jan 21, 2018 at 15:12

3 Answers 3


You can take a look at here. As you can read from there:

  1. Download and unpack hiddenDomains

If you haven't already done this, download the latest version of hiddenDomains from the Sourceforge website

Now unpack it

shell$ tar -xzvf hiddenDomains.VERSION.NUMBER.tar.gz

Where VERSION and NUMBER represent the release that you downloaded.

  1. Install R and required R packages (if necessary) Download and install R if you don't already have it.

If you don't already have them, you will need to install two hidden Markov model libraries:

You can do this by starting R on the command line:

shell$ R

Or, if you prefer RStudio, you can use that.

Regardless of how you started R, type the following commands to install the packages.

> install.packages("depmixS4")
> install.packages("HiddenMarkov")

Here and here may also be helpful for knowing how to use it.


There is a package called ‘HMM’ (not 'hmm'). You can find the documentation here. There are a lot of tutorials available.


Use depmixS4 package in R. This basic example would help-


depmixs4 vignette is also present. u can get in package also.

A simple code sample would be-

R Code snippets-

Required library


data loading-

physician_prescrition_data <-c(12,16,45,45,56,67,78,98,120,124,156)

model execution-

HMM_model <- depmixS4::depmix(physician_prescrition_data~1, nstates = 2,ntimes=length(physician_prescrition_data))

model fitting

HMM_fm <- fit(HMM_model)

Transition probabilties-


posterior states-

posterior(HMM_fm) plot(ts(posterior(HMM_fm)[,1]))

Emission probabilties-



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.