Learn R Programming

msm (version 0.7.6)

boot.msm: Bootstrap resampling for multi-state models

Description

Draw a number of bootstrap resamples, refit a msm model to the resamples, and calculate statistics on the refitted models.

Usage

boot.msm(x, stat=pmatrix.msm, B=1000, file=NULL)

Arguments

x
A fitted msm model, as output by msm.
stat
A function to call on each refitted msm model. By default this is pmatrix.msm, returning the transition probability matrix in one time unit. If NULL then no function is computed
B
Number of bootstrap resamples.
file
Name of a file in which to save partial results after each replicate. This is saved using save and can be restored using load, producing an object called

Value

  • A list with B components, containing the result of calling function stat on each of the refitted models. If stat is NULL, then each component just contains the refitted model. If one of the B model fits was unsuccessful and resulted in an error, then the corresponding list component will contain the error message.

Details

The bootstrap datasets are computed by resampling independent transitions between pairs of states (for non-hidden models without censoring), or independent patient series (for hidden models or models with censoring). Therefore this approach doesn't work if, for example, the data for a HMM consist of a series of observations from just one individual.

Confidence intervals or standard errors for the corresponding statistic can be calculated by summarising the returned list of B replicated outputs. This is currently implemented for the transition probability matrix and total length of stay, see pmatrix.msm, totlos.msm. At the moment, for other outputs, users will have to write their own code to summarise the output of boot.msm.

Most of msm's output functions present confidence intervals based on asymptotic standard errors calculated from the Hessian. These are expected to be underestimates of the true standard errors (Cramer-Rao lower bound). Bootstrapping may give a more accurate estimate of the uncertainty. All objects used in the original call to msm which produced x, such as the qmatrix, should be in the working environment, or else boot.msm will produce an object not found error. This enables boot.msm to refit the original model to the replicate datasets. If stat is NULL, then B different msm model objects will be stored in memory. This is unadvisable, as msm objects tend to be large, since they contain the original data used for the msm fit, so this will be wasteful of memory.

To specify more than one statistic, write a function consisting of a list of different function calls, for example,

stat = function(x) list (pmatrix.msm(x, t=1), pmatrix.msm(x, t=2))

References

Efron, B. and Tibshirani, R.J. (1993) An Introduction to the Bootstrap, Chapman and Hall.

See Also

qmatrix.msm, qratio.msm, sojourn.msm, ematrix.msm, pmatrix.msm, pmatrix.piecewise.msm, totlos.msm, prevalence.msm.

Examples

Run this code
## Psoriatic arthritis example 
  data(psor)
  psor.q <- rbind(c(0,0.1,0,0),c(0,0,0.1,0),c(0,0,0,0.1),c(0,0,0,0))
  psor.msm <- msm(state ~ months, subject=ptnum, data=psor, qmatrix = psor.q, covariates = ~ollwsdrt+hieffusn, constraint = list(hieffusn=c(1,1,1),ollwsdrt=c(1,1,2)), control = list(REPORT=1,trace=2), method="BFGS")
  ## Bootstrap the baseline transition intensity matrix.  This will take a long time. 
  q.list <- boot.msm(psor.msm, function(x)x$Qmatrices$baseline)
  ## Manipulate the resulting list of matrices to calculate bootstrap standard errors. 
  apply(array(unlist(q.list), dim=c(4,4,5)), c(1,2), sd)
  ## Similarly calculate a bootstrap 95% confidence interval
  apply(array(unlist(q.list), dim=c(4,4,5)), c(1,2), function(x)quantile(x, c(0.025, 0.975)))
  ## Bootstrap standard errors are larger than the asymptotic standard errors calculated from the Hessian
  psor.msm$QmatricesSE$baseline

Run the code above in your browser using DataLab