##################################################################### # # Instructions on using this program # 1. change the name of the Supplementary Functions file to Functions.R, # change the name of the Supplementary Data file to Data.csv, # and change extension of this file from .txt to .R # 2. put this file, Functions.R and Data.csv in the same directory # 3. change DIR variable to be the name of this directory # 4. create two subdirectories called Figures and Tables # 5. Install R # (see www.r-project.org/ to get R and instructions on using R) # 6. Run this program in R # ################################################################### # # Description of Data File # # The file is a comma separated file, with the first line giving # the variable name. # # The variables are: # # setting= setting number, see text and Table 1 # study=study name # ug = dose for rPA vaccines # proportionofhumandose= dose for AVA vaccines # diluent= either "saline" or "adjuvanted" # survive= 0 for died, 1 for survived # vaccine= C for AVA vaccine, A,B,D, or E for different rPA vaccines # species= numeric symbol, 1=rhesus,2=rabbit,3=cynos,4=human # Species= either Rhesus, Rabbit, Cynos, or Human # challenge=number of weeks after initial vaccination of the challenge # ed50=TNA taken at week given by ed50_week variable # ed50_week = number of weeks after last vaccination (or after second vaccination for humans) # in which TNA was measured # elisa=ELISA # elisa_week = number of weeks after last vaccination (or after second vaccination for humans) # in which ELISA was measured # # # ################################################################### ####################################### # set DIR, nPerm, nBoot and determine # where to put figures and tables ####################################### DIR<-"H:/My Documents/extramural/anthrax Meta/R/forPaper/" #DIR<-"C:/H/My Documents/extramural/anthrax Meta/R/forPaper/" ## use colors that are robust to colorblindness # orange for rabbits, sky-blue for cynos, blue-green for rhesus colorRabbits<-"#E69F00" colorCynos<-"#56B4E9" colorRhesus<-"#009E73" # get functions from other file source(paste(DIR,"Functions.R",sep="")) ## for final analysis use nPerm=2000 and nBoot=2000 ## for quicker run can change that to smaller values nPerm<-2000 nBoot<-2000 #nPerm<-3 #nBoot<-3 putplot<-function(name,width=3.5){ ## for Windows based results, i.e., for importing into Word files use... #dev.print(win.metafile,filename=paste(DIR,"Figures/",name,".wmf",sep="")) ## or for more portability use if (!is.null(width)){ dev.print(pdf,file=paste(DIR,"Figures/",name,".pdf",sep=""),width=width) } else { dev.print(pdf,file=paste(DIR,"Figures/",name,".pdf",sep="")) } } putcsv<-function(x,name,rowNames=FALSE){ write.csv(x,file=paste(DIR,"Tables/",name,sep=""),row.names=rowNames) } ################################################################### # # Import data # ################################################################### d<-read.csv(paste(DIR,"Data.csv",sep=""),header=TRUE) ### add log10 values d<-data.frame(d,log10elisa=log10(d$elisa),log10ed50=log10(d$ed50)) # main data set, use only non-missing ed50=TNA dm<-d[!is.na(d$ed50),] ################################################################### # # Table: Settings # ################################################################### tableSettings<-function(d){ n<-nrow(d) ### animals studies are 1-11 ### for Human studies, only use setting=14, 2 doses IM S<-c(1:11,14) nanimal<-ndose<-rep(NA,length(S)) for (i in 1:length(S)){ di<-d[d$setting==S[i],] nanimal[i]<-nrow(di) if (di[1,"vaccine"]=="C"){ ud<-unique(di[,"proportionofhumandose"]) ndose[i]<-length(ud) } else { ud<-unique(di[,"ug"]) ndose[i]<-length(ud) } } out<-data.frame(setting=S,ndose,nanimal) out } ## count only non-missing TNA tab1<-tableSettings(dm) putcsv(tab1,"tableSettings.csv") ################################################################### # # Figures: ELISA vs TNA # ################################################################### #### Figure S1H Human dh<-dm[dm$Species=="Human",] ### for Human studies, in cross-species comparisons ### only use setting=14, 2 doses IM ### but for ELISA vs TNA correlations we can use all human data #dh<-d[d$setting==14,] par(mfrow=c(1,1)) ed50<-dh$ed50 tigg<-dh$elisa I<-ed50>min(ed50,na.rm=TRUE) & tigg>min(tigg,na.rm=TRUE) I<- !is.na(I) & I set.seed(1) jig1<-exp(rnorm(length(ed50),0,sd=.05)) jig2<-exp(rnorm(length(ed50),0,sd=.05)) plot(ed50*jig1,tigg*jig2,log="xy",xlab="Toxin Neutralizing Activity",ylab="ELISA",axes=FALSE) axis(1,at=c(min(ed50,na.rm=TRUE),10,10^2,10^3,10^4,10^5),label=c("BLD","10","100","1000","10,000","100,000")) axis(2,at=c(min(tigg,na.rm=TRUE),10,10^2,10^3,10^4,10^5),label=c("BLD","10","100","1000","10,000","100,000"),las=1) box() putplot("FigureS1H",width=7) #putplot("FigureS1H35",width=3.5) ct1<-cor.test(log(ed50),log(tigg)) ct1 ### calculate the proportion below the limit of detection propBLD<-function(x){ x<-x[!is.na(x)]; 100*length(x[x==min(x)])/length(x) } #propBLD(ed50) #propBLD(tigg) #### check correlation without values BLD #### two different LoD values, use >15 and >1. #I<-ed50>min(ed50,na.rm=TRUE) & tigg>min(tigg,na.rm=TRUE) #I<-ed50>15 & tigg> 1 #I<- !is.na(I) & I #ct2<-cor.test(log(ed50[I]),log(tigg[I])) #ct2 ### Figure S1R Rabbit dr<-dm[dm$Species=="Rabbit",] ed50<-dr$ed50 tigg<-dr$elisa I<-ed50>min(ed50,na.rm=TRUE) & tigg>min(tigg,na.rm=TRUE) I<- !is.na(I) & I jig1<-exp(rnorm(length(ed50),0,sd=.05)) jig2<-exp(rnorm(length(ed50),0,sd=.05)) plot(ed50*jig1,tigg*jig2,log="xy",xlab="Toxin Neutralizing Activity",ylab="ELISA",axes=FALSE,col=colorRabbits) axis(1,at=c(min(ed50,na.rm=TRUE),10,10^2,10^3,10^4,10^5),label=c("BLD","10","100","1000","10,000","100,000")) axis(2,at=c(min(tigg,na.rm=TRUE),10,10^2,10^3,10^4,10^5), label=c("BLD","10","100","1000","10,000","100,000"),las=1) box() #propBLD(ed50) #propBLD(tigg) ct1<-cor.test(log(ed50),log(tigg)) ct1 #I<-ed50>min(ed50,na.rm=TRUE) & tigg>min(tigg,na.rm=TRUE) #I<- !is.na(I) & I #ct2<-cor.test(log(ed50[I]),log(tigg[I])) #ct2 putplot("FigureS3R",width=7) ### Figure 1NHP dNHP<-dm[dm$Species=="Cynos" | dm$Species=="Rhesus",] ed50<-dNHP$ed50 tigg<-dNHP$elisa I<-ed50>min(ed50,na.rm=TRUE) & tigg>min(tigg,na.rm=TRUE) I<- !is.na(I) & I jig1<-exp(rnorm(length(ed50),0,sd=.05)) jig2<-exp(rnorm(length(ed50),0,sd=.05)) plot(ed50*jig1,tigg*jig2,log="xy",xlab="Toxin Neutralizing Activity",ylab="ELISA",axes=FALSE,type="n") I<-dNHP$Species=="Cynos" points(ed50[I]*jig1[I],tigg[I]*jig2[I],col=colorCynos) I<-dNHP$Species=="Rhesus" points(ed50[I]*jig1[I],tigg[I]*jig2[I],col=colorRhesus) axis(1,at=c(min(ed50,na.rm=TRUE),10,10^2,10^3,10^4,10^5),label=c("BLD","10","100","1000","10,000","100,000")) axis(2,at=c(min(tigg,na.rm=TRUE),10,10^2,10^3,10^4,10^5), label=c("BLD","10","100","1000","10,000","100,000"),las=1) box() #propBLD(ed50) #propBLD(tigg) ct1<-cor.test(log(ed50),log(tigg)) ct1 #I<-ed50>min(ed50,na.rm=TRUE) & tigg>min(tigg,na.rm=TRUE) #I<- !is.na(I) & I #ct2<-cor.test(log(ed50[I]),log(tigg[I])) #ct2 putplot("FigureS2NHP",width=7) ################################################################### # # Figure: logistic with Bootstrap CI # ################################################################### OUT<-matrix(NA,11,8,dimnames=list(paste("setting",1:11),c("estimate","lower","upper","n","var log(x)","mean log(x)","n Boot","n Boot missing"))) par(mfrow=c(3,4),oma=c(4,4,0,0),mar=c(1,1,3.5,1)) for (i in 1:11){ OUT[i,]<-glmplotBoot(s=i,B=nBoot) } # if for the bootstrap data set all animals survive or all die, then set # values to missing, count how many are missing in such a way by OUT[,"n Boot missing"] putcsv(round(OUT),"PA50with95CI.csv",rowNames=TRUE) mtext("Toxin Neutralizing Activity",side=1,outer=TRUE,padj=2,cex=1.3) mtext("Probability of Survival",outer=TRUE,side=2,padj=-2,cex=1.3) #putplot("Fig11Panel",width=5) putplot("Figure1",width=5) # meta analysis for forest plots metaRabbits<-meta(OUT[1:5,6],OUT[1:5,5],OUT[1:5,4],tau2=NULL) metaCynos<-meta(OUT[6:7,6],OUT[6:7,5],OUT[6:7,4],tau2=NULL) metaRhesus<-meta(OUT[8:11,6],OUT[8:11,5],OUT[8:11,4],tau2=NULL) # fixed effects model, tau2=0 #metaRabbits<-meta(OUT[1:5,6],OUT[1:5,5],OUT[1:5,4],tau2=0) #metaCynos<-meta(OUT[6:7,6],OUT[6:7,5],OUT[6:7,4],tau2=0) #metaRhesus<-meta(OUT[8:11,6],OUT[8:11,5],OUT[8:11,4],tau2=0) forest<-matrix(NA,14,5,dimnames=list( c(paste("Setting",1:5),"Overall rabbits", paste("Setting",6:7),"Overall cynos", paste("Setting",8:11),"Overall rhesus"), c("estimate","lower","upper","n","tau2"))) forest[1:5,1:4]<-OUT[1:5,c("estimate","lower","upper","n")] forest[6,]<-metaRabbits forest[7:8,1:4]<-OUT[6:7,c("estimate","lower","upper","n")] forest[9,]<-metaCynos forest[10:13,1:4]<-OUT[8:11,c("estimate","lower","upper","n")] forest[14,]<-metaRhesus par(mfrow=c(1,1),mar=c(4,4,1,1),oma=c(0,0,0,0)) plotForest(forest,bit=.1,plotstyle="traditional",XLIM=10^c(0,5.5),XLAB="Toxin Neutralizing Activity") #plotForest(forest,bit=.1,plotstyle="traditional",XLAB="Toxin Neutralizing Activity") #putplot("ForestPA50",width=3.5) putplot("Figure2",width=3.5) putcsv(forest,"MetaPA50.csv",rowNames=TRUE) ### Now do permutation tests to make sure the slopes are all significantly ### different from zero set.seed(43943591) pvalues<-rep(NA,11) names(pvalues)<-paste("settting=",1:11) for (i in 1:11){ pvalues[i]<-permTestOneSetting(i,nperm=nPerm) } #### these are one-sided p-values, so multiply by 2 to make 2-sided #### with nPerm=2000 all are the lowest possible, p=2*1/2001 2*pvalues ################################################################### # # Figure: VE Combined # ################################################################### par(mfrow=c(1,1),mar=c(4,4,1,1)+.1) ## remember all functions are in Functions.R figVECombined() #putplot("Fig2b3noci",width=3.5) putplot("Figure3",width=3.5) #### Now do permutation test set.seed(43943591) pvalues<-rep(NA,3) names(pvalues)<-c("rabbits","cynos","rhesus") ### p-values are one-sided, double to get 2 sided ones outRabbits<-permTest(1:5,nperm=nPerm) 2*outRabbits$p.value outCynos<-permTest(6:7,nperm=nPerm) 2*outCynos$p.value outRhesus<-permTest(8:11,nperm=nPerm) 2*outRhesus$p.value ################################################################### # # Table: PPE # ################################################################### t0<-proc.time() tabPPE<-calcCoD.PPE(1:11,x="log10ed50") putcsv(tabPPE,"tablePPE.csv") tabPPEboot<-ppeboot(nBoot) putcsv(tabPPEboot,"tablePPEboot.csv") ################################################################### # # Figure: Model 2 for Setting 3 # ################################################################### par(mfrow=c(1,1),mar=c(5,4,1,1)+.1) #graph.studyModel(d=dm[dm$setting==3 & dm$ug>0,], # xvar="log10ed50",svar="ug",fit="none",XLAB="TNA at Week 4",LEGX=1.1,DOSE0=.005) graph.studyModel(d=dm[dm$setting==3,], xvar="log10ed50",svar="ug",fit="none",XLAB="TNA at Week 4",LEGX=1.1,DOSE0=.005) #putplot("FigModel2Setting3",width=3.5) putplot("Figure4",width=3.5) #### test for dose effect from Model 2 d3<-dm[dm$setting==3,] logdoseS3<-log10(d3$ug) logdoseS3[logdoseS3==-Inf]<-log10(0.005) d3<-data.frame(d3,logdose=logdoseS3) gModel2Setting3<-glm(survive~log10ed50+logdose,data=d3) summary(gModel2Setting3) ################################################################### # # Cross Species Pairwise Tests on PA50 # ################################################################### test36<-pwe(3,6,B=nBoot) test38<-pwe(3,8,B=nBoot) test68<-pwe(6,8,B=nBoot) test47<-pwe(4,7,B=nBoot) pairwiseTests<-rbind(test36,test38,test68,test47) putcsv(pairwiseTests,"pairwiseTestsSpecies.csv") ################################################################### # # Table: Cross-species # ################################################################### ## setting 14 - AVRP_Human_2IM has day 56 data ## from people who have received 2 intra-muscular shots at 0 and 28 days. strata<-list(c(3,6,8),c(4,7)) set.seed(123011) tabObsPred<-obspredTable(d=dm,dH=dm[dm$setting==14,],strata,B=nBoot) putcsv(tabObsPred,"crossSpeciesObsPred.csv") ###################################################### #### Figure Cross Species Prediction ###################################################### par(mar=c(4,4,1,1)+.1) crossSpeciesPlot(3,6,colorRabbits,colorCynos,XLAB="Toxin Neutralizing Activity") #putplot("crossSpecies36",width=3.5) putplot("Figure5",width=3.5)