Description Usage Arguments Details Value Author(s) References See Also Examples
Plot a KaplanMeier curve and compare it with the fitted survival probability
computed from a msm
model. Fast builds and returns the
associated datasets.
1 2 3 4 5 6 7 8 9 10  survplot(x, from = 1, to = NULL, range = NULL, covariates = "mean",
exacttimes = TRUE, times, grid = 100L, km = FALSE, return.all = FALSE,
return.km = NULL, return.p = NULL, convert = FALSE, add = FALSE,
ci = c("none", "normal", "bootstrap"), interp = c("start", "midpoint"),
B = 100L, legend.pos = "topright", xlab = "Time",
ylab = "Survival Probability", main = NULL, lty.fit = 1, lwd.fit = 1,
col.fit = "red", lty.ci.fit = 3, lwd.ci.fit = 1, col.ci.fit = col.fit,
mark.time = FALSE, lty.km = 5, lwd.km = 1, col.km = "darkblue",
do.plot = TRUE, plot.width = 7, plot.height = 7, devnew = TRUE,
verbose = TRUE)

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 which tells at how many points to compute the fitted
survival (see 'Details').
If 
km 
If 
return.all 
If 
return.km 
If 
return.p 
If 
convert 
If 
add 
If 
ci 
If 
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. 
legend.pos 
Where to position the legend. Default is 
xlab 
x axis label. 
ylab 
y axis label. 
main 
The main title of the plot(s) as character. Default is 
lty.fit 
Line type for the fitted curve. See 
lwd.fit 
Line width for the fitted curve. See 
col.fit 
Line color for the fitted curve. See 
lty.ci.fit 
Line type for the fitted curve confidence limits.
See 
lwd.ci.fit 
Line width for the fitted curve confidence limits.
See 
col.ci.fit 
Line color for the fitted curve confidence limits.
See 
mark.time 
Mark the empirical survival curve at each censoring point.
See 
lty.km 
Line type for the KaplanMeier passed to

lwd.km 
Line width for the KaplanMeier passed to

col.km 
Line color for the KaplanMeier passed to

do.plot 
If 
plot.width 
Width of new graphical device. Default is 7.
See 
plot.height 
Height of new graphical device. Default is 7.
See 
devnew 
Set the graphical device where to plot. By default,

verbose 
If 
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 fastly
build and return to the user the datasets used to compute the KaplanMeier
and the fitted survival by setting return.all = TRUE
. When this is
TRUE
, setting return.km
or return.p
to FALSE
produces an error and survplot
does not conclude the job. If these
are set to TRUE
, a warning is raised but the job is taken
to the end. For more details about how survplot
returns objects,
please refer to the vignette with vignette("msmtools")
.
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.
If return.all
is set to TRUE
, then survplot
returns a named list with $km
and $fitted
as data.table
or as data.frame
when convert = TRUE
. To save them in the
working environment, assign survplot
to an object (see 'Examples').
$km
contains up to 4 columns:

The ordered subject ID as passed in the 

The times at which to compute the fitted survival. 

If 

State of transition to compute the KaplanMeier. 
——
$fitted
contains 2 columns:

Times at which to compute the fitted survival. 

The corresponding values of the fitted survival. 
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 http://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 34 35 36 37 38 39 40 41 42  ## 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
survplot( msm_model, km = TRUE, ci = 'none',
verbose = FALSE )
# plotting the fitted and empirical survival from state = 2 and
# adding it to the previous plot
survplot( msm_model, from = 2, km = TRUE, ci = 'none', add = TRUE,
verbose = FALSE )
# returning fitted and empirical data
all_data = survplot( msm_model, ci = 'none', return.all = TRUE,
verbose = FALSE, do.plot = FALSE )
# saving them separately
km_data = all_data[[ 1 ]]
fitted_data = all_data[[ 2 ]]
## End(Not run)

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