Description Usage Arguments Value Author(s) Examples
View source: R/probsL1mstate.R
Compute subject-specific or overall transition probabilities.
1 | probs.l1mstate(object, longdt, tmat, predt, direction=c("forward","fixedhorizon"))
|
object |
fitted cumhaz.l1mstate object |
longdt |
long-format data input |
tmat |
a transition matrix for multi-state model |
predt |
a prediction time |
direction |
indicates whether prediction is forward or for a fixed horizon |
A list with each element [[s]] containing a data frame with the estimated transition probabilities from state s. It also includes transition and tmat information for plotting purpose
Xuan Dang xuandang11289@gmail.com
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | library(L1mstate)
set.seed(1001)
N <- 200
x1 <- rbinom(N, 1, .5)
x2 <- rbinom(N, 1, .5)
x3 <- rbinom(N, 1, .5)
x4 <- rbinom(N, 1, .5)
x5 <- rbinom(N, 1, .5)
x6 <- rbinom(N, 1, .5)
x <- data.frame(x1,x2,x3,x4,x5,x6)
col_names <- c(sprintf("X%d", seq(1,6)))
colnames(x) <- col_names
beta12 <- c(-.65,-.65,-.65,0,0,0)
beta13 <- c(-.65,0,0,0,-.65,0)
beta23 <- c(0,-.65,-.65,0,0,-.65)
N12 <- N-2*N%/%5
N13 <- N-N12
hx12 <- exp(as.matrix(x[1:N12,]) %*% beta12)
ty12 <- rexp(N12,hx12)
hx13 <- exp(as.matrix(x[(N12+1):N,]) %*% beta13)
ty13 <- rexp(N13,hx13)
hx23 <- exp(as.matrix(x[1:N12,]) %*% beta23)
ty23 <- rexp(N12,hx23)
t2 <- rep(0,N)
t2[1:N12] <- ty12
t2[(N12+1):N] <- ty13
s2 <- rep(0,N)
s2[1:N12] <- rep(1,N12)
t3 <- rep(0,N)
t3[1:N12] <- ty12+ty23
t3[(N12+1):N] <- ty13
#censor case for state 3
tcens3 <- rbinom(n=N, prob = 0.3, size = 1)
s3 <- 1-tcens3
# pre-process data into long-format using msprep
dt <- data.frame(illt=t2, ills=s2, dt=t3, ds=s3, x)
tmat <- matrix(c(NA,NA,NA,1,NA,NA,2,3,NA), nrow = 3)
longdt <- msprep(time=c(NA,"illt","dt"),status=c(NA,"ills","ds"),
keep = col_names, data=dt,trans=tmat)
out <- cv.l1mstateR(longdt, nlambda = 100, nfolds = 10)
ptsA <- longdt[which(longdt$X1==1 & longdt$X2==0 & longdt$X3==1 & longdt$X4==0
& longdt$X5==1 & longdt$X6==1),]
## observed transitions (ground truth)
# predicted time = 0
events(ptsA)
# use models to predict the transition probabilities
# L1MSTATE
ptA <- ptsA[which(ptsA$id == unique(ptsA$id)[1]),]
ptA <- ptA[,c(4,9:14)]
cumhazA <- cumhaz.l1mstate(object=out, longdt=longdt, newdata=ptA, cv.method="pcvl")
probA_0 <- probs.l1mstate(cumhazA, longdt = longdt, tmat, predt = 0, direction = "forward")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.