library(knitr)
knitr::opts_chunk$set(
    fig.align = "center",
    fig.height = 5.5,
    fig.width = 6,
    warning = FALSE,
    collapse = TRUE,
    dev.args = list(pointsize = 10),
    out.width = "90%",
    par = TRUE
)
knit_hooks$set(par = function(before, options, envir)
  { if (before && options$fig.show != "none") 
       par(family = "sans", mar = c(4.1,4.1,1.1,1.1), mgp = c(3,1,0), tcl = -0.5)
})
library(HMMR)

Introduction

HMMR is an R package for flexible and user-friendly probabilistic segmentation of time series (or structured longitudinal data) with regime changes by a regression model governed by a hidden Markov process, fitted by the EM (Baum-Welch) algorithm. This document gives a quick tour of HMMR (version r packageVersion("HMMR")) functionalities. It was written in R Markdown, using the knitr package for production.

See help(package="HMMR") for further details and references provided by citation("HMMR").

Load data

data("toydataset")
x <- toydataset$x
y <- toydataset$y

Set up HMMR model parameters

K <- 5 # Number of regimes (states)
p <- 3 # Dimension of beta (order of the polynomial regressors)
variance_type <- "heteroskedastic" # "heteroskedastic" or "homoskedastic" model

Set up EM parameters

n_tries <- 1
max_iter <- 1500
threshold <- 1e-6
verbose <- TRUE

Estimation

hmmr <- emHMMR(X = x, Y = y, K, p, variance_type, n_tries, 
               max_iter, threshold, verbose)

Summary

hmmr$summary()

Plots

Predicted time series and predicted regime probabilities

hmmr$plot(what = "predicted")

Filtered time series and filtering regime probabilities

hmmr$plot(what = "filtered")

Fitted regressors

hmmr$plot(what = "regressors")

Smoothed time series and segmentation

hmmr$plot(what = "smoothed")

Log-likelihood

hmmr$plot(what = "loglikelihood")


fchamroukhi/HMMR_r documentation built on Aug. 8, 2019, 2:38 p.m.