knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center", fig.path = "man/figures/README-" )
User-friendly and flexible algorithm for time series segmentation with a regression model governed by a hidden Markov process.
Hidden Markov Model Regression (HMMR) for segmentation of time series with regime changes. The model assumes that the time series is governed by a sequence of hidden discrete regimes/states, where each regime/state has Gaussian regressors as observations. The model parameters are estimated by MLE via the EM algorithm.
You can install the development version of HMMR from GitHub with:
# install.packages("devtools") devtools::install_github("fchamroukhi/HMMR_r")
To build vignettes for examples of usage, type the command below instead:
# install.packages("devtools") devtools::install_github("fchamroukhi/HMMR_r", build_opts = c("--no-resave-data", "--no-manual"), build_vignettes = TRUE)
Use the following command to display vignettes:
browseVignettes("HMMR")
library(HMMR)
# Application to a toy data set data("toydataset") x <- toydataset$x y <- toydataset$y K <- 5 # Number of regimes (states) p <- 3 # Dimension of beta (order of the polynomial regressors) variance_type <- "heteroskedastic" # "heteroskedastic" or "homoskedastic" model n_tries <- 1 max_iter <- 1500 threshold <- 1e-6 verbose <- TRUE hmmr <- emHMMR(X = x, Y = y, K, p, variance_type, n_tries, max_iter, threshold, verbose) hmmr$summary() hmmr$plot()
# Application to a real data set data("realdataset") x <- realdataset$x y <- realdataset$y2 K <- 5 # Number of regimes (states) p <- 3 # Dimension of beta (order of the polynomial regressors) variance_type <- "heteroskedastic" # "heteroskedastic" or "homoskedastic" model n_tries <- 1 max_iter <- 1500 threshold <- 1e-6 verbose <- TRUE hmmr <- emHMMR(X = x, Y = y, K, p, variance_type, n_tries, max_iter, threshold, verbose) hmmr$summary() hmmr$plot()
In this package, it is possible to select models based on information criteria such as BIC, AIC and ICL.
The selection can be done for the two following parameters:
Let's select a HMMR model for the following time series Y:
data("toydataset") x <- toydataset$x y <- toydataset$y plot(x, y, type = "l", xlab = "x", ylab = "Y")
selectedhmmr <- selectHMMR(X = x, Y = y, Kmin = 2, Kmax = 6, pmin = 0, pmax = 3) selectedhmmr$plot(what = "smoothed")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.