Learn R Programming

HMMHSMM (version 0.1.0)

confintHMM: Bootstrap Confidence Intervals for Hidden Markov Models

Description

Computes bootstrap confidence intervals for the parameters of a fitted Hidden Markov Model (HMM). The function resamples data by simulating from the fitted model, refits the HMM repeatedly to the simulated data, and constructs confidence intervals for the state-dependent parameters and the transition probability matrix.

Usage

confintHMM(x, HMM, obsdist, level = 0.95, B = 100, EM = FALSE,
           verbose = TRUE, seed = NULL, ...)

Value

A list with three elements:

obspar_CI

A data frame with columns: Parameter, Estimate, Lower, and Upper, giving bootstrap confidence intervals for the observation distribution parameters.

Pi_CI

A list containing: Estimate, the estimated transition matrix from the fitted model; Lower, the lower bounds of the bootstrap confidence intervals for each transition probability; Upper, the corresponding upper bounds.

bootstrap_samples

A list containing: obspar, matrix of bootstrap samples for observation parameters; Pi, array of bootstrap samples for transition matrix; n_successful, number of successful bootstrap iterations; n_attempts, total number of attempts made.

Arguments

x

Numeric vector. The observed data sequence.

HMM

A list containing estimated HMM parameters, typically returned by findmleHMM. Must include estimate$Pi, estimate$delta, and state-dependent observation parameters.

obsdist

Character string. Observation distribution. Supported distributions: "norm", "pois", "weibull", "zip", "nbinom", "zinb", "exp", "gamma", "lnorm", "gev", "ZInormal", "ZIgamma".

level

Numeric. Confidence level for the intervals. Default is 0.95.

B

Integer. Number of bootstrap replicates to perform. Default is 100.

EM

Logical. Whether to use the EM algorithm during refitting. Default is FALSE.

verbose

Logical. If TRUE, progress messages are printed to the console. Default is TRUE.

seed

Integer or NULL. Random seed for reproducibility. Default is NULL.

...

Any other parameters that may need to be passed to findmleHMM, for example tol or maxiter.

Author

Aimee Cody

Details

The function uses a parametric bootstrap procedure. Data are simulated from the fitted HMM using generateHMM, and parameters are re-estimated with findmleHMM. Confidence intervals are then obtained from the empirical quantiles of the bootstrap replicates. When verbose = TRUE, the function reports progress. The function will stop if too many failed bootstrap attempts occur.

See Also

findmleHMM, for estimating HMM parameters from data. generateHMM, for simulating HMM data. confintHSMM, computing bootstrapped confidence intervals for a hidden semi-Markov model.

Examples

Run this code
J <- 2
Pi <- matrix(c(0.9, 0.1,
               0.2, 0.8), nrow = 2, byrow = TRUE)
obspar <- list(lambda = c(2, 7))
sim_data <- generateHMM(n = 1000, J = J, obsdist = "pois", obspar = obspar, Pi = Pi)
HMM_fit <- findmleHMM(J = J, x = sim_data$x, obsdist = "pois",
                      obspar = obspar, Pi = Pi, EM = FALSE)
# \donttest{
ci <- confintHMM(x = sim_data$x, HMM = HMM_fit, obsdist = "pois",
                 B = 50, level = 0.9)
ci$obspar_CI
ci$Pi_CI
ci_silent <- confintHMM(x = sim_data$x, HMM = HMM_fit, obsdist = "pois",
                        B = 50, level = 0.9, verbose = FALSE)
# }

Run the code above in your browser using DataLab