Skip to content

Commit 4c3d227

Browse files
committed
names for sim.recurrent
1 parent 814ead9 commit 4c3d227

File tree

4 files changed

+47
-28
lines changed

4 files changed

+47
-28
lines changed

R/recurrent.marginal.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,7 @@ if (3 %in% which) {
12811281
##' @param rc relative risk for exponential censoring
12821282
##' @param strata1 strata variable for cox1 baseline, then data is not needed
12831283
##' @param stratad strata variable for coxd baseline, then data is not needed
1284+
##' @param death.code code for death (default is 3) in status variable, events are coded as 1
12841285
##' @param ... Additional arguments to simGLcox, nmin, nmax regulates linear approximation grid
12851286
##' @author Thomas Scheike
12861287
##' @references
@@ -1292,20 +1293,21 @@ if (3 %in% which) {
12921293
##' n <- 100
12931294
##' xr <- phreg(Surv(entry,time,status==1)~x+cluster(id),data=hf)
12941295
##' dr <- phreg(Surv(entry,time,status==2)~x+cluster(id),data=hf)
1295-
##' simcoxcox <- sim.recurrent(xr,dr,n=n,data=hf)
1296+
##' simcoxcox <- sim.recurrent(xr,dr,n=n,data=hf,death.code=2)
12961297
##' recGL <- recreg(Event(entry,time,status)~x+cluster(id),hf,death.code=2)
1297-
##' simglcox <- sim.recurrent(recGL,dr,n=n,data=hf)
1298+
##' simglcox <- sim.recurrent(recGL,dr,n=n,data=hf,death.code=2)
12981299
##'
12991300
#' @export sim.recurrent
13001301
#' @usage sim.recurrent(cox1,coxd=NULL,n=1,data=NULL,
13011302
#' type=c("default","cox-cox","gl-cox"),id="id",
13021303
#' varz=1,share=1,cens=0.001,scale1=1,scaled=1,dependence=NULL,
1303-
#' r1=NULL,rd=NULL,rc=NULL,strata1=NULL,stratad=NULL,...)
1304+
#' r1=NULL,rd=NULL,rc=NULL,strata1=NULL,stratad=NULL,death.code=3death.code=3,,...)
13041305
sim.recurrent <- function(cox1,coxd=NULL,
13051306
n=1, data=NULL,type=c("default","cox-cox","gl-cox"),
13061307
id="id",varz=1,share=1,cens=0.001,
13071308
scale1=1,scaled=1,dependence=NULL,
13081309
r1=NULL,rd=NULL,rc=NULL,strata1=NULL,stratad=NULL,
1310+
death.code=3,
13091311
...) {# {{{
13101312
## exp censoring default
13111313
death <- NULL
@@ -1365,28 +1367,33 @@ for (j in 1:attr(strat1d,"nlevel")) {
13651367
rrss$id <- r1i[rrss$id+1]
13661368
rrs <- rbind(rrs,rrss)
13671369
}
1370+
rrs <- dtransform(rrs,statusD=death.code,statusD==3)
13681371
} else {
13691372
if (is.null(dependence)) dependence <- 0
13701373
if (!is.null(LamD))
1371-
rrs <- simRecurrentList(n,list(Lam1),death.cumhaz=list(LamD),rr=matrix(r1,ncol=1),rd=matrix(rd,ncol=1),rc=rc,cens=cens,var.z=varz,dependence=dependence)
1374+
rrs <- simRecurrentList(n,Lam1,death.cumhaz=LamD,rr=matrix(r1,ncol=1),rd=matrix(rd,ncol=1),rc=rc,cens=cens,var.z=varz,dependence=dependence)
13721375
else rrs <- simRecurrentList(n,list(Lam1),rr=matrix(r1,ncol=1),rc=rc,cens=cens,var.z=varz,dependence=dependence)
1373-
rrs$Z <- attr(rrs,"z")[rrs$id]
1376+
rrs$Z <- attr(rrs,"z")[rrs$id+1]
13741377

13751378
rrs$statusD <- rrs$status
13761379
if (!is.null(LamD)) {
1377-
rrs <- dtransform(rrs,statusD=3,death==1)
1380+
rrs <- dtransform(rrs,statusD=death.code,death==1)
13781381
}
1379-
rrs$id <- rrs$id-1
13801382
}
13811383

13821384
## add covariates,
13831385
if (!is.null(data)) rrs <- cbind(rrs,rrdata$data[rrs$id,])
13841386

1387+
## add correct names to entry,time,status
1388+
varsY <- all.vars(update(drop.specials(xr$formula,"cluster"),.~1))
1389+
rrs[,varsY] <- cbind(rrs$start,rrs$stop,rrs$statusD)
1390+
1391+
rrs <- dkeep(rrs,c(all.vars(xr$formula),all.vars(dr$formula),"orig.id"))
1392+
13851393
return(rrs)
13861394
}
13871395
# }}}
13881396

1389-
13901397
simRecurrentIIHist <- function(n,cumhaz,death.cumhaz,cens=NULL,rr=NULL,rc=NULL,rd=NULL,
13911398
max.recurrent=100,dependence=0,var.z=0.22,cor.mat=NULL,
13921399
HistN1=~I(Nt^.5),HistD=~I(Nt^.5),HistN1.beta=c(1.0),HistD.beta=c(1.0),...)

R/sim-pc-hazard.R

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ rcrisk <-function(cumA,cumB,rr1=NULL,rr2=NULL,n=NULL,
355355
sim.phreg <- function(cox,n,data=NULL,Z=NULL,rr=NULL,strata=NULL,
356356
entry=NULL,extend=NULL,cens=NULL,rrc=NULL,...)
357357
{# {{{
358-
359358
if (!is.null(data)) {
360359
scox1 <- draw.phreg(cox,n,data=data,onlyX=TRUE,...)
361360
dat <- scox1$data
@@ -403,6 +402,15 @@ sim.phreg <- function(cox,n,data=NULL,Z=NULL,rr=NULL,strata=NULL,
403402
ptt$status <- ifelse(ptt$time<pct,ptt$status,0)
404403
}
405404

405+
##### add correct names to entry,time,status
406+
###varsY <- all.vars(update(drop.specials(cox$formula,"cluster"),.~1))
407+
###if (length(varsY)==2)
408+
###ptt[,varsY] <- cbind(ptt$time,ptt$status)
409+
###if (length(varsY)==3)
410+
###ptt[,varsY] <- cbind(ptt$entry,ptt$time,ptt$status)
411+
###
412+
###ptt <- dkeep(ptt,c(all.vars(cox$formula),"orig.id"))
413+
406414
return(ptt)
407415
}# }}}
408416

@@ -576,6 +584,15 @@ sim.phregs <- function(coxs,n,data=NULL,rr=NULL,strata=NULL,
576584
ptt$status <- ifelse(ptt$time<pct,ptt$status,0)
577585
}
578586

587+
##### add correct names to entry,time,status
588+
###varsY <- all.vars(update(drop.specials(coxs[[1]]$formula,"cluster"),.~1))
589+
###print(varsY)
590+
###if (length(varsY)==2)
591+
###ptt[,varsY] <- cbind(ptt$time,ptt$status)
592+
###if (length(varsY)==3)
593+
###ptt[,varsY] <- cbind(ptt$entry,ptt$time,ptt$status)
594+
###ptt <- dkeep(ptt,c(varsY,names(datas),"orig.id"))
595+
579596
return(ptt)
580597
}# }}}
581598

man/sim.recurrent.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/cooking-survival-data.Rmd

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ library(mets)
513513
514514
simcoxcox <- sim.recurrent(xr,dr,n=n,data=hf)
515515
516-
xrs <- phreg(Surv(start,stop,statusD==1)~treatment+cluster(id),data=simcoxcox)
517-
drs <- phreg(Surv(start,stop,statusD==3)~treatment+cluster(id),data=simcoxcox)
516+
xrs <- phreg(Surv(entry,time,status==1)~treatment+cluster(id),data=simcoxcox)
517+
drs <- phreg(Surv(entry,time,status==3)~treatment+cluster(id),data=simcoxcox)
518518
estimate(xrs)
519519
estimate(drs)
520520
@@ -530,27 +530,20 @@ library(mets)
530530
and a now with Ghosh-Lin and Cox marginals
531531

532532
```{r}
533-
recGL <- recreg(Event(entry,time,status)~x+cluster(id),hf,death.code=2)
533+
recGL <- recreg(Event(entry,time,status)~treatment+cluster(id),hf,death.code=2)
534534
estimate(recGL)
535535
estimate(dr)
536536
537537
simglcox <- sim.recurrent(recGL,dr,n=n,data=hf)
538538
539-
simcoxcox <- sim.recurrent(xr,dr,n=n,data=hf)
540-
dtable(simcoxcox,~statusD)
541-
542-
recGL <- recreg(Event(entry,time,status)~x+cluster(id),hf,death.code=2)
543-
simglcox <- sim.recurrent(recGL,dr,n=n,data=hf)
544-
545-
GLs <- recreg(Event(start,stop,statusD)~x+cluster(id),data=simglcox,death.code=3)
546-
drs <- phreg(Surv(start,stop,statusD==3)~x+cluster(id),data=simglcox)
539+
GLs <- recreg(Event(entry,time,status)~treatment+cluster(id),data=simglcox,death.code=3)
540+
drs <- phreg(Surv(entry,time,status==3)~treatment+cluster(id),data=simglcox)
547541
estimate(GLs)
548542
estimate(drs)
549543
550544
par(mfrow=c(1,2))
551545
plot(GLs);
552546
plot(recGL,add=TRUE)
553-
###
554547
plot(drs)
555548
plot(dr,add=TRUE)
556549
@@ -569,8 +562,8 @@ xr <- phreg(Surv(entry,time,status==1)~strata(x)+age+cluster(id),data=hf)
569562
dr <- phreg(Surv(entry,time,status==2)~x+strata(Z1)+age+cluster(id),data=hf)
570563
n <- 100
571564
rr <- sim.recurrent(xr,dr,n=n,data=hf)
572-
rxr <- phreg(Surv(start,stop,statusD==1)~strata(x)+age+cluster(id),data=rr)
573-
rdr <- phreg(Surv(start,stop,statusD==3)~x+strata(Z1)+age+cluster(id),data=rr)
565+
rxr <- phreg(Surv(entry,time,status==1)~strata(x)+age+cluster(id),data=rr)
566+
rdr <- phreg(Surv(entry,time,status==3)~x+strata(Z1)+age+cluster(id),data=rr)
574567
estimate(xr)
575568
estimate(rxr)
576569
estimate(dr)
@@ -583,8 +576,8 @@ glr <- recreg(Event(entry,time,status)~strata(x)+age+cluster(id),data=hf,death.c
583576
dr <- phreg(Surv(entry,time,status==2)~x+strata(Z1)+age+cluster(id),data=hf)
584577
n <- 100
585578
rr <- sim.recurrent(glr,dr,n=n,data=hf)
586-
rxr <- recreg(Event(start,stop,statusD)~strata(x)+age+cluster(id),data=rr,death.code=3)
587-
rdr <- phreg(Surv(start,stop,statusD==3)~x+strata(Z1)+age+cluster(id),data=rr)
579+
rxr <- recreg(Event(entry,time,status)~strata(x)+age+cluster(id),data=rr,death.code=3)
580+
rdr <- phreg(Surv(entry,time,status==3)~x+strata(Z1)+age+cluster(id),data=rr)
588581
estimate(xr)
589582
estimate(rxr)
590583
estimate(dr)

0 commit comments

Comments
 (0)