mstatejson | R Documentation |
Function mstatejson can receive models from mstate package. It then uses functions from mstate package internally to estimate multi-state model measures such as transition probabilities, length of stay, and confidence intervals of the estimations. Function mstatejson then take these results and reshapes them so that they can be fed to MSMplus properly as a json file.
mstatejson(
x,
qmat,
process = "Markov",
totlos = FALSE,
ci.json = FALSE,
cl.json = 0.95,
B.json = 10,
variance = FALSE,
vartype = "aalen",
covariates_list = list(),
Mjson = 50,
jsonpath = "",
name = "predictions.json"
)
x |
The hazard model (or list of hazard models) |
qmat |
he user has to supply the transition matrix |
process |
"Markov" for clock forward approach, "semiMarkov" for clock reset approach, Default: 'Markov' |
totlos |
Estimate total length of stay spent in each state "TRUE", "FALSE", Default: "FALSE" |
ci.json |
Estimate confidence intervals, "TRUE", "FALSE", Default: "FALSE" |
cl.json |
Specify confidence level, Default: 0.95 |
B.json |
Number of simulations from the normal asymptotic distribution used to calculate variances. Decrease for greater speed at the expense of accuracy, Default: 100 |
variance |
A logical value indicating whether the (co-)variances of the subject-specific transition hazards should be computed. Default is FALSE |
vartype |
A character string specifying the type of variances to be computed (so only needed if variance=TRUE). Possible values are "aalen" or "greenwood" |
covariates_list |
The user can specify different covariate patterns for which predictions will be made, Default: list() |
Mjson |
Number of individuals to simulate in order to approximate the transition probabilities. Users should adjust this to obtain the required precision. Default: 100 |
jsonpath |
specify the path of the folder that the json file should be saved, Default: "" saves the json file to the current working directory |
name |
Specify the name of the output json file, Default: 'predictions.json' |
DETAILS
OUTPUT_DESCRIPTION
stri_sort
## Not run:
#EXAMPLE
library("MSMplus")
library("survival")
library("mstate")
library("dplyr")
head(ebmt)
### Let's first define the transition matrix
tmat <- transMat(x = list(c(2, 3),c(3), c() ), names = c("Transplant", "Platelet Recovery", "Relapse/Death" ) )
### We will now create dummy variables for the age categories
ebmt$age2= recode(ebmt$age, ">40" =0, "20-40"=1,"<=20" =0 )
ebmt$age3= recode(ebmt$age, ">40" =1, "20-40"=0,"<=20" =0 )
#Data preparation- From one row per participant to multiple rows per participant, one for each allowed transition.
msebmt <- msprep(data = ebmt, trans = tmat,
time = c(NA, "prtime", "rfstime"), status = c(NA, "prstat", "rfsstat"), keep=c("age2","age3"))
### Semi parametric analysis
#### Markov
### Run the hazard models: Clock forward approach
cfcox <- coxph(Surv(Tstart, Tstop, status) ~age2+age3+strata(trans), data = msebmt)
### Prediction for different covariate patterns (the 3 age categories)
wh1 <- which(msebmt$age2 == 0 & msebmt$age3 == 0)
pat1 <- msebmt[rep(wh1[1], 3), 9:10]
pat1$trans <- 1:3
attr(pat1, "trans") <- tmat
pat1$strata <- pat1$trans
wh2 <- which(msebmt$age2 == 1 & msebmt$age3 == 0)
pat2 <- msebmt[rep(wh2[1], 3), 9:10]
pat2$trans <- 1:3
attr(pat2, "trans") <- tmat
pat2$strata <- pat2$trans
wh3 <- which(msebmt$age2 == 0 & msebmt$age3 == 1)
pat3 <- msebmt[rep(wh3[1], 3), 9:10]
pat3$trans <- 1:3
attr(pat3, "trans") <- tmat
pat3$strata <- pat3$trans
##We now run the mstatejson function to perform the multi-state model analysis using the function
##from package mstate and the pack the predictions in a json file.
results_semipar <- MSMplus::mstatejson(x=cfcox, qmat=tmat, process="Markov",
totlos=TRUE, ci.json=TRUE, cl.json=0.95, B.json=10,
variance=FALSE, vartype="greenwood",
covariates_list=list(pat1 ,pat2, pat3 ) , Mjson=50,
jsonpath="",
name="predictions_EBMT_mstate_fw.json")
results_semipar
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.