R Code Blocks for Simulations and Figures in Manuscript by Mahiane et al 2012


This page provides links to the complete set of R Code blocks used in the investigation reported in the manuscript by Guy Mahiane et al, which describes a new method for estimating incidence from repeated age- structured prevalence data.

In order to reproduce the results in this manuscript, it is necessary to install R in your computer; you can then download and unzip the file "OnlineCode20120608" and store it in your computer. This file contains three (sub)folders: "simulated_population", "SIM_EST" and "SIM_COH".

1) Simulating the HIV epidemic

The folder "simulated_population" contains the file "simul_HIV_epidemic.r" which, when ran (we did it with R2.12.0), generates the file
"CF_pop_sizes_lnorm.RData". The file "CF_pop_sizes_lnorm.RData" itself is very important because the information on the simulated epidemic is stored
 in it: prevalence as function of age and time is available in it.

1.1) How to run "simul_HIV_epidemic.r" in the folder "simulated_population"?
To run "simul_HIV_epidemic.r", make sure that the file "mortality.r" in the (sub)folder "extrafile" ( which contains
the code for calculating the AIDS related mortality (see Supplementary materials)) is available.

Launch R and set the directory to "...OnlineCode20120608/simulated_population". Then, run the file "simul_HIV_epidemic.r" from the R console.

2) Simulating the surveys and estimations

2.1) Statistical approach (general framework)
The folder "SIM_EST/statistical_approach" contains four (sub)folders: "t7_fig1ab_4", "t15_fig1cd_4", "t21_fig1cd_4", "t28_fig1ef_4" and "t28_figS4b_4". These folders
allow obtaining the figures 2 a and b), 2 c and d), 2 e and f), 2 g and h)  and S4b, respectively. They all contain a file with the exension ".r"; running
 this file, having presumably set the directory to the current folder, generates data from surveys conducted to the corresponding phase of the 
epidemic. Thus, the files in "t7_fig1ab_4", "t15_fig1cd_4", "t21_fig1cd_4" and "t28_fig1ef_4" should be ran in order to be able to generate the graphs in Figure 2. The
 file in "t28_figS4b_4" should be ran in order to obtain the graphs in figure S-4 (b).

2.2)  Brunet and Struchiner approach (general framework) 
The folder "SIM_EST/brunet/lowess_approach" contains four (sub)folders: "t7_figS7a_4", "t15_figS7b_4", "t21_figS7b_4", "t28_figS7c_4". These folders
allow obtaining the figures 3 a and b), 3 c and d), 3 e and f), and 3 g and h), respectively. They all contain a file with the exension ".r"; running
 this file, having presumably set the directory to the current folder, generates data from surveys conducted to the corresponding phase of the 
epidemic. Thus, the ".r" files in "t7_figS7a_4", "t15_figS7b_4", "t21_figS7b_4" and "t28_figS7c_4" should be ran in order to be able to generate the graphs in Figure 3.

2.3)  Brunet and Struchiner's approach (general framework) 
The folder "SIM_EST/brunet/lowess_approach" contains four (sub)folders: "t7_figS7a_4", "t15_figS7b_4", "t21_figS7b_4", "t28_figS7c_4". These folders
allow obtaining the figures 3 a and b), 3 c and d), 3 e and f), and 3 g and h), respectively. They all contain a file with the exension ".r"; running
 this file, having presumably set the directory to the current folder, generates data from surveys conducted to the corresponding phase of the 
epidemic. Thus, the ".r" files in "t7_figS7a_4", "t15_figS7b_4", "t21_figS7b_4" and "t28_figS7c_4" should be ran in order to be able to generate the graphs in Figure 3.

2.4) Hallett's approach (general framework)
The folder "SIM_EST/compare_hallett_figS4a_4" contains four files: "boot_prev_Comhal_7_4", "boot_prev_Comhal_15_4", "boot_prev_Comhal_21_4" and "boot_prev_Comhal_28_4". 
 Running these files, having presumably set the directory to the current folder, generates data from surveys conducted to the corresponding phase of the 
epidemic and are essential for generating Figure 4. 

2.5) Log-normal smoothing (supplementary materials) 
The folder "SIM_EST/lnorm_smooth_figS3ab_4" in the folder "brunet" contains the file "boot_lnorm_t28_4.r". Running
 this file, having presumably set the directory to the current folder, should be ran in order to be able to generate the graphs in 
Figures S-3 (a and b).

2.6) Spline smoothing (supplementary materials) 
The folder "SIM_EST/spline_smooth_figS3cd_4" in the folder "brunet" contains the file "boot_spline_t28_4.r". Running
 this file, having presumably set the directory to the current folder, should be ran in order to be able to generate the graphs in 
Figures S-3 (c and d).

Required package: pspline

2.7) Comparison with Hallett's approach 
The folder "SIM_EST/compare_hallett_figS4a_4" contains the file "boot_prev_Comhal_28_4.r". Running
 this file, having presumably set the directory to the current folder, should be ran in order to be able to generate the graphs in 
Figure S-4a.


3) Generating the graphs
The folder "SIM_COH" contains 13 (sub)folders: "Figure1", "Figure2", "Figure3", "Figure 4", "Figure 5", "Figure 6", "FigureS-1", "FigureS-2", "FigureS-3", "FigureS-4", 
"FigureS-5", "FigureS-6" and "Table1". Each the first twelve folders contains one file with its name but with the extension ".r". Running these files, having
 presumably ran the corresponding simulation as indicated in 2) and set the directory to the corresponding directory, generates the desired figure.

Required packages: plotrix and rootsolve (for Figure3).

Nota: Running the files as indicated in 3) will generate the figure. Paragraph 1) and 2) are only necessary if the user wants to re-do the 
experiments. 

4) Generating Table 1
Results in the Table 1 can be generated by running the file "Table1.r" in the folder "SIM_COH/Table1". Running this file generates the file "Table1.xls"
which is an excel file containing three sheets. The sheet "Constant Incidence" contains the results reported in Table 1 while the sheets 
"Increasing Incidence" and "Decreasing Incidence" contain results of the sensitivity analysis repoted in the results section.

Required packages: rjava, xlsxjars and xlsx

 

Download the code here