Learn R Programming

HMMHSMM (version 0.1.0)

confintHSMM: Bootstrap Confidence Intervals for Hidden Semi-Markov Models

Description

Computes bootstrap confidence intervals for the parameters of a fitted Hidden Semi-Markov Model (HSMM). The function resamples data by simulation from the fitted model, refits the HSMM repeatedly, and constructs confidence intervals for the state-dependent observation parameters, dwell-time distribution parameters, and the transition probability matrix.

Usage

confintHSMM(x, HSMM, obsdist, dwelldist, level = 0.95, B = 100, M = NA,
            shift = FALSE, maxiter = 100, tol = 1e-5, verbose = TRUE, seed = NULL)

Value

A list with four elements:

obspar_CI

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

dwellpar_CI

A data frame with columns: Parameter, Estimate, Lower, and Upper, giving bootstrap confidence intervals for the dwell-time 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; dwellpar, matrix of bootstrap samples for dwell-time 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.

HSMM

A list containing estimated HSMM parameters, typically returned by findmleHSMM. Must include the transition matrix Pi, observation parameters, and dwell-time parameters.

obsdist

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

dwelldist

Character string. Dwell-time distribution. Supported distributions: "pois", "nbinom", "betabinom".

level

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

B

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

M

Integer. Maximum dwell time to consider for semi-Markov states. If NA, defaults to min(length(x), 1000).

shift

Logical. Indicates whether the dwell-time distribution includes a user-specified shift parameter. If FALSE, a shift of 1 is applied automatically. Defaults to FALSE.

maxiter

Integer. Maximum number of EM iterations for each bootstrap refit. Default is 100.

tol

Numeric. Convergence tolerance for the EM algorithm during bootstrap refits. Default is 1e-5.

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.

Author

Aimee Cody

Details

The function uses a parametric bootstrap procedure. Data are simulated from the fitted HSMM using generateHSMM, and parameters are re-estimated with findmleHSMM. Confidence intervals are then obtained from the empirical quantiles of the bootstrap replicates. When verbose = TRUE, progress is reported. Replicates that fail to converge are retried until B successful fits are obtained.

See Also

findmleHSMM, for estimating HSMM parameters from data. generateHSMM, for simulating HSMM data. confintHMM, computing bootstrapped confidence intervals for a hidden Markov model.

Examples

Run this code
J <- 2
Pi <- matrix(c(0, 1,
               1, 0), nrow = 2, byrow = TRUE)

obspar <- list(mean = c(4, 3), sd = c(1, 1))

dwellpar <- list(lambda = c(5, 7))

sim_data <- generateHSMM(n = 1000, J = J, obsdist = "norm",
                         dwelldist = "pois", obspar = obspar,
                         dwellpar = dwellpar, Pi = Pi)

HSMM_fit <- findmleHSMM(x = sim_data$x, J = J, M = 100,
                        obsdist = "norm", dwelldist = "pois",
                        obspar = obspar, dwellpar = dwellpar, Pi = Pi)

# \donttest{
ci <- confintHSMM(x = sim_data$x, HSMM = HSMM_fit,
                  obsdist = "norm", dwelldist = "pois",
                  B = 50, M = 50, level = 0.9)

ci$obspar_CI
ci$dwellpar_CI
ci$Pi_CI

ci_silent <- confintHSMM(x = sim_data$x, HSMM = HSMM_fit,
                         obsdist = "norm", dwelldist = "pois",
                         B = 50, M = 50, level = 0.9, verbose = FALSE)
# }

Run the code above in your browser using DataLab