-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_data_packages.R
42 lines (33 loc) · 1.58 KB
/
load_data_packages.R
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
#######################################################
#### ####
#### Load data and packages for PHID mgcv tutorial ####
#### ####
#######################################################
#### Load packages ####
install.packages("pacman")
# p_load installs packages and loads them in the same step
pacman::p_load(tidyverse, data.table, mgcv, sf, mgcViz, INLA,
spdep, geobr, cowplot, pROC)
#### Load Brazilian shapefile ####
## Due to time constraints, select municipality-level data from Rio de Janeiro
# Load data from geobr package, taken from IBGE
shp <- read_municipality(code_muni = "RJ") %>%
rename(municip_code_ibge = code_muni) %>%
arrange(municip_code_ibge) %>%
# Add municipaliity index for INLA random effects
mutate(municip_index = 1:nrow(.))
#### Load epidemiological and socioeconomic data ####
## Use data from RJ 2010 - 2020
df <- fread("data/dengue_rj.csv") %>%
filter(year >= 2010) %>%
# Convert year to a factor to include as a fixed effect
mutate(fyear = factor(year),
# Create a time index value for INLA random effects
time = year - 2009,
# Create a categorical level of influence variables with labels
regic18 = factor(level18_num, levels = 1:5,
labels = c("Metropolis",
"Regional capital",
"Sub-regional centre",
"Zone centre",
"Local centre")))