msprep2: Converts long state entry data into a format suitable for...

Description Usage Arguments Details Value Examples

View source: R/msprep2.R

Description

This function performs the same role as msprep from the mstate package, except that it accepts long data (each row corresponds to a state entry) rather than the wide format used by msprep (each row represents an individual with state entry indicated in columns).

Usage

1
2
3
4
5
6
7
8
9
msprep2(
  entry,
  tmat,
  censors = NULL,
  start_times = NULL,
  start_states = NULL,
  covars = NULL,
  idcol = "id"
)

Arguments

entry

Long data frame of format id | state | time. State can either be character, with the same state names used in tmat, or integer where they refer to the rownumber of that state in tmat. Note that the state and time fields must be labelled this way.

tmat

Transition matrix in the standard format required by msprep.

censors

A long data frame with 2 columns, id and censor_time. Gives the last follow-up time for individuals that haven't entered a sink state.

start_times

A long data frame with 2 columns, id and start_time. Gives the time at which the patient entered the simulation. Defaults to 0.

start_states

A long data frame with 2 columns, id and start_state. Gives the state the patient entered the simulation in. Defaults to 1.

covars

Data frame where each row corresponds to an individual and details their covariate values. Must contain the id column specified in idcol alongside any covariate fields of interest.

idcol

The column that indexes these patients, must be present in entry and censors, start_times, start_states, and covars if supplied.

Details

The long data format required by msprep2 is a more natural way of organising state entry data than the wide format required by msprep. An additional benefit of having the state entries organised in this fashion is that it allows for the situation where an individual enters the same state multiple times, which is not supported by msprep.

Value

An object of class msdata, representing the transition data in long format.

Examples

1
2
3
4
5
6
7
8
9
 library(multistateutils)
 library(mstate)

 tmat <- trans.illdeath()
 entry <- data.frame(id=c(1, 2, 2),
                     state=c(2, 2, 3),
                     time=c(23, 35, 360))

 msprep2(entry, tmat)

stulacy/RDES documentation built on Feb. 14, 2021, 2:31 a.m.