Learn R Programming

fHMM (version 1.2.2)

fit_model: Model fitting

Description

This function fits a HMM to fHMM_data via numerical likelihood maximization.

Usage

fit_model(data, ncluster = 1, seed = NULL, verbose = TRUE, init = NULL)

Value

An object of class fHMM_model.

Arguments

data

An object of class fHMM_data.

ncluster

Set the number of clusters for parallelization. By default, ncluster = 1.

seed

Set a seed for the sampling of initial values. No seed by default.

verbose

Set to TRUE to print progress messages.

init

Optionally an object of class parUncon for initialization. This can for example be the estimate of a previously fitted model model, i.e. the element model$estimate. The initial values are computed via replicate(n, jitter(init, amount = 1), simplify = FALSE), where n <- data$controls$fit$runs.

Details

The function is parallelized if ncluster > 1.

Examples

Run this code
### 2-state HMM with normal distributions

# define model
controls <- set_controls(states = 2, sdds = "normal", horizon = 100, runs = 20)

# define parameters
parameters <- fHMM_parameters(controls, mu = c(-1, 1), seed = 1)

# sample data
data <- prepare_data(controls, true_parameter = parameters, seed = 1)

# fit model
model <- fit_model(data, seed = 1)

# inspect fit
summary(model)
plot(model, "sdds")

# decode states
model <- decode_states(model)

# predict
predict(model, ahead = 5)

Run the code above in your browser using DataLab