remove_redundant_observations {icmstate} | R Documentation |
Remove redundant observations from supplied data frame
Description
Remove redundant observed states from a supplied data frame. Observations are redundant either when we observe an absorbing state multiple times (as we cannot leave an absorbing state), or when a transient state is observed multiple times between transitions (as we cannot have loops, therefore no extra information is provided when we observe a transient state multiple times).
Usage
remove_redundant_observations(gd, tmat)
Arguments
gd |
A
The true transition time between states is then interval censored between the times. |
tmat |
A transition matrix as created by |
Value
A data.frame
containing the information contained in the
input data.frame
gd
,
but without redundant observations. Depending on whether tmat
was
specified the function may remove more observations.
Examples
#We simulate some data
#Function to generate evaluation times: at 0 and uniform inter-observation
eval_times <- function(n_obs, stop_time){
cumsum( c( 0, runif( n_obs-1, 0, 2*(stop_time-4)/(n_obs-1) ) ) )
}
#Simulate illness-death model data with Weibull transitions
sim_dat <- sim_id_weib(n = 20, n_obs = 6, stop_time = 15, eval_times = eval_times,
start_state = "stable", shape = c(0.5, 0.5, 2),
scale = c(5, 10, 10/gamma(1.5)))
visualise_msm(sim_dat)
require(mstate)
sim_dat_clean <- remove_redundant_observations(sim_dat, trans.illdeath())
visualise_msm(sim_dat_clean)