%\VignetteIndexEntry{Instructions for Using seqDesign and Generating the Output PDF Report}
%\VignetteEngine{knitr::knitr}
%\VignetteEncoding{UTF-8}

\documentclass[11pt]{article}

\usepackage{amsmath, amsthm, amssymb}
\usepackage[cp1250]{inputenc}
\usepackage[english]{babel}
\usepackage{amsfonts}
\usepackage{multirow}
\usepackage[round,authoryear]{natbib}
\usepackage{lscape}
\usepackage{float}
\usepackage{array}
\usepackage{subfig}
\usepackage{epsfig, psfrag, graphicx, lscape}
\textwidth=6.5in
\textheight=8.4in
\setlength{\topmargin}{0.21truein}
\hoffset-18mm
\usepackage{parskip}

\begin{document}
\pagestyle{empty}
\begin{center}
{\LARGE \textbf{Instructions for Using `seqDesign' and Generating Output Tables and Figures Describing Operating Characteristics of the Trial Design}\bigskip\medskip\\
}
\end{center}
\vspace*{5mm}
\textbf{Step 1.} Specify per-arm sample sizes in the placebo and vaccine arm, average VE scenarios (the length of each component of \verb+aveVElist+ equals the number of vaccine arms in a given scenario), the annual incidence in the placebo arm, the type of estimand, the logical value for whether lagged non-efficacy monitoring should be applied (and, if TRUE, the time lag in weeks for this monitoring), and the output directory:
<<eval=FALSE, echo=TRUE, tidy=FALSE, size='footnotesize'>>=
N.pla <- 1900
N.vax <- 1700
aveVElist <- list(-2, -1.5, -1, -0.5, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, c(0,0), c(0.4,0), 
                  c(0.4,0.4), c(0.4,0.2), c(0.4,0.3), c(0.5,0.3), c(0.5,0.4), c(0.6,0.3), c(0.6,0.4))
infRate <- 0.04
estimand <- "cuminc"
laggedMonitoring <- TRUE
lagTime <- 26
outDir <- "./"
@

\textbf{Step 2.} Simulate data-sets (for each component of \verb+aveVElist+), apply the monitoring procedures, and extract results needed for generating output tables and figures:
<<eval=FALSE, echo=TRUE, tidy=FALSE, size='footnotesize'>>=
for (i in 1:length(aveVElist)){
  simTrial(N=c(N.pla, rep(N.vax, length(aveVElist[[i]]))), aveVE=c(0, aveVElist[[i]]), 
           VEmodel="half", vePeriods=c(1,27,79), enrollPeriod=78, enrollPartial=13, 
           enrollPartialRelRate=0.5, dropoutRate=0.05, infecRate=infRate, fuTime=156, 
           visitSchedule=c(0, (13/3)*(1:4), seq(13*6/3, 156, by=13*2/3)), 
           missVaccProb=c(0,0.05,0.1,0.15), VEcutoffWeek=26, nTrials=1000,
           blockSize=NULL, stage1=78, saveDir=outDir, randomSeed=9)
  
  monitorTrial(dataFile=
                 paste0("simTrial_nPlac=",N.pla,"_nVacc=",              
                        paste(rep(N.vax, length(aveVElist[[i]])), collapse="_"),
                        "_aveVE=",paste(aveVElist[[i]], collapse="_"),"_infRate=",infRate,".RData"), 
               stage1=78, stage2=156, harmMonitorRange=c(10,100), alphaPerTest=NULL, 
               nonEffStartMethod="FKG", nonEffInterval=20, lowerVEnoneff=0, upperVEnoneff=0.4, 
               stage1VE=0, lowerVEuncPower=0, highVE=0.6, alphaNoneff=0.05, alphaStage1=0.05, 
               alphaUncPower=0.05, alphaHigh=0.05, estimand=estimand, 
               laggedMonitoring=laggedMonitoring, lagTime=lagTime, saveDir=outDir)
 
  censTrial(dataFile=
              paste0("simTrial_nPlac=",N.pla, "_nVacc=",
                     paste(rep(N.vax, length(aveVElist[[i]])), collapse="_"),"_aveVE=", 
                     paste(aveVElist[[i]], collapse="_"),"_infRate=",infRate,".RData"),
            monitorFile=
              paste0("monitorTrial_nPlac=", N.pla, "_nVacc=",
                     paste(rep(N.vax, length(aveVElist[[i]])), collapse="_"),"_aveVE=", 
                     paste(aveVElist[[i]], collapse="_"),"_infRate=",infRate,"_",estimand,".RData"),
            stage1=78, stage2=156, saveDir=outDir)
  
  if (i %in% 17:22){
    rankTrial(censFile=
                paste0("trialDataCens_nPlac=",N.pla,"_nVacc=",
                       paste(rep(N.vax, length(aveVElist[[i]])), collapse="_"),"_aveVE=",
                       paste(aveVElist[[i]], collapse="_"),"_infRate=",infRate,"_",estimand,".RData"),
              idxHighestVE=1, headHead=matrix(1:2, nrow=1, ncol=2), lowerVE=0, stage1=78, stage2=156, 
              alpha=0.05, saveDir=outDir)
  }
}

VEpowerPP(dataList=
            as.list(paste0("trialDataCens_nPlac=", N.pla, "_nVacc=", N.vax, "_aveVE=", 
                           do.call("c", aveVElist[5:13]), "_infRate=",infRate,"_",estimand,".RData")),
          lowerVEuncPower=0, alphaUncPower=0.05, VEcutoffWeek=26, stage1=78, 
          outName=paste0("VEpwPP_nPlac=", N.pla, "_nVacc=", N.vax, "_infRate=",infRate,".RData"),
          saveDir=outDir)
@

\textbf{Step 3.} Look up the vignette titled ``seqDesign's Report Template" by, e.g., calling
<<eval=FALSE, echo=TRUE, tidy=FALSE>>=
browseVignettes(package="seqDesign")
@

The vignette's source contains .Rnw template code for generating the report, and the vignette's PDF is the compiled template code (note that it is a static PDF because the .Rnw source requires seqDesign's .RData output files to be compiled and those are not part of the package, the user generates them in Step~2). Update the user-specified constants in the first R chunk and compile the PDF report. Note that other changes in table/figure captions, legends and labels might be needed to reflect the specified trial design.

\end{document}