msmjson | R Documentation |
Function msmjson can receive models from msm package. It then uses functions from msm package internally to estimate multi-state model measures such as transition probabilities, transition intensity rates, length of stay, probability of visiting each state probability each state is next, sojoutn times and confidence intervals of the estimations. Function flexjson then take these results and reshapes them so that they can be fed to MSMplus properly as a json file.
msmjson(
msm.model,
vartime = seq(1, 1, 1),
mat.init,
totlos = FALSE,
visit = FALSE,
sojourn = FALSE,
pnext = FALSE,
efpt = FALSE,
envisits = FALSE,
ci.json = "normal",
cl.json = 0.95,
B.json = 50,
cores.json = NULL,
piecewise.times.json = NULL,
piecewise.covariates.json = NULL,
num.integ.json = FALSE,
covariates_list = list(),
jsonpath = "",
name = "predictions_R.json"
)
msm.model |
A fitted multi-state model, as returned by msm. |
vartime |
The time points to estimate the transition probabilities for, by default one unit. |
mat.init |
A transition intensity matrix. Default: NULL |
totlos |
Estimate the total length of stay in each state for the time points specified by vartime argument, Default: "FALSE" |
visit |
Estimate the probability of visiting each state for the time points specified by vartime argument, Default: "FALSE" |
sojourn |
Estimate the mean sojourn time in each state, Default: "FALSE" |
pnext |
Estimate the probability that each state is next, Default: "FALSE" |
efpt |
Estimate the expected first passage time by each state, Default: "FALSE" |
envisits |
Estimate the number of visits in each state , Default: "FALSE" |
ci.json |
Estimate confidence intervals, Default: 'normal' |
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: 50 |
cores.json |
Number of cores to use for bootstrapping using parallel processing. See boot.msm for more details., Default: NULL |
piecewise.times.json |
Times at which piecewise-constant intensities change. See pmatrix.piecewise.msm for how to specify this. This is only required for time-inhomogeneous models specified using explicit time-dependent covariates, and should not be used for models specified using "pci"., Default: NULL |
piecewise.covariates.json |
Covariates on which the piecewise-constant intensities depend. See pmatrix.piecewise.msm for how to specify this., Default: NULL |
num.integ.json |
Use numerical integration instead of analytic solution (see below). |
covariates_list |
The user can specify different covariate patterns for which predictions will be made, Default: list() |
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
returns a list of objects: the time variable the number of covariate patterns, the names of covariate patterns, the transition matrix, the number of transitions, the transition probabilities, transition intensity rates, length of stay, probability of visiting each state probability each state is next, sojoutn times and confidence intervals of the estimations(if estimated).
stri_sort
## Not run:
#Example
# Multi-state model analysis: Using msmjson function together with msm package
library("MSMplus")
library("msm")
library("dplyr")
options(scipen = 999,"digits"=10)
head(cav)
### Renaming variable PTNUM to id
cav$id=cav$PTNUM
### Defining the transition matrix
tmat=matrix(NA,nrow=4,ncol=4)
tmat[1,2]=1; tmat[1,4]=2; tmat[2,1]=3; tmat[2,3]=4
tmat[2,4]=5; tmat[3,2]=6; tmat[3,4]=7
### We can now call function msboxes_R
results3_days=MSMplus::msboxes_R(data=cav,id= cav$id, yb=c(0.3,0.5,0.6,0.75), msm=TRUE,
xb=c(0.5,0.2,0.7,0.3),boxwidth=0.1,boxheight=0.1,
tmatrix= tmat, vartime=seq(0,10,by=1),scale=1,
jsonpath="", name="msboxes_cav_R.json" )
### Defining the transition matrix with initial values under an initial assumption
#0 for transitions not allowed, initial values for rest of transitions under a rationale ##
Q<- rbind(c(0,0.25,0,0.25),c(0.166,0,0.166,0.166),c(0,0.25,0,0.25),c(0,0,0,0))
### Getting initial Q matrix in a default way- Feed the hand made matrix
q.crude<- crudeinits.msm(state~years, id,data=cav, qmatrix=Q)
### Apply the msm model
cavsex.msm<- msm(state~years, covariates=~sex, id,data=cav,qmatrix=q.crude, deathexact = 4, control=list(trace=1,REPORT=1))
summary(cavsex.msm)
### Prediction for different covariate patterns (males and females)
results <- MSMplus::msmjson(msm.model=cavsex.msm, vartime=seq(1,3,1), mat.init=q.crude,
totlos=TRUE, visit=TRUE, sojourn=TRUE, pnext=TRUE, efpt=TRUE, envisits=TRUE,
ci.json="normal", cl.json=0.95, B.json=100,
cores.json=NULL,piecewise.times.json=NULL, piecewise.covariates.json=NULL,num.integ.json=FALSE,
covariates_list=list(list(sex = 1),list(sex = 0)),
jsonpath="",
name="predictions_cav_R.json" )
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.