sim_mspdata: Simulate panel multi-state data

View source: R/simulate.R

sim_mspdataR Documentation

Simulate panel multi-state data

Description

Generates exact continuous-time trajectories under a built-in or user-supplied generator and records the occupied state at a set of observation times, producing a panel dataset in long format. sim_semimarkov is the Weibull-sojourn wrapper used to assess sensitivity to the Markov assumption. sim.mspdata is a deprecated alias.

Usage

sim_mspdata(process = NULL, n = 100L, t = 10, Q = NULL,
  schedule = c("regular", "random"), by = 1, visit_rate = 1.2,
  p_miss = 0, start_state = 1L, exact_absorption = FALSE,
  sojourn = c("exponential", "weibull"), shape = 1)

sim_semimarkov(process = NULL, n = 100L, t = 10, shape = 1, Q = NULL,
  schedule = c("regular", "random"), by = 1, visit_rate = 1.2,
  p_miss = 0, start_state = 1L)

sim.mspdata(...)

Arguments

process

Character. One of ms_structures(). May be NULL if Q is supplied.

n

Integer. Number of subjects.

t

Numeric. Length of the observation window.

Q

Optional user-supplied generator matrix, checked against the structural zeros of process when both are given.

schedule

"regular" for a common grid, or "random" for subject-specific visit times from a Poisson process.

by

Numeric. Spacing of the regular grid.

visit_rate

Numeric. Visit intensity for the random schedule.

p_miss

Numeric in [0, 1). Probability that a post-baseline visit is missed.

start_state

Integer state at time zero, or a vector of probabilities over states.

exact_absorption

Logical. Append the exact entry time into an absorbing state as an extra record.

sojourn

"exponential" for the Markov process, or "weibull" for a semi-Markov process.

shape

Weibull shape. The scale is calibrated so the mean holding time matches the Markov mean, so shape = 1 recovers the Markov process.

...

Passed to sim_mspdata.

Details

Trajectory generation and panel construction are kept separate: the state recorded at observation time u is the destination of the last jump at or before u. Discretising the process directly onto the observation grid shifts the implied holding-time distribution by up to one inter-visit interval and biases every leaving rate.

Value

A data frame with columns subject, time and state, one row per subject-visit, with the generating generator attached as attribute "Q".

See Also

fit_msm, ms_occupancy

Examples

dat <- sim_mspdata("illness_death_3state", n = 50, t = 10)
head(dat)

irr <- sim_mspdata("illness_death_3state", n = 50, t = 10,
                   schedule = "random", visit_rate = 1.2, p_miss = 0.2)
range(table(irr$subject))

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