fit_msm: Fit a continuous-time Markov multi-state model to panel data

View source: R/fit.R

fit_msmR Documentation

Fit a continuous-time Markov multi-state model to panel data

Description

Fits the continuous-time Markov model implied by one of the seven built-in structures, or by a user-supplied generator, by maximum likelihood, and returns all primary inferential summaries in a single object. Likelihood evaluation is delegated to msm.

Usage

fit_msm(data, process = NULL, state = "state", subject = "subject",
  time = "time", t = NULL, Q = NULL, deathexact = NULL,
  inits = c("crude", "user"), ci = c("normal", "none"), ...)

fit.msm(...)

Arguments

data

A data frame in long format, one row per subject-visit.

process

Character. One of ms_structures().

state, subject, time

Character. Column names in data.

t

Numeric. Horizon at which the transition probability matrix is evaluated. This has no effect on estimation.

Q

Optional user-supplied generator giving the permitted transitions.

deathexact

Integer vector of states whose entry times are recorded exactly rather than interval-censored, passed to msm.

inits

"crude" for starting values from crudeinits.msm, or "user" to use Q.

ci

Interval type passed to qmatrix.msm.

...

Further arguments passed to msm, or to fit_msm in the case of the deprecated alias.

Details

Mean sojourn times are per visit to a state, not total time occupied. Where a state can be re-entered, total occupancy exceeds the reported sojourn time by a factor equal to the expected number of visits.

State coding, duplicate visit times and observed transitions are validated against the assumed structure before the optimiser is called, and the optimiser's own convergence code is reported rather than inferred from the absence of an error.

The objective minimised by msm grows with the number of observed intervals and can overflow during the search in large samples, so that a well identified model fails with a numerical overflow. When that happens the fit is repeated with the objective rescaled, which leaves the maximum unchanged; a warning is issued and rescaled in the returned object records it. The rescaling is applied only after an unscaled attempt has failed, so a fit that succeeds without it is identical to the equivalent hand-written msm() call.

fit.msm is a deprecated alias: the name is read by S3 dispatch as the msm method of a generic called fit, and msm::msm returns objects of class msm.

Value

An object of class "modMStates_fit" with elements qmatrix (estimates, se, ci.lower, ci.upper), sojourn, pmatrix, counts, converged, convergence_code, rescaled, loglik, npar, n_subjects, n_observations, process, horizon and fit, the underlying msm object.

References

Jackson CH (2011). Multi-state models for panel data: the msm package for R. Journal of Statistical Software 38(8), 1-29.

Kalbfleisch JD, Lawless JF (1985). The analysis of panel data under a Markov assumption. Journal of the American Statistical Association 80(392), 863-871.

See Also

sim_mspdata, ms_montecarlo

Examples

dat <- sim_mspdata("illness_death_3state", n = 200, t = 10)
fit <- fit_msm(dat, "illness_death_3state", t = 5)
fit
fit$counts

modMStates documentation built on Sept. 3, 2026, 5:10 p.m.