Calculate a confidence interval for a model output by repeatedly replacing the parameters in a fitted model object with a draw from the multivariate normal distribution of the maximum likelihood estimates, then recalculating the output function.
bootci.fmsm( x, B, fn, cl = 0.95, attrs = NULL, cores = NULL, sample = FALSE, ... )
x | Output from |
---|---|
B | Number of parameter draws to use |
fn | Function to bootstrap the results of. It must have an argument named `codex giving a fitted flexsurv model object. This may return a value with any format, e.g. list, matrix or vector, as long as it can be converted to a numeric vector with |
cl | Width of symmetric confidence interval, by default 0.95 |
attrs | Any attributes of the value returned from |
cores | Number of cores to use for parallel processing. |
sample | If |
... | Additional arguments to pass to |
A matrix with two rows, giving the upper and lower confidence limits respectively. Each row is a vector of the same length as the unlisted result of the function corresponding to fncall
.
## How to use bootci.msm ## Write a function with one argument called x giving a fitted model, ## and returning some results of the model. The results may be in any form. tmat <- rbind(c(NA,1,2),c(NA,NA,3),c(NA,NA,NA)) bexp <- flexsurvreg(Surv(Tstart, Tstop, status) ~ trans, data=bosms3, dist="exp") summfn <- function(x, t){ resp <- pmatrix.fs(x, trans=tmat, t=t) rest <- totlos.fs(x, trans=tmat, t=t) list(resp, rest) } ## Use bootci.msm to obtain the confidence interval ## The matrix columns are in the order of the unlisted results of the original ## summfn. You will have to rearrange them into the format that you want. ## If summfn has any extra arguments, in this case \code{t}, make sure they are ## passed through via the ... argument to bootci.fmsm bootci.fmsm(bexp, B=3, fn=summfn, t=10)#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] #> 2.5% 0.06967108 0 0 0.1538312 0.08214595 0 0.7178206 0.8660887 1 #> 97.5% 0.10204690 0 0 0.1936701 0.13391131 0 0.7757457 0.9178541 1 #> [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] #> 2.5% 3.491438 0 0 2.166812 3.671630 0 3.892823 5.693384 10 #> 97.5% 3.934041 0 0 2.342600 4.306616 0 4.279784 6.328370 10bootci.fmsm(bexp, B=3, fn=summfn, t=5)#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] #> 2.5% 0.2628198 0 0 0.2708368 0.2458269 0 0.4067587 0.6799882 1 #> 97.5% 0.2838817 0 0 0.3123221 0.3200118 0 0.4661788 0.7541731 1 #> [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] #> 2.5% 2.758261 0 0 1.129070 2.687109 0 0.9518442 2.016127 5 #> 97.5% 2.843546 0 0 1.216438 2.983873 0 1.1120121 2.312891 5