Description Usage Arguments Details Value Author(s) References See Also Examples
Plot the fitted survival probability computed over a msm
model and
compare it with the KaplanMeier. Fast build and return the underlying data structures.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  survplot(
x,
from = 1,
to = NULL,
range = NULL,
covariates = "mean",
exacttimes = TRUE,
times,
grid = 100L,
km = FALSE,
out = c("none", "fitted", "km", "all"),
ci = c("none", "normal", "bootstrap"),
interp = c("start", "midpoint"),
B = 100L,
ci_km = c("none", "plain", "log", "loglog", "logit", "arcsin")
)

x 
A 
from 
State from which to compute the estimated survival. Default to state 1. 
to 
The absorbing state to which compute the estimated survival.
Default to the highest state found by 
range 
A numeric vector of two elements which gives the time range of the plot. 
covariates 
Covariate values for which to evaluate the expected
probabilities. These can either be: the string 
exacttimes 
If 
times 
An optional numeric vector giving the times at which to compute the fitted survival. 
grid 
An integer specifying the grid points at which to compute the fitted
survival (see 'Details').
If 
km 
If 
out 
A character vector specifying what the function has to return. Accepted values are

ci 
A character vector with the type of confidence intervals to compute for the fitted
survival curve. Specify either 
interp 
If 
B 
Number of bootstrap or normal replicates for the confidence interval. The default is 100 rather than the usual 1000, since these plots are for rough diagnostic purposes. 
ci_km 
A character vector with the type of confidence intervals to compute for the
KaplanMeier curve. Specify either 
The function is a wrapper of plot.survfit.msm
and does more things. survplot
manages correctly the plot of a fitted
survival in an exact times framework (when exacttimes = TRUE
) by just
resetting the time scale and looking at the followup time. It can quickly
build and return to the user the data structures used to compute the KaplanMeier
and the fitted survival probability by specifying out = "all"
.
The user can defined custom times (through times
) or let
survplot
choose them on its own (through grid
).
In the latter case, survplot
looks for the followup time and divides
it by grid
. The higher it is, the finer the grid will be so that computing
the fitted survival will take longer, but will be more precise.
When out = "none"
, a gg/ggplot
object is returned. If out
is anything
else, then a named list is returned. The KaplanMeier data can be accessed with $km
while
the estimated survival data with $fitted
. If out = "all"
, the plot, the KaplanMeier
and the estimated curve are returned.
Francesco Grossetti francesco.grossetti@unibocconi.it.
Titman, A. and Sharples, L.D. (2010). Model diagnostics for
multistate models, Statistical Methods in Medical Research, 19,
621651.
Titman, A. and Sharples, L.D. (2008). A general goodnessoffit test for
Markov and hidden Markov models, Statistics in Medicine, 27,
21772195.
Jackson, C.H. (2011). MultiState Models for Panel Data:
The msm Package for R. Journal of Statistical Software, 38(8), 129.
URL https://www.jstatsoft.org/v38/i08/.
plot.survfit.msm
msm
,
pmatrix.msm
, setDF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  ## Not run:
data( hosp )
# augmenting the data
hosp_augmented = augment( data = hosp, data_key = subj, n_events = adm_number,
pattern = label_3, t_start = dateIN, t_end = dateOUT,
t_cens = dateCENS )
# let's define the initial transition matrix for our model
Qmat = matrix( data = 0, nrow = 3, ncol = 3, byrow = TRUE )
Qmat[ 1, 1:3 ] = 1
Qmat[ 2, 1:3 ] = 1
colnames( Qmat ) = c( 'IN', 'OUT', 'DEAD' )
rownames( Qmat ) = c( 'IN', 'OUT', 'DEAD' )
# attaching the msm package and running the model using
# gender and age as covariates
library( msm )
msm_model = msm( status_num ~ augmented_int, subject = subj,
data = hosp_augmented, covariates = ~ gender + age,
exacttimes = TRUE, gen.inits = TRUE, qmatrix = Qmat,
method = 'BFGS', control = list( fnscale = 6e+05, trace = 0,
REPORT = 1, maxit = 10000 ) )
# plotting the fitted and empirical survival from state = 1
theplot = survplot( x = msm_model, km = TRUE )
# plotting the fitted and empirical survival from state = 2 and
and returning both the fitted and the empirical curve
out_all = survplot( msm_model, from = 2, km = TRUE, out = "all" )
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.