Package 'modMStates'

Title: What the Package Does (Title Case)
Description: More about what it does (maybe more than one line). Continuation lines should be indented.
Authors: Jane Doe [aut, cre]
Maintainer: Jane Doe <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-10-04 10:03:18 UTC
Source: https://github.com/infinitebstats/modmstates

Help Index


Fit a Continuous-Time Multi-State Model

Description

A unified interface to fit predefined continuous-time Markov multi-state models using the msm package. The function selects an appropriate model structure based on the specified process type and returns key inferential results including transition intensities, sojourn times, and transition probability matrices.

Usage

fit.msm(data, process, state, subject, time, t = 4)

Arguments

data

A data frame containing the multi-state panel data.

process

Character string specifying the MSM structure. One of: "two_state", "recurrent", "illness_death3", "illness_death4", "reversible_id", "competing_risks", "complex".

state

Character string. Name of the state variable in data.

subject

Character string. Name of the subject identifier in data.

time

Character string. Name of the time variable in data.

t

Numeric. Time point at which transition probabilities are computed (default 4).

Details

The following process types map to predefined intensity matrix structures:

"two_state"

1 -> 2 (absorbing).

"recurrent"

1 <-> 2 (reversible).

"illness_death3"

1 -> 2, 1 -> 3, 2 -> 3; state 3 absorbing.

"illness_death4"

1 -> 2 -> 3 -> 4; state 4 absorbing.

"reversible_id"

1 <-> 2, 1 -> 3, 2 -> 3; state 3 absorbing.

"competing_risks"

1 -> 2, 1 -> 3; states 2 and 3 absorbing.

"complex"

1 <-> 2, 1 -> 3, 1 -> 4, 2 -> 3, 2 -> 4; states 3 and 4 absorbing.

Value

An object of class "msm_results", which is a named list with the following components:

fit

Summary of the fitted msm model object.

state_table

Observed transition frequency table.

qmatrix

Estimated transition intensity matrix with confidence intervals.

sojourn

Estimated mean sojourn times in each transient state.

pmatrix

Transition probability matrix at time t.

See Also

sim.mspdata for simulating multi-state data, msm for the underlying model fitting engine.

Examples

dat <- sim.mspdata(process = "two_state", n = 200, t = 10)
res <- fit.msm(
  data    = dat,
  process = "two_state",
  state   = "state",
  subject = "subject",
  time    = "time",
  t       = 4
)
res$qmatrix
res$sojourn
res$pmatrix

Simulate Multi-State Model Data

Description

A unified interface to simulate data from different continuous-time Markov multi-state processes using predefined MSM structures. Data are generated using simmulti.msm from the msm package.

Usage

sim.mspdata(process, n, t)

Arguments

process

Character string specifying the MSM type. One of: "two_state", "recurrent", "illness_death_3state", "illness_death_4state", "reversible_illness_death", "competing_risks", "complex".

n

Integer. Number of subjects to simulate.

t

Numeric. Maximum follow-up time (observations are generated at integer times from 0 to t).

Details

The following process structures are available:

"two_state"

Simple failure process: state 1 (alive) to state 2 (failure, absorbing).

"recurrent"

Recurrent event process: individuals move between state 1 (no event) and state 2 (event) repeatedly.

"illness_death_3state"

Three-state illness-death model: healthy, ill, and death (absorbing). Transitions from healthy to ill, healthy to death, and ill to death.

"illness_death_4state"

Four-state illness-death model: healthy, mild illness, severe illness, and death (absorbing).

"reversible_illness_death"

Reversible illness-death model: healthy and ill states are reversible, with death as absorbing.

"competing_risks"

Competing risks process: state 1 (event-free) with two absorbing failure states.

"complex"

Complex hybrid model combining recurrent illness, competing risks, and illness-dependent mortality.

Value

A data frame containing simulated multi-state panel data with columns subject, time, and state. Additional attributes "process", "n", and "t" record the simulation parameters.

See Also

fit.msm for fitting multi-state models to the simulated data.

Examples

sim <- sim.mspdata(process = "two_state", n = 200, t = 10)
head(sim)

sim2 <- sim.mspdata(process = "recurrent", n = 150, t = 10)
head(sim2)