Learn R Programming

HMMHSMM (version 0.1.0)

findmleHSMMnostarting: Fit Hidden Semi-Markov Model (HSMM) Without User-Provided Starting Values

Description

Fits a hidden semi-Markov model (HSMM) to a univariate time series by maximum likelihood, using multiple randomly generated initializations instead of user-provided starting parameters. The best-fitting model is selected by log-likelihood.

Usage

findmleHSMMnostarting(J, x, obsdist, dwelldist, M = NA, no.initials = 50,
                      verbose = TRUE, seed = NULL, ...)

Value

An object containing:

loglikelihoods

Numeric vector of log-likelihood values across iterations.

AIC

Akaike Information Criteria for the fitted model.

BIC

Bayesian Information Criteria for the fitted model.

delta

Numeric vector. Estimated initial state probabilities.

Pi

Matrix. Estimated J x J transition probability matrix.

dwellparameters

List. Estimated dwell-time distribution parameters.

observationparameters

List. Estimated observation distribution parameters.

Arguments

J

Integer, number of hidden states (must be at least 2).

x

Numeric vector, observed time series.

obsdist

Character string specifying the observation distribution. One of "pois", "norm", "weibull", "zip", "nbinom", "zinb", "exp", "gamma", "lnorm", "gev", "ZInormal", "ZIgamma".

dwelldist

Character string specifying the dwell-time distribution. One of "pois", "nbinom", "betabinom".

M

Integer, truncation parameter for dwell-time distribution (default NA, computed automatically).

no.initials

Integer, number of random starting values to try (default 50).

verbose

Logical, if TRUE (default), progress messages are printed to the console. Set to FALSE to suppress informational output.

seed

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

...

Further arguments to pass to findmleHSMM, such as maxiter and tol.

Author

Aimee Cody

Details

This function automates parameter initialization by sampling plausible random values for state-dependent observation parameters, dwell-time parameters, initial distribution \(\delta\), and transition matrix \(\Pi\). It repeatedly calls findmleHSMM with these initializations, and retains the model with the highest log-likelihood. When obsdist = "gev", initial values are obtained via repeated calls to evd::fgev on random data segments until a sufficient number of estimates are collected.

See Also

findmleHSMM, for fitting an HSMM with user-supplied initial values. generateHSMM, for simulating HSMM data. findmleHMMnostarting, for the non-initialised estimation of hidden Markov models.

Examples

Run this code
set.seed(321)
J <- 3
Pi <- matrix(c(0.0, 0.6, 0.4,
               0.5, 0.0, 0.5,
               0.3, 0.7, 0.0), nrow = J, byrow = TRUE)
obspar <- list(
  mean = c(-2, 0, 3),
  sd   = c(1, 1.5, 2)
)
dwellpar <- list(
  lambda = c(3, 5, 4)
)
sim <- generateHSMM(n = 200, J = J, obsdist = "norm",
                    dwelldist = "pois", obspar = obspar,
                    dwellpar = dwellpar, Pi = Pi)
fit <- findmleHSMMnostarting(J = J, x = sim$x,
                                       obsdist = "norm", dwelldist = "pois",
                                       M = 100, no.initials = 30)
fit$observationparameters
fit$dwellparameters
fit$Pi
fit$delta
fit$loglikelihoods

Run the code above in your browser using DataLab