%HAART after OI report \documentclass[11pt]{article} \usepackage[margin=1.0in]{geometry} \usepackage[pdftex]{lscape} % allows tables to be landscape when \usepackage{threeparttable} \title{Time to HAART initiation after OI report} \author{Yanink Caro \& Bryan Shepherd} %\date{} %\SweaveOpts{prefix.string=graphics/plot} % Created a "graphics" subdirectory to save graph files in \begin{document} \SweaveOpts{concordance=TRUE} \maketitle % Hidden R code chunk --- reading in the data <>= rm(list=ls()) setwd("~/CCASAnet/Brenda_ CCASAnet/OI HAART/R files") source("table_functions_ycv.R") load("basic8CD4crypto.rda") library(quantreg) library("rms") @ <>= getmedian <- function(var,digits=1){ m1 <- round(median(var,na.rm=TRUE),digits) paste0(m1) } getquantiles <- function(var,digits=1){ q1 <- round(quantile(var,na.rm=TRUE,prob = 0.25),digits) q3 <- round(quantile(var,na.rm=TRUE,prob = 0.75),digits) paste0("(",q1,"--",q3,")") } cub.cd4<-(basic8CD4crypto$cd4Enrol)^(1/3) cd4enrol.imp<-lm(cub.cd4~site+age+male+year+route,data=basic8CD4crypto) summary(cd4enrol.imp) aux<-predict(cd4enrol.imp, basic8CD4crypto[is.na(basic8CD4crypto$cd4Enrol),c('site','age','male','year','route')]) basic8CD4crypto$CD4EnrolIMP<-with(basic8CD4crypto, ifelse(!is.na(cd4Enrol),cd4Enrol,aux^3)) basic8CD4crypto$included<-basic8CD4crypto$drop_y<-basic8CD4crypto$EXCL<-basic8CD4crypto$include_ce<-basic8CD4crypto$exclude_b<-NULL @ % R code chunk that generates LaTeX code to create table <>= library(xtable) getmedianIQR <- function(var,digits=1){ m1 <- round(median(var,na.rm=TRUE),digits) q1 <- round(quantile(var,na.rm=TRUE,prob = 0.25),digits) q3 <- round(quantile(var,na.rm=TRUE,prob = 0.75),digits) paste0(m1," (",q1,"--",q3,")") } getmedianIQR(basic8CD4crypto$age) tapply(basic8CD4crypto$age,basic8CD4crypto$site,getmedianIQR) line1 <- getmedtex(var=basic8CD4crypto$age,by=as.character(basic8CD4crypto$site),label="Patient age (years)",digits=0,inc.pval=FALSE) line2 <- getnp1line(var=ifelse(basic8CD4crypto$male==1,1,NA),by=as.character(basic8CD4crypto$site),rowlabel="Male",inc.pval=FALSE,indent=FALSE) getmedianIQR(basic8CD4crypto$cd4Enrol) tapply(basic8CD4crypto$cd4Enrol,basic8CD4crypto$site,getmedianIQR) line3 <- getmedtex(var=basic8CD4crypto$cd4Enrol,by=as.character(basic8CD4crypto$site),label="CD4 at enrol",digits=0,inc.pval=FALSE, lower.label=FALSE) line4 <- getnp1line(var=ifelse(basic8CD4crypto$TB==1,1,NA),by=as.character(basic8CD4crypto$site),rowlabel="TB",inc.pval=FALSE,indent=FALSE) line5 <- getnp1line(var=ifelse(basic8CD4crypto$Crypto==1,1,NA),by=as.character(basic8CD4crypto$site),rowlabel="Cryptococcocis",inc.pval=FALSE,indent=FALSE) line6 <- getnptex(var=basic8CD4crypto$route,by=as.character(basic8CD4crypto$site),label="Probable Infection Route",inc.pval=FALSE) line7 <- getnptex(var=basic8CD4crypto$regimen_class_new,by=as.character(basic8CD4crypto$site),label="HAART regimen",inc.pval=FALSE) tapply(basic8CD4crypto$timeOI,basic8CD4crypto$site,getmedianIQR) line8 <- getmedtex(var=basic8CD4crypto$timeOI/7,by=as.character(basic8CD4crypto$site),label="time since OI to HAART (weeks)",digits=1,inc.pval=FALSE,lower.label=FALSE) line9<-getnp1line(var=ifelse(basic8CD4crypto$before4==1,1,NA),by=as.character(basic8CD4crypto$site),rowlabel="Patients in the Early group",inc.pval=FALSE,indent=FALSE) crosstab2 <- table(as.character(basic8CD4crypto$site)) names(crosstab2) <- c("Argentina","Brazil","Chile","Honduras","Mexico") site.n2 <- printheader(crosstab2) table1 <- paste(line1,line2,line3$line.incmiss,line4,line5,line6,line7,line8,line9, sep=" \\\\\\\\ ") @ \begin{landscape} %%%%%%%%%%%%%%%%%%%% % TABLE 1 % %%%%%%%%%%%%%%%%%%%% \begin{center} \setlength{\tabcolsep}{4pt} \begin{threeparttable} \footnotesize \centering{ \caption{Summary of Patient Demographics by Site} \label{tab:base} \begin{tabular}{lllllll} \hline \Sexpr{site.n2}\\ \hline \\ \Sexpr{table1}\\ \tabularnewline \hline \end{tabular} } \begin{tablenotes} \item[a] Continuous variables are reported as medians (interquartile range). \item[b] Other regimen of HAART include regimens with Maraviroc or with 3 nucleotides. \end{tablenotes} \end{threeparttable} \end{center} \bigskip \bigskip \end{landscape} \begin{landscape} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Figure 1 %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{figure} \caption{Probability of Starting ART during the first year in OI non TB or cryptococcocis, only TB, and only cryptococcocis} \begin{center} <>= par(mfrow = c(2, 2), mai=c(1.2,1.2,0.3,0.3)) # 2 rows and 2 columns with(basic8CD4crypto, plot(survfit(Surv(timeOI,auxart)~pre2009),mark.time=FALSE, fun="event", xlim=c(0,365) , xlab="Months from all OI", ylab="Probability of Starting ART",axes=FALSE, col=c(1,2))) axis(2,cex.axis=0.9) axis(1, at=365*c(0,1/4,2/4,3/4,1), labels=c(0,3,6,9,12),cex.axis=0.9) legend("bottomright",legend=c("2009 and after","before 2009"),col=c(1,2),lty=c(1,1),inset=0.05,cex=0.8) legend("center",legend="p<0.01", bty = "n",inset=0.05) with(basic8CD4crypto[basic8CD4crypto$TB==0 & basic8CD4crypto$Crypto==0,], plot(survfit(Surv(timeOI,auxart)~pre2009),mark.time=FALSE, fun="event", xlim=c(0,365) , xlab="Months from OI (non TB or CM) ", ylab="Probability of Starting ART",axes=FALSE, col=c(1,2))) axis(2,cex.axis=0.9) axis(1, at=365*c(0,1/4,2/4,3/4,1), labels=c(0,3,6,9,12),cex.axis=0.9) legend("bottomright",legend=c("2009 and after","before 2009"),col=c(1,2),lty=c(1,1),inset=0.05,cex=0.8) legend("center",legend="p<0.01", bty = "n",inset=0.05) with(basic8CD4crypto[basic8CD4crypto$TB==1 & basic8CD4crypto$Crypto==0,], plot(survfit(Surv(timeOI,auxart)~pre2009),mark.time=FALSE, fun="event", xlim=c(0,365), xlab="Months from TB", ylab="Probability of Starting ART",axes=FALSE, col=c(1,2))) axis(2,cex.axis=0.9) axis(1, at=365*c(0,1/4,2/4,3/4,1), labels=c(0,3,6,9,12),cex.axis=0.9) legend("bottomright",legend=c("2009 and after","before 2009"),col=c(1,2),lty=c(1,1),inset=0.05,cex=0.8) legend("center",legend="p<0.01",bty = "n", inset=0.05) with(basic8CD4crypto[basic8CD4crypto$Crypto==1 & basic8CD4crypto$TB==0,], plot(survfit(Surv(timeOI,auxart)~pre2009),mark.time=FALSE, fun="event", xlim=c(0,365), xlab="Months from CM", ylab="Probability of Starting ART",axes=FALSE, col=c(1,2))) axis(2,cex.axis=0.9) axis(1, at=365*c(0,1/4,2/4,3/4,1), labels=c(0,3,6,9,12),cex.axis=0.9) legend("bottomright",legend=c("2009 and after","before 2009"),col=c(1,2),lty=c(1,1),inset=0.05,cex=0.8) legend("center",legend="p=0.96",bty = "n", inset=0.05) @ \end{center} \end{figure} \end{landscape} <>= dd<-datadist(basic8CD4crypto) options(datadist="dd") ourknots.year <- quantile(basic8CD4crypto$year, probs=c(0.25,0.5,0.75),na.rm=TRUE) Modelbefore<-lrm(before4 ~ male + I(age/10) + cd4Enrol+ TB + as.factor(route) + rcs(year,ourknots.year) + as.factor(site)+ Crypto, data=basic8CD4crypto, x=TRUE, y=TRUE) MB<-summary(Modelbefore, age=c(20,30),cd4Enrol=c(25,50),year=c(2002,2004), site="brazil",route="Heterosexual") MB1<-summary(Modelbefore, age=c(20,40)) MB2<-summary(Modelbefore, age=c(20,50)) MB3<-summary(Modelbefore, cd4Enrol=c(25,100)) MB4<-summary(Modelbefore, cd4Enrol=c(25,150)) MB5<-summary(Modelbefore, cd4Enrol=c(25,200)) MB6<-summary(Modelbefore, year=c(2002,2006)) MB7<-summary(Modelbefore, year=c(2002,2008)) MB8<-summary(Modelbefore, year=c(2002,2010)) MB9<-summary(Modelbefore, year=c(2002,2012)) av<-anova(Modelbefore) all.OR<-round(c(MB[2,4],MB[4,4],MB1[4,4],MB2[4,4],MB[6,4],MB3[6,4],MB4[6,4],MB5[6,4],MB[8,4],MB[12,4],MB[14,4],MB[16,4], MB[18,4],MB[10,4],MB6[10,4],MB7[10,4],MB8[10,4],MB9[10,4],MB[20,4],MB[22,4],MB[24,4],MB[26,4] ),2) all.low<-round(c(MB[2,6],MB[4,6],MB1[4,6],MB2[4,6],MB[6,6],MB3[6,6],MB4[6,6],MB5[6,6],MB[8,6],MB[12,6],MB[14,6],MB[16,6] ,MB[18,6],MB[10,6],MB6[10,6],MB7[10,6], MB8[10,6],MB9[10,6],MB[20,6],MB[22,6],MB[24,6],MB[26,6] ),2) all.up<-round(c(MB[2,7],MB[4,7],MB1[4,7],MB2[4,7],MB[6,7],MB3[6,7],MB4[6,7],MB5[6,7],MB[8,7],MB[12,7],MB[14,7],MB[16,7], MB[18,7],MB[10,7],MB6[10,7],MB7[10,7], MB8[10,7],MB9[10,7],MB[20,7],MB[22,7],MB[24,7],MB[26,7] ),2) p.values<-round(c(av[1,3],av[2,3],av[3,3],av[4,3],av[9,3],av[5,3],av[6,3],av[8,3]),3) @ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Figure 2 %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%% <>= jpeg("prob-early-haart.jpg",width=1200, height=1500, res=150) fitted<-Predict(Modelbefore, year, fun=function(x) {exp(x)/(1+exp(x))}) with(fitted, plot(year,yhat,type="l", xlab="Year of opportunistic infection", ylim=c(0,1),xlim=c(2002,2012),ylab="Estimated Probability of starting HAART within 4 weeks of OI",cex.lab=1.3,axes=F,xaxs="i", yaxs="i",xaxs="i", yaxs="i")) axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) with(fitted,polygon(c(year,rev(year)),c(lower,rev(upper)), col = "grey", border = FALSE)) with(fitted,lines(year,yhat,type="s",lty=1,col="blue")) box() @ \begin{figure} \begin{center} \caption{Probability of Early HAART initiation} \includegraphics[width=5 in, height=4 in, angle=0]{prob-early-haart.jpg} \end{center} \end{figure} \begin{landscape} %%%%%%%%%%%%%%%%%%%% % TABLE 2 % %%%%%%%%%%%%%%%%%%%% \begin{center} \setlength{\tabcolsep}{15pt} \begin{threeparttable} \footnotesize \centering{ \caption{Factors associated with early HAART initiation after an OI} \begin{tabular}{lcccc} \hline & OR & 95 \% confidence & interval & p-value\\ \hline Male & \Sexpr{all.OR[1]} & \Sexpr{all.low[1]} & \Sexpr{all.up[1]} & \Sexpr{p.values[1]}\\ \\ Age (years) & & & & \Sexpr{p.values[2]}\\ 20 & 1& & & \\ 30 & \Sexpr{all.OR[2]} & \Sexpr{all.low[2]} & \Sexpr{all.up[2]} & \\ 40 & \Sexpr{all.OR[3]} & \Sexpr{all.low[3]} & \Sexpr{all.up[3]} & \\ 50 & \Sexpr{all.OR[4]} & \Sexpr{all.low[4]} & \Sexpr{all.up[4]} & \\ \\ CD4 at Enrol & & & & \Sexpr{p.values[3]}\\ 25 & 1 & & & \\ 50 & \Sexpr{all.OR[5]} & \Sexpr{all.low[5]} & \Sexpr{all.up[5]} & \\ 100 & \Sexpr{all.OR[6]} & \Sexpr{all.low[6]} & \Sexpr{all.up[6]} & \\ 150 & \Sexpr{all.OR[7]} & \Sexpr{all.low[7]} & \Sexpr{all.up[7]} & \\ 200 & \Sexpr{all.OR[8]} & \Sexpr{all.low[8]} & \Sexpr{all.up[8]} & \\ \\ TB & \Sexpr{all.OR[9]} & \Sexpr{all.low[9]} & \Sexpr{all.up[9]} & \Sexpr{p.values[4]}\\ \\ Crypto & \Sexpr{all.OR[10]} & \Sexpr{all.low[10]} & \Sexpr{all.up[10]} & \Sexpr{p.values[5]}\\ \\ Route of transmission & & & &\Sexpr{p.values[6]} \\ Heterosexual & 1 & & & \\ MSM & \Sexpr{all.OR[11]} & \Sexpr{all.low[11]} & \Sexpr{all.up[11]} & \\ Other &\Sexpr{all.OR[12]} & \Sexpr{all.low[12]} & \Sexpr{all.up[12]} & \\ Unknown & \Sexpr{all.OR[13]} & \Sexpr{all.low[13]} & \Sexpr{all.up[13]} &\\ \\ Year of OI & & & & \Sexpr{p.values[7]}\\ 2002 & 1 & & & \\ 2004 & \Sexpr{all.OR[14]} &\Sexpr{all.low[14]} & \Sexpr{all.up[14]}& \\ 2006 & \Sexpr{all.OR[15]} & \Sexpr{all.low[15]} & \Sexpr{all.up[15]}& \\ 2008 & \Sexpr{all.OR[16]} & \Sexpr{all.low[16]} & \Sexpr{all.up[16]}& \\ 2010 & \Sexpr{all.OR[17]} & \Sexpr{all.low[17]} & \Sexpr{all.up[17]}& \\ 2012 & \Sexpr{all.OR[18]} & \Sexpr{all.low[18]} & \Sexpr{all.up[18]} &\\ \\ Site & & & & \Sexpr{p.values[8]}\\ Brazil & 1 & & & \\ Argentina & \Sexpr{all.OR[19]} & \Sexpr{all.low[19]} & \Sexpr{all.up[19]} &\\ Chile & \Sexpr{all.OR[20]} & \Sexpr{all.low[20]} & \Sexpr{all.up[20]} &\\ Honduras & \Sexpr{all.OR[21]} & \Sexpr{all.low[21]} & \Sexpr{all.up[21]} &\\ Mexico & \Sexpr{all.OR[22]} & \Sexpr{all.low[22]} & \Sexpr{all.up[22]} &\\ \tabularnewline \hline \end{tabular} } \end{threeparttable} \end{center} \bigskip \bigskip \end{landscape} %%%Imputation of CD4 at enrol <>= dd<-datadist(basic8CD4crypto) options(datadist="dd") ourknots.year <- quantile(basic8CD4crypto$year, probs=c(0.25,0.5,0.75),na.rm=TRUE) ModelbeforeIMP<-lrm(before4 ~ male + I(age/10) + CD4EnrolIMP+ TB + as.factor(route) + rcs(year,ourknots.year) + as.factor(site)+ Crypto, data=basic8CD4crypto, x=TRUE, y=TRUE) MB<-summary(ModelbeforeIMP, age=c(20,30),CD4EnrolIMP=c(25,50),year=c(2002,2004), site="brazil",route="Heterosexual") MB1<-summary(ModelbeforeIMP, age=c(20,40)) MB2<-summary(ModelbeforeIMP, age=c(20,50)) MB3<-summary(ModelbeforeIMP, CD4EnrolIMP=c(25,100)) MB4<-summary(ModelbeforeIMP, CD4EnrolIMP=c(25,150)) MB5<-summary(ModelbeforeIMP, CD4EnrolIMP=c(25,200)) MB6<-summary(ModelbeforeIMP, year=c(2002,2006)) MB7<-summary(ModelbeforeIMP, year=c(2002,2008)) MB8<-summary(ModelbeforeIMP, year=c(2002,2010)) MB9<-summary(ModelbeforeIMP, year=c(2002,2012)) avIMP<-anova(ModelbeforeIMP) allIMP.OR<-round(c(MB[2,4],MB[4,4],MB1[4,4],MB2[4,4],MB[6,4],MB3[6,4],MB4[6,4],MB5[6,4],MB[8,4],MB[12,4],MB[14,4],MB[16,4], MB[18,4],MB[10,4],MB6[10,4],MB7[10,4],MB8[10,4],MB9[10,4],MB[20,4],MB[22,4],MB[24,4],MB[26,4] ),2) allIMP.low<-round(c(MB[2,6],MB[4,6],MB1[4,6],MB2[4,6],MB[6,6],MB3[6,6],MB4[6,6],MB5[6,6],MB[8,6],MB[12,6],MB[14,6],MB[16,6] ,MB[18,6],MB[10,6],MB6[10,6],MB7[10,6], MB8[10,6],MB9[10,6],MB[20,6],MB[22,6],MB[24,6],MB[26,6] ),2) allIMP.up<-round(c(MB[2,7],MB[4,7],MB1[4,7],MB2[4,7],MB[6,7],MB3[6,7],MB4[6,7],MB5[6,7],MB[8,7],MB[12,7],MB[14,7],MB[16,7], MB[18,7],MB[10,7],MB6[10,7],MB7[10,7], MB8[10,7],MB9[10,7],MB[20,7],MB[22,7],MB[24,7],MB[26,7] ),2) p.values<-round(c(avIMP[1,3],avIMP[2,3],avIMP[3,3],avIMP[4,3],avIMP[9,3],avIMP[5,3],avIMP[6,3],avIMP[8,3]),3) @ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Figure 2 CD4 at Enrol IMP %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%% <>= jpeg("prob-early-haart-imp.jpg",width=1200, height=1500, res=150) fitted<-Predict(ModelbeforeIMP, year, fun=function(x) {exp(x)/(1+exp(x))}) with(fitted, plot(year,yhat,type="l", xlab="Year of opportunistic infection", ylim=c(0,1),xlim=c(2002,2012),ylab="Estimated Probability of starting HAART within 4 weeks of OI (CD4 IMP)",cex.lab=1.3,axes=F,xaxs="i", yaxs="i",xaxs="i", yaxs="i")) axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) with(fitted,polygon(c(year,rev(year)),c(lower,rev(upper)), col = "grey", border = FALSE)) with(fitted,lines(year,yhat,type="s",lty=1,col="blue")) box() @ \begin{figure} \begin{center} \caption{Adjusted Probability of Early HAART initiation} \includegraphics[width=5 in, height=4 in, angle=0]{prob-early-haart-imp.jpg} \end{center} \end{figure} \begin{landscape} %%%%%%%%%%%%%%%%%%%% % TABLE 2 % %%%%%%%%%%%%%%%%%%%% \begin{center} \setlength{\tabcolsep}{15pt} \begin{threeparttable} \footnotesize \centering{ \caption{Factors associated with early HAART initiation after an OI (CD4 at Enrol imp)} \begin{tabular}{lcccc} \hline & OR & 95 \% confidence & interval & p-value\\ \hline Male & \Sexpr{allIMP.OR[1]} & \Sexpr{allIMP.low[1]} & \Sexpr{allIMP.up[1]} & \Sexpr{p.values[1]}\\ \\ Age (years) & & & & \Sexpr{p.values[2]}\\ 20 & 1& & & \\ 30 & \Sexpr{allIMP.OR[2]} & \Sexpr{allIMP.low[2]} & \Sexpr{allIMP.up[2]} & \\ 40 & \Sexpr{allIMP.OR[3]} & \Sexpr{allIMP.low[3]} & \Sexpr{allIMP.up[3]} & \\ 50 & \Sexpr{allIMP.OR[4]} & \Sexpr{allIMP.low[4]} & \Sexpr{allIMP.up[4]} & \\ \\ CD4 at Enrol & & & & \Sexpr{p.values[3]}\\ 25 & 1 & & & \\ 50 & \Sexpr{allIMP.OR[5]} & \Sexpr{allIMP.low[5]} & \Sexpr{allIMP.up[5]} & \\ 100 & \Sexpr{allIMP.OR[6]} & \Sexpr{allIMP.low[6]} & \Sexpr{allIMP.up[6]} & \\ 150 & \Sexpr{allIMP.OR[7]} & \Sexpr{allIMP.low[7]} & \Sexpr{allIMP.up[7]} & \\ 200 & \Sexpr{allIMP.OR[8]} & \Sexpr{allIMP.low[8]} & \Sexpr{allIMP.up[8]} & \\ \\ TB & \Sexpr{allIMP.OR[9]} & \Sexpr{allIMP.low[9]} & \Sexpr{allIMP.up[9]} & \Sexpr{p.values[4]}\\ \\ Crypto & \Sexpr{allIMP.OR[10]} & \Sexpr{allIMP.low[10]} & \Sexpr{allIMP.up[10]} & \Sexpr{p.values[5]}\\ \\ Route of transmission & & & &\Sexpr{p.values[6]} \\ Heterosexual & 1 & & & \\ MSM & \Sexpr{allIMP.OR[11]} & \Sexpr{allIMP.low[11]} & \Sexpr{allIMP.up[11]} & \\ Other &\Sexpr{allIMP.OR[12]} & \Sexpr{allIMP.low[12]} & \Sexpr{allIMP.up[12]} & \\ Unknown & \Sexpr{allIMP.OR[13]} & \Sexpr{allIMP.low[13]} & \Sexpr{allIMP.up[13]} &\\ \\ Year of OI & & & & \Sexpr{p.values[7]}\\ 2002 & 1 & & & \\ 2004 & \Sexpr{allIMP.OR[14]} &\Sexpr{allIMP.low[14]} & \Sexpr{allIMP.up[14]}& \\ 2006 & \Sexpr{allIMP.OR[15]} & \Sexpr{allIMP.low[15]} & \Sexpr{allIMP.up[15]}& \\ 2008 & \Sexpr{allIMP.OR[16]} & \Sexpr{allIMP.low[16]} & \Sexpr{allIMP.up[16]}& \\ 2010 & \Sexpr{allIMP.OR[17]} & \Sexpr{allIMP.low[17]} & \Sexpr{allIMP.up[17]}& \\ 2012 & \Sexpr{allIMP.OR[18]} & \Sexpr{allIMP.low[18]} & \Sexpr{allIMP.up[18]} &\\ \\ Site & & & & \Sexpr{p.values[8]}\\ Brazil & 1 & & & \\ Argentina & \Sexpr{allIMP.OR[19]} & \Sexpr{allIMP.low[19]} & \Sexpr{allIMP.up[19]} &\\ Chile & \Sexpr{allIMP.OR[20]} & \Sexpr{allIMP.low[20]} & \Sexpr{allIMP.up[20]} &\\ Honduras & \Sexpr{allIMP.OR[21]} & \Sexpr{allIMP.low[21]} & \Sexpr{allIMP.up[21]} &\\ Mexico & \Sexpr{allIMP.OR[22]} & \Sexpr{allIMP.low[22]} & \Sexpr{allIMP.up[22]} &\\ \tabularnewline \hline \end{tabular} } \end{threeparttable} \end{center} \bigskip \bigskip \end{landscape} <>= medians<-c( median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2000]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2001]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2002]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2003]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2004]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2005]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2006]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2007]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2008]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2009]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2010]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2011]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2012]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2013]), median(basic8CD4crypto$timeOI[basic8CD4crypto$year==2014])) regyear<-with(basic8CD4crypto, rq(timeOI/7~rcs(year,ourknots.year), tau=.5)) basic8CD4crypto$mediantime<-with(basic8CD4crypto, ifelse(year==2000,medians[1], ifelse(year==2001, medians[2], ifelse(year==2002, medians[3], ifelse(year==2003,medians[4], ifelse(year==2004, medians[5], ifelse(year==2005, medians[6], ifelse(year==2006,medians[7], ifelse(year==2007, medians[8], ifelse(year==2008, medians[9], ifelse(year==2009,medians[10], ifelse(year==2010, medians[11], ifelse(year==2011, medians[12], ifelse(year==2012, medians[13], ifelse(year==2013, medians[14], medians[15])))))))))) ) ) )) ) @ <>= jpeg("median-time-by-year.jpg",width=1200, height=1500, res=150) plot(basic8CD4crypto$year,basic8CD4crypto$mediantime/7, pch=19,xlab="Year of opportunistic infection", ylab="Median time to HAART (weeks)",ylim=c(1,10), xlim=c(2002,2012), cex.lab=1.3,axes=F,xaxs="i",yaxs="i") axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) lines(spline(basic8CD4crypto$year,(predict(regyear))), lwd=3, col=2) @ \begin{figure} \begin{center} \caption{Median regression for time since OI by year of OI} \includegraphics[width=5 in, height=4 in, angle=0]{median-time-by-year.jpg} \end{center} \end{figure} <>= options(datadist="dd") ourknots.year <- quantile(basic8CD4crypto$year, probs=c(0.25,0.5,0.75),na.rm=TRUE) regmedtimeOIR<-with(basic8CD4crypto, Rq(timeOI/7 ~ as.factor(route) + male + rcs(year,ourknots.year) + TB + I(age/10) + cd4Enrol + site +Crypto ,tau=0.5), se="boot" ,model=TRUE) summary(regmedtimeOIR, year=c(2004,2007)) summary(regmedtimeOIR, year=c(2004,2009)) summary(regmedtimeOIR, year=c(2004,2010)) anova(regmedtimeOIR) @ <>= jpeg("adjusted-median-time-by-year.jpg",width=1200, height=1500, res=150) fitted<-Predict(regmedtimeOIR, year) with(fitted, plot(year,yhat,type="l", xlab="Year of opportunistic infection", ylim=c(1,7),xlim=c(2002,2012),ylab="Adjusted Median time to HAART (weeks)",cex.lab=1.3,axes=F,xaxs="i", yaxs="i",xaxs="i", yaxs="i")) axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) with(fitted,polygon(c(year,rev(year)),c(lower,rev(upper)), col = "grey", border = FALSE)) with(fitted,lines(year,yhat,type="s",lty=1,col="blue")) box() @ \begin{figure} \begin{center} \caption{Adjusted Median Regression for time since OI by year of OI} \includegraphics[width=5 in, height=4 in, angle=0]{adjusted-median-time-by-year.jpg} \end{center} \end{figure} %%%%%%%%%%%%%CD4 at enrol imputated <>= basic8CD4crypto$Site<-factor(basic8CD4crypto$site, levels=c('argentina','brazil','chile','honduras','mexico')) basic8CD4crypto$site<-NULL options(datadist="dd") ourknots.year <- quantile(basic8CD4crypto$year, probs=c(0.25,0.5,0.75),na.rm=TRUE) regmedtimeOIRimp<-with(basic8CD4crypto, Rq(timeOI/7 ~ as.factor(route) + male + rcs(year,ourknots.year) + TB + I(age/10) + CD4EnrolIMP + Site +Crypto ,tau=0.5), se="boot" ,model=TRUE) summary(regmedtimeOIRimp, year=c(2004,2007), Site="brazil") summary(regmedtimeOIRimp, year=c(2004,2009), Site="brazil") summary(regmedtimeOIRimp, year=c(2004,2010), Site="brazil") anova(regmedtimeOIRimp) @ <>= jpeg("adjusted-median-time-by-year-imp.jpg",width=1200, height=1500, res=150) fitted<-Predict(regmedtimeOIRimp, year,Site="brazil") with(fitted, plot(year,yhat,type="l", xlab="Year of opportunistic infection", ylim=c(1,7),xlim=c(2002,2012),ylab="Adjusted Median time to HAART (weeks).",cex.lab=1.3,axes=F,xaxs="i", yaxs="i",xaxs="i", yaxs="i")) axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) with(fitted,polygon(c(year,rev(year)),c(lower,rev(upper)), col = "grey", border = FALSE)) with(fitted,lines(year,yhat,type="s",lty=1,col="blue")) box() @ \begin{figure} \begin{center} \caption{Adjusted Median Regression for time since OI by year of OI (IMP)} \includegraphics[width=5 in, height=4 in, angle=0]{adjusted-median-time-by-year-imp.jpg} \end{center} \end{figure} \end{document} \begin{figure} \caption{} \begin{center} <>= jpeg("all_graphs-imp.jpg",width=1500, height=1200, res=150) par(mfrow = c(1, 3), mai=c(0.7,0.8,0.3,0.4)) plot(basic8CD4crypto$year,basic8CD4crypto$mediantime/7, pch=19,xlab="Year of opportunistic infection", ylab="Median time to HAART (weeks)",ylim=c(1,10), xlim=c(2002,2012), cex.lab=1.3,axes=F,xaxs="i",yaxs="i") axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) lines(spline(basic8CD4crypto$year,(predict(regyear))), lwd=3, col=2) box() fitted<-Predict(regmedtimeOIRimp, year, Site="brazil") with(fitted, plot(year,yhat,type="l", xlab="Year of opportunistic infection", ylim=c(1,7),xlim=c(2002,2012),ylab="Adjusted Median time to HAART (weeks)",cex.lab=1.3,axes=F,xaxs="i", yaxs="i",xaxs="i", yaxs="i")) axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) with(fitted,polygon(c(year,rev(year)),c(lower,rev(upper)), col = "grey", border = FALSE)) with(fitted,lines(year,yhat,type="s",lty=1,col="blue")) box() fitted<-Predict(ModelbeforeIMP, year, fun=function(x) {exp(x)/(1+exp(x))}) with(fitted, plot(year,yhat,type="l", xlab="Year of opportunistic infection", ylim=c(0,1),xlim=c(2002,2012),ylab="Estimated Probability of starting HAART within 4 weeks of OI",cex.lab=1.3,axes=F,xaxs="i", yaxs="i",xaxs="i", yaxs="i")) axis(2, cex.axis=1.5) axis(1, cex.axis=1.5) with(fitted,polygon(c(year,rev(year)),c(lower,rev(upper)), col = "grey", border = FALSE)) with(fitted,lines(year,yhat,type="s",lty=1,col="blue")) box() @ \end{center} \end{figure} \begin{figure} \begin{center} \caption{Adjusted models for time since OI by year of OI} \includegraphics[width=5 in, height=4 in, angle=0]{all_graphs-imp.jpg} \end{center} \end{figure} \end{document}