simMarkovOrd
simMarkovOrd.RdSimulate 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 matchingy). If length 1 this value is used for all subjects, otherwise it is a vector of lengthn.- X
an optional vector of matrix of baseline covariate values passed to
g. If a vector,Xrepresents a set of single values for all the covariates and those values are used for every subject. OtherwiseXis a matrix with rows corresponding to subjects and columns corresponding to covariates whichgmust know how to handle.gonly sees one row ofXat a time.- absorb
vector of absorbing states, a subset of
y(numeric, character, or factor matchingy). 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 user-specified function of three or more arguments which in order are
yprev- the value ofyat the previous time, the current timet, thegapbetween the previous time and the current time, an optional (usually named) covariate vectorX, and optional arguments such as a regression coefficient value to simulate from. The function needs to allowyprevto be a vector andyprevmust not include any absorbing states. Thegfunction returns the linear predictor for the proportional odds model aside fromintercepts. The returned value must be a matrix with row names taken fromyprev. 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 tointercepts. The different columns are used fory-specific contributions to the linear predictor (aside fromintercepts) for a partial or constrained partial proportional odds model. Parameters for partial proportional odds effects may be included in the ... arguments.- carry
set to
TRUEto 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 response-dependent 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 returnsNULLif no observations are to be dropped, returns the vector of new times to sample.- ...
additional arguments to pass to
gsuch as a regresson coefficient
Details
Simulates longitudinal data for subjects following a first-order Markov process under a proportional odds model. Optionally, response-dependent 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.