simMarkovOrd {Hmisc}  R Documentation 
simMarkovOrd
Description
Simulate Ordinal Markov Process
Usage
simMarkovOrd(
n = 1,
y,
times,
initial,
X = NULL,
absorb = NULL,
intercepts,
g,
carry = FALSE,
rdsample = NULL,
...
)
Arguments
n 
number of subjects to simulate

y 
vector of possible y values in order (numeric, character, factor)

times 
vector of measurement times

initial 
initial value of y (baseline state; numeric, character, or factor matching y ). If length 1 this value is used for all subjects, otherwise it is a vector of length n .

X 
an optional vector of matrix of baseline covariate values passed to g . If a vector, X represents a set of single values for all the covariates and those values are used for every subject. Otherwise X is a matrix with rows corresponding to subjects and columns corresponding to covariates which g must know how to handle. g only sees one row of X at a time.

absorb 
vector of absorbing states, a subset of y (numeric, character, or factor matching y ). The default is no absorbing states. Observations are truncated when an absorbing state is simulated.

intercepts 
vector of intercepts in the proportional odds model. There must be one fewer of these than the length of y .

g 
a userspecified function of three or more arguments which in order are yprev  the value of y at the previous time, the current time t , the gap between the previous time and the current time, an optional (usually named) covariate vector X , and optional arguments such as a regression coefficient value to simulate from. The function needs to allow yprev to be a vector and yprev must not include any absorbing states. The g function returns the linear predictor for the proportional odds model aside from intercepts . The returned value must be a matrix with row names taken from yprev . If the model is a proportional odds model, the returned value must be one column. If it is a partial proportional odds model, the value must have one column for each distinct value of the response variable Y after the first one, with the levels of Y used as optional column names. So columns correspond to intercepts . The different columns are used for y specific contributions to the linear predictor (aside from intercepts ) for a partial or constrained partial proportional odds model. Parameters for partial proportional odds effects may be included in the ... arguments.

carry 
set to TRUE to carry absorbing state forward after it is first hit; the default is to end records for the subject once the absorbing state is hit

rdsample 
an optional function to do responsedependent sampling. It is a function of these arguments, which are vectors that stop at any absorbing state: times (ascending measurement times for one subject), y (vector of ordinal outcomes at these times for one subject. The function returns NULL if no observations are to be dropped, returns the vector of new times to sample.

... 
additional arguments to pass to g such as a regresson coefficient

Details
Simulates longitudinal data for subjects following a firstorder Markov process under a proportional odds model. Optionally, responsedependent sampling can be done, e.g., if a subject hits a specified state at time t, measurements are removed for times t+1, t+3, t+5, ... This is applicable when for example a study of hospitalized patients samples every day, Y=1 denotes patient discharge to home, and sampling is less frequent outside the hospital. This example assumes that arriving home is not an absorbing state, i.e., a patient could return to the hospital.
Value
data frame with one row per subject per time, and columns id, time, yprev, y, values in ...
Author(s)
Frank Harrell
See Also
https://hbiostat.org/R/Hmisc/markov/
[Package
Hmisc version 5.13
Index]