prevplot: Plot observed and expected prevalences for a multi-state...

Description Usage Arguments Details Author(s) References See Also Examples

View source: R/prevplot.R

Description

Provides a graphical indication of goodness of fit of a multi-state model computed by msm using observed and expected prevalences. It also computes a rough indicator of where the data depart from the fitted Markov model.

Usage

1
2
3
4
5
6
7
prevplot(x, prev.obj, M = FALSE, exacttimes = TRUE, ci = FALSE,
  grid = 100L, x.lab.grid = 500L, xlab = "Time",
  ylab = "Prevalence (%)", lty.fit = 1, lwd.fit = 1, col.fit = "red",
  lty.ci.fit = 2, lwd.ci.fit = 1, col.ci.fit = col.fit, lwd.obs = 1,
  lty.obs = 1, col.obs = "darkblue", legend.pos = "topright",
  par.col = 3, plot.width = 10, plot.height = 5, max.m = 0.1,
  devnew = TRUE, verbose = TRUE)

Arguments

x

A msm object.

prev.obj

A list computed by prevalence.msm. It can be with or without confidence intervals. prevplot will behaves accordingly.

M

If TRUE, then a rough indicator of deviance from the model is computed (see 'Details'). Default is FALSE.

exacttimes

If TRUE (default) then transition times are known and exact. This is inherited from msm and should be set the same way.

ci

If TRUE, then confidence intervals, if they exist, are plotted. Default is FALSE.

grid

Define how many points should be used to build the x axis. Defaul is 100.

x.lab.grid

Define the interval on the x axis at which draw tick marks. Default is 500.

xlab

x axis label.

ylab

y axis label.

lty.fit

Line type for the expected prevalences. See par.

lwd.fit

Line width for the expected prevalences. See par.

col.fit

Line color for the expected prevalences. See par.

lty.ci.fit

Line type for the expected prevalences confidence limits. See par.

lwd.ci.fit

Line width for the expected prevalences confidence limits. See par.

col.ci.fit

Line color for the expected prevalences confidence limits. See par.

lwd.obs

Line width for the observed prevalences. See par.

lty.obs

Line type for the observed prevalences. See par.

col.obs

Line color for the observed prevalences. See par.

legend.pos

Where to position the legend. Default is "topright", but x and y coordinate can be passed. If NULL, then legend is not shown.

par.col

The number of columns of the plot. Default is 3.

plot.width

Width of new graphical device. Default is 7. See par.

plot.height

Height of new graphical device. Default is 7. See par.

max.m

If M = TRUE, it adjusts the upper y limit when plotting M.

devnew

Set the graphical device where to plot. By default, prevplot plots on a new device by setting dev.new. If FALSE, then a plot is drawn onto the current device as specified by dev.cur. If FALSE and no external devices are opened, then a plot is drawn using internal graphics. See dev.

verbose

If FALSE, all information produced by print, cat and message are suppressed. Default is TRUE.

Details

When M = TRUE, a rough indicator of the deviance from the Markov model is computed according to Titman and Sharples (2008). A comparison at a given time t_i of a patient k in the state s between observed counts O_{is} with expected ones E_{is} is build as follows:

(O_{is} - E_{is})^2 / E_{is}

Author(s)

Francesco Grossetti francesco.grossetti@unibocconi.it.

References

Titman, A. and Sharples, L.D. (2010). Model diagnostics for multi-state models, Statistical Methods in Medical Research, 19, 621-651.

Titman, A. and Sharples, L.D. (2008). A general goodness-of-fit test for Markov and hidden Markov models, Statistics in Medicine, 27, 2177-2195.

Gentleman RC, Lawless JF, Lindsey JC, Yan P. (1994). Multi-state Markov models for analysing incomplete disease data with illustrations for HIV disease. Statistics in Medicine, 13:805-821.

Jackson, C.H. (2011). Multi-State Models for Panel Data:
The msm Package for R. Journal of Statistical Software, 38(8), 1-29.
URL http://www.jstatsoft.org/v38/i08/.

See Also

plot.prevalence.msm msm prevalence.msm

Examples

 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
## 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 ) )

# defining the times at which compute the prevalences
t_min = min( hosp_augmented$augmented_int )
t_max = max( hosp_augmented$augmented_int )
steps = 100L

# computing prevalences
prev = prevalence.msm( msm_model, covariates = 'mean', ci = 'normal',
                       times = seq( t_min, t_max, steps ) )

# and plotting them using prevplot()
prevplot( msm_model, prev, ci = TRUE, devnew = FALSE, verbose = FALSE )

## End(Not run)

contefranz/msmtools documentation built on May 13, 2019, 10:50 p.m.