fit_model {fHMM} | R Documentation |
Model fitting
Description
This function fits a hidden Markov model via numerical likelihood maximization.
Usage
fit_model(
data,
controls = data[["controls"]],
fit = list(),
runs = 10,
origin = FALSE,
accept = 1:3,
gradtol = 0.01,
iterlim = 100,
print.level = 0,
steptol = 0.01,
ncluster = 1,
seed = NULL,
verbose = TRUE,
initial_estimate = NULL
)
Arguments
data |
An object of class |
controls |
Either a The
Either none, all, or selected elements can be specified. Unspecified parameters are set to their default values. Important: Specifications in |
fit |
A The
Either none, all, or selected elements can be specified. Unspecified parameters are set to their default values, see below. Specifications in |
runs |
An By default, |
origin |
Only relevant for simulated data, i.e., if the In this case, a By default, |
accept |
An By default, |
gradtol |
A positive By default, |
iterlim |
A positive By default, |
print.level |
One of By default, |
steptol |
A positive By default, |
ncluster |
Set the number of clusters for parallel optimization runs to reduce
optimization time.
By default, |
seed |
Set a seed for the generation of initial values. No seed by default. |
verbose |
Set to |
initial_estimate |
Optionally defines an initial estimate for the numerical likelihood optimization. Good initial estimates can improve the optimization process. Can be:
|
Details
Multiple optimization runs starting from different initial values are
computed in parallel if ncluster > 1
.
Value
An object of class fHMM_model
.
Examples
### 2-state HMM with normal distributions
# set specifications
controls <- set_controls(
states = 2, sdds = "normal", horizon = 100, runs = 10
)
# 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)
plot(model, "ts")
# predict
predict(model, ahead = 5)