sim.cif: Simulation of output from Cumulative incidence regression...

Description Usage Arguments Author(s) Examples

View source: R/sim-pc-hazard.r

Description

Simulates data that looks like fit from fitted cumulative incidence model

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## S3 method for class 'cif'
sim(
  cif,
  n,
  data = NULL,
  Z = NULL,
  drawZ = TRUE,
  cens = NULL,
  rrc = NULL,
  cumstart = c(0, 0),
  ...
)

Arguments

cif

output form prop.odds.subdist or ccr (cmprsk), can also call invsubdist with with cumulative and linear predictor

n

number of simulations.

data

to extract covariates for simulations (draws from observed covariates).

Z

to use these covariates for simulation rather than drawing new ones.

drawZ

to random sample from Z or not

cens

specifies censoring model, if "is.matrix" then uses cumulative hazard given, if "is.scalar" then uses rate for exponential, and if not given then takes average rate of in simulated data from cox model.

rrc

possible vector of relative risk for cox-type censoring.

cumstart

to start cumulatives at time 0 in 0.

...

arguments for invsubdist

Author(s)

Thomas Scheike

Examples

  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
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
data(TRACE)

## Logit link for proportional odds model, using comp.risk to save time 
#' cif <-  prop.odds.subdist(Event(time,status)~vf+chf+wmi,data=TRACE,cause=9)
cif <-  comp.risk(Event(time,status)~const(vf)+const(chf)+const(wmi),
                  data=TRACE,cause=9,model="logistic2")
sim1 <- sim.cif(cif,500,data=TRACE)
#' cc <-  prop.odds.subdist(Event(time,status)~vf+chf+wmi,data=sim1,cause=1)
cc <-  comp.risk(Event(time,status)~const(vf)+const(chf)+const(wmi),
                  data=sim1,cause=1,model="logistic2")
cbind(cif$gamma,cc$gamma)

plot(cif) 
lines(cc$cum)

#################################################################
## Fine-Gray model model, using comp.risk to avoid dependcies
#################################################################
cif <-  comp.risk(Event(time,status)~const(vf)+const(chf)+const(wmi),
                  data=TRACE,cause=9)
sim1 <- sim.cif(cif,500,data=TRACE)
#' cc <-  crr 
cc <-  comp.risk(Event(time,status)~const(vf)+const(chf)+const(wmi),
                  data=sim1,cause=1)
cbind(cif$gamma,cc$gamma)
plot(cif) 
lines(cc$cum)

# faster/better with  mets package 
# library(mets)
# scif <-  cifreg(Event(time,status)~vf+chf+wmi,data=sim1,cause=1,prop=NULL)
#   
# plot(scif$cum,type="l")
# lines(cif$cum,col=2)
# cbind(cif$gamma,scif$coef)
# 
################################################################
#  simulating several causes with specific cumulatives 
################################################################
data(bmt)
cif1 <-  comp.risk(Event(time,cause)~const(tcell)+const(age),
                  data=bmt,cause=1,model="logistic2")
cif2 <-  comp.risk(Event(time,cause)~const(tcell)+const(age),
                  data=bmt,cause=2,model="logistic2")

## must look at same time-scale
cifs <- pre.cifs(list(cif1,cif2))
plot(cifs[[1]]$cum,type="l")
lines(cifs[[2]]$cum,col=2)
legend("topleft",c("cause1","cause2"),lty=1,col=1:2)

 n <- 500
 sim1 <- sim.cif(cifs[[1]],n,data=bmt)
 Z <- sim1[,c("tcell","age")]
 sim2 <- sim.cif(cifs[[2]],n,data=bmt,Z=Z,drawZ=FALSE)
 ###
 rt <- rbinom(n,1,(sim1$F1tau+sim2$F1tau))
 rb <- rbinom(n,1,sim1$F1tau/(sim1$F1tau+sim2$F1tau))
 cause=ifelse(rb==1,1,2)
 time=ifelse(cause==1,sim1$timecause,sim2$timecause)
 cause <- rt*cause
 time[cause==0] <- tail(cifs[[1]]$cum[,1],1)

 bt <- data.frame(time=time,cause=cause,tcell=sim1$tcell,age=sim1$age)
 scif1 <-  comp.risk(Event(time,cause)~const(tcell)+const(age),
                   data=bt,cause=1,model="logistic2")
 scif2 <-  comp.risk(Event(time,cause)~const(tcell)+const(age),
                   data=bt,cause=2,model="logistic2")

 plot(scif1$cum,type="l")
 lines(scif2$cum,col=1,lty=2)
 legend("topleft",c("cause1","cause2"),lty=1:2,col=1:1)
 lines(cifs[[1]]$cum,col=2)
 lines(cifs[[2]]$cum,col=2,lty=2)

#  Everyhing wrapped in call assuming covariates work in the same way for two models
dd <- sim.cifs(list(cif1,cif2),2000,data=bmt)
scif1 <-  comp.risk(Event(time,cause)~const(tcell)+const(age),
                  data=dd,cause=1,model="logistic2")
scif2 <-  comp.risk(Event(time,cause)~const(tcell)+const(age),
                  data=dd,cause=2,model="logistic2")

plot(scif1$cum,type="l")
lines(scif2$cum,col=1,lty=2)
legend("topleft",c("cause1","cause2"),lty=1:2,col=1:1)
lines(cifs[[1]]$cum,col=2)
lines(cifs[[2]]$cum,col=2,lty=2)

# Everyhing wrapped in call assuming covariates work in the same way for two models
# but now draws cif1 to be of correct model, but model 2 is adapted 
#(if needed) to make constraints satisfied F1+F2 <=1
# see doubleFG of mets package for paramtrization
# and drawns as "if not cause1" then distribute according to cause 2
# dd <- sim.cifsRestrict(list(cif1,cif2),2000,data=bmt)
# faster with mets package 
# dd <- sim.cifs(list(cif1,cif2),1000,data=bmt)
# scif1 <-  cifreg(Event(time,cause)~tcell+age,data=dd,cause=1)
# scif2 <-  cifreg(Event(time,cause)~tcell+age,data=dd,cause=2)
#   
# plot(scif1$cum,type="l")
# legend("topleft",c("cause1","cause2"),lty=1:2,col=1:1)
# lines(cifs[[1]]$cum,col=2)
# lines(cifs[[2]]$cum,col=2,lty=2)
# 

timereg documentation built on Oct. 13, 2021, 5:06 p.m.

Related to sim.cif in timereg...