forked from grlurton/ImpactSimul
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
139 lines (98 loc) · 4.62 KB
/
README.Rmd
File metadata and controls
139 lines (98 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ImpactSimul
<!-- badges: start -->
<!-- badges: end -->
ImpactSimul is an Agent Based Model aimed at helping estimate the impact of an intervention in an HIV program, using a simple and tractable approach. It was first developed to estimate the impact to be expected from Solthis’ Empower II program. It is written in R.
## Installation
### Install the R package
You can install ImpactSimul from [GitHub](https://github.com/) just by running:
``` r
# install.packages("devtools")
devtools::install_github("grlurton/ImpactSimul")
```
### Install Python
To obtain epidemiological data on a country, ImpactSim uses a Python script that queries the UNAIDS database and gets standardized data. To get this running, we need to set-up a python environment and download _chromedriver_. You shouldn't have to write any line of Python and will use the script `unaids_scrap.py` which you can find under `/utils` in in this repo which you can put into the `utils` directory in your project's folder..
We suggest installing Python using Anaconda.
1. Go to https://www.anaconda.com/products/individual
2. Download the appropriate installer for your operating system.
3.Just double-click the downloaded file. In most cases, you can just keep all default options in the installer.
### Load the conda environment
To install the Python libraries you'll need for the extraction, you just need to install the conda environment `ImpactSimulEnv.yml` which you can find under `/utils` in this repo.
Once you have downloaded it, just open a terminal in the directory you have downloaded it in, and run the following code.
``` bash
conda env create -f ImpactSimulEnv.yml -n ImpactSimul
```
### Install ChromeDriver
1. Install the Chrome web browser, available on https://www.google.com/chrome/
2. Download ChromeDriver from https://chromedriver.chromium.org/downloads . Make sure you pick the driver corresponding to your version of the Chrome browser.
3. Unzip ChromeDriver, and move the file into the `utils` directory in your project's folder
## Example
``` r
library(ImpactSimul)
library("readxl")
library(dplyr)
library(yaml)
library(reticulate)
download_data <- TRUE
run_life_table <- TRUE
n_sim <- 1000
parameters_folder <-
time.unit <- 7
###############################
##### SET UP THE LIFE TABLE ###
###############################
if(run_life_table){
lt_male <- read_excel("data/lifeTables_SierraLeone.xlsx", sheet = "Male")
lt_female <- read_excel("data/lifeTables_SierraLeone.xlsx", sheet = "Male")
lt <- prep_life_tables(lt_male, lt_female, "data/ltSierraLeone.rds")
}
if(download_data){
extract_unaids("ImpactSimul", "utils/unaids_scrap.py", "Sierra Leone", "utils/chromedriver", "data/unaids_estimates/")
}
parameters_bio <- yaml.load_file("params/parameters_bio.yaml")
list_scenarios <- create_scenario_list()
#############################
### Loading external data ###
#############################
# estimates UNAIDS
data <- readRDS("data/unaids_estimates/SierraLeone/UNAIDS_estimates_SierraLeone.rds")
prop_male <- data$MeanNum[grepl(pattern = "Men aged 15 and over newly infected with HIV ",
x = data$indic)]/data$MeanNum[grepl(pattern = "Adults aged 15 and over newly infected with HIV",
x = data$indic)]
#########################
### Loading functions ###
#########################
param <- params(time.unit = time.unit)
init <- init(i.prev.male = 1,
i.prev.feml = 1,
max.inf.time = 15 * 365,
n=param$N)
for(scenario_simulation in names(list_scenarios)){
print(scenario_simulation)
assign(paste0("result_", scenario_simulation), run_simulations(init, param, scenario_simulation, intervention_start = 0, prop_male, nsteps = 52 * 5, nsim = 100))
}
## Simulation results for the different scenarios
res_0 <- summary_outcomes(result_parameters_baseline)
res_1 <- summary_outcomes(result_parameters_intervention)
## DALYs comparison for the different scenarios
DALYs_0 <- calculate_DALYs(res_0, parameters_bio, param)
DALYs_1 <- calculate_DALYs(res_1, parameters_bio, param)
hist(sample(DALYs_0$DALYs, 10000, replace=T) - sample(DALYs_1$DALYs, 10000, replace=T),
main = "DALYS averted")
## mean effect and 95% empirical confidence interval
c(mean(DALYs_0$DALYs - DALYs_1$DALYs),
quantile(DALYs_0$DALYs - DALYs_1$DALYs, .025),
quantile(DALYs_0$DALYs - DALYs_1$DALYs, .975)
)
```