######## Primary analyses rm(list=ls()) source('sensitivitySGD.R', chdir=TRUE) vax<-scan("vax004po.txt", list(sid=0, Vx=0, sex=0, age=0, white=0, black=0, asian=0, hisp=0, otherrace=0, education=0, US=0, Canada=0, Netherlands=0, site=0, region=0, baselineriskscore=0, calenddayssinceentry=0, HIVinfection=0, daysinfectiongroup=0, daysinfectiondiagnosis=0, treatmentstart=0, daystreatmentstart=0, composite=0, dayscomposite=0, dayssinceinfectiondiagnosis=0, grouptime=0, viralload=0, CD4list=0)) id<-unique(vax$sid) trtstart<-daystrtstart<-comp<-dayscomp<-z<-white<-risk<-s<-daysinfectiondiagnosis<-NULL count<-1 for(i in 1:length(vax$sid)){ if (vax$sid[i]==id[count]) { trtstart[count]<-vax$treatmentstart[i] daystrtstart[count]<-vax$daystreatmentstart[i] comp[count]<-vax$composite[i] dayscomp[count]<-vax$dayscomposite[i] z[count]<-vax$Vx[i] white[count]<-vax$white[i] risk[count]<-vax$baselineriskscore[i] s[count]<-vax$HIVinfection[i] daysinfectiondiagnosis[count]<-vax$daysinfectiondiagnosis[i] count<-count+1 } } ### Looking only inside the non-white cohort z<-z[white==0] s<-s[white==0] trtstart<-trtstart[white==0] daystrtstart<-daystrtstart[white==0] ## number patients N<-length(z) ## number vaxinated Nv<-sum(z) ## number placebo Np<-N-Nv ## number infected that where not vacinated np<-sum((1-z)*s) ## number infected that where vacinated nv<-sum(z*s) d<-trtstart y<-daystrtstart/30 # Converting to months p0<-np/Np p1<-nv/Nv phi <- c(0.99, 0.95, 0.90, 0.8, 0.5, p0) Pi<-phi*p1 psi<-c(log((1-p0-p1+Pi)*Pi / ((p0-Pi)*(p1-Pi)))) beta <- beta0 <- beta1 <- seq(from=-3/12, to=3/12, length=101) t.points<-24 results<-sensitivitySGD(z=z,y=y, s=s, d=d, beta0=beta0, beta1=beta1, psi=psi, ci=0.95, N.boot=1000, selection=1L, groupings=c(0L,1L), empty.principle.stratum=c(0L,1L), trigger=1L, ci.method='bootstrap', tau = 24, time.points=t.points) save(results, file="results.rda") ########## Analysis where principal strata are based on being infected within k years of randomization (k=2 or 3) ########## (results presented in Figures 1 and 2 of Supplemental Material) rm(list=ls()) library(survival) source('sensitivitySGD.R') source('sensitivitySGD_followup.R') vax<-scan("vax004po.txt", list(sid=integer(0), Vx=integer(0), sex=integer(0), age=integer(0), white=integer(0), black=integer(0), asian=integer(0), hisp=integer(0), otherrace=integer(0), education=integer(0), US=integer(0), Canada=integer(0), Netherlands=integer(0), site=integer(0), region=integer(0), baselineriskscore=integer(0), calenddayssinceentry=integer(0), HIVinfection=integer(0), daysinfectiongroup=integer(0), daysinfectiondiagnosis=integer(0), treatmentstart=integer(0),daystreatmentstart=integer(0), composite=integer(0), dayscomposite=integer(0), dayssinceinfectiondiagnosis=integer(0), grouptime=integer(0), viralload=double(0), CD4list=integer(0))) id<-unique(vax$sid) d <- y <- z <- s.star <- white <- v <- NULL count<-1 for(i in 1:length(vax$sid)){ if (vax$sid[i]==id[count]) { d[count]<-vax$treatmentstart[i] y[count]<-vax$daystreatmentstart[i]/30 z[count]<-vax$Vx[i] white[count]<-vax$white[i] s.star[count]<-vax$HIVinfection[i] v[count] <- vax$daysinfectiondiagnosis[i] count<-count+1 } } z <- z[white==0L] s.star <- s.star[white==0L] v <- v[white==0L] d <- d[white==0L] y <- y[white==0L] s <- ifelse(s.star & v < 1080, 1L, 0L) p0.3 <- 1-min(summary(survfit(Surv(v, s)~1, subset=z==0))$surv) p1.3 <- 1-min(summary(survfit(Surv(v, s)~1, subset=z==1))$surv) beta0 <- seq(from=-3L,to=3L,length.out=101L)/12L beta1 <- seq(from=-3L,to=3L,length.out=101L)/12L tau <- 24L t.point <- c(12L, 24L) phi3 <- c(0.99, 0.95, 0.90, 0.8, 0.5, p0.3) psi3 <- sapply(phi3, p0=p0.3, p1=p1.3, function(phi, p0, p1) log((1L-p0-p1+phi*p1)*(phi*p1) / ((p0 - phi*p1)*(p1 - phi*p1)))) ans3 <- sensitivitySGDFollowup(z, s, v=v, d, y, beta0=beta0, beta1=beta1, psi=psi3, tau=tau, time.points=t.point, ci=0.95, selection=1L, groupings=c(0L,1L), empty.principle.stratum=c(0L,1L), trigger=1L, ci.method='bootstrap', N.boot=1000L, verbose=TRUE) s <- ifelse(s.star & v < 720, 1L, 0L) p0.2 <- 1L-min(summary(survfit(Surv(v, s)~1L, subset=z==0L))$surv) p1.2 <- 1L-min(summary(survfit(Surv(v, s)~1L, subset=z==1L))$surv) phi2 <- c(0.99, 0.95, 0.90, 0.8, 0.5, p0.2) psi2 <- sapply(phi2, p0=p0.2, p1=p1.2, function(phi, p0, p1) log((1L-p0-p1+phi*p1)*(phi*p1) / ((p0 - phi*p1)*(p1 - phi*p1)))) ans2 <- sensitivitySGDFollowup(z, s, v=v, d, y, beta0=beta0, beta1=beta1, psi=psi2, tau=tau, time.points=t.point, ci=0.95, selection=1L, groupings=c(0L,1L), empty.principle.stratum=c(0L,1L), trigger=1L, ci.method='bootstrap', N.boot=1000L, verbose=TRUE) save(beta0,beta1,tau,t.point,ans3,phi3,psi3,p0.3,p1.3,ans2,phi2,psi2,p0.2,p1.2, file="vaxgen_followup.Rda") ####### Analysis with Y defined as time from randomization until start of ART ####### (results presented in Figure 3 Supplemental Material) rm(list=ls()) library(survival) source('sensitivitySGD.R') source('sensitivitySGD_followup.R') vax<-scan("vax004po.txt", list(sid=integer(0L), Vx=integer(0L), sex=integer(0), age=integer(0L), white=integer(0L), black=integer(0L), asian=integer(0L), hisp=integer(0L), otherrace=integer(0L), education=integer(0L), US=integer(0L), Canada=integer(0L), Netherlands=integer(0L), site=integer(0L), region=integer(0L), baselineriskscore=integer(0L), calenddayssinceentry=integer(0L), HIVinfection=integer(0L), daysinfectiongroup=integer(0L), daysinfectiondiagnosis=integer(0L), treatmentstart=integer(0L), daystreatmentstart=integer(0L), composite=integer(0L), dayscomposite=integer(0L), dayssinceinfectiondiagnosis=integer(0L), grouptime=integer(0L), viralload=double(0L), CD4list=integer(0L))) id<-unique(vax$sid) d <- y <- z <- s <- s.star <- v <- white <- NULL count<-1L for(i in 1:length(vax$sid)){ if (vax$sid[i]==id[count]) { d[count]<-vax$treatmentstart[i] y[count]<-(vax$daystreatmentstart[i] + vax$daysinfectiondiagnosis[i])/30 z[count]<-vax$Vx[i] white[count]<-vax$white[i] s.star[count] <-vax$HIVinfection[i] v[count] <- vax$daysinfectiondiagnosis[i]/30 count<-count + 1L } } z <- z[white==0L] s.star <- s.star[white==0L] v <- v[white==0L] d <- d[white==0L] y <- y[white==0L] beta0 <- seq(from=-3L,to=3L,length.out=101L)/12L beta1 <- seq(from=-3L,to=3L,length.out=101L)/12L tau <- 60L t.point <- c(60L) phi <- c(0.99, 0.95, 0.90, 0.8, 0.5, sum(z==0L & s.star==1L)/sum(z==0L)) set.seed(4633097) s <- ifelse(s.star & v < 36L, 1L, 0L) p0 <- 1L-min(summary(survfit(Surv(v, s)~1L, subset=z==0L))$surv) p1 <- 1L-min(summary(survfit(Surv(v, s)~1L, subset=z==1L))$surv) phi <- c(0.99, 0.95, 0.90, 0.8, 0.5, p0) altYFollow3Year <- list(p0=p0, p1=p1, phi=phi) altYFollow3Year$sens <- sensitivitySGDFollowup(z, s.star, v=v, d, y, beta0=beta0, beta1=beta1, phi=phi, tau=tau, followup.time=36L, time.points=t.point, ci=0.95, selection=1L, groupings=c(0L,1L), empty.principle.stratum=c(0L,1L), trigger=1L, ci.method='bootstrap', N.boot=1000L, verbose=TRUE) cat("\n") save(altYFollow3Year, altYFollow2Year, phi, beta0, beta1, tau, t.point, file='vaxgen_altY_3year_followup.Rda')