generated from r4ds/bookclub-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
10_disease-risk-modeling.Rmd
281 lines (211 loc) · 6.62 KB
/
10_disease-risk-modeling.Rmd
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Disease risk modeling
**Learning objectives:**
- how to model disease risk
- how to map disease risk
## Introduction
- Bayesian spatial models have been used to understand geographic patterns and risk factors of childhood overweight and obesity prevalence in Costa Rica (Gómez et al. 2023), and mosquito-borne diseases in Brazil (Pavani, Bastos, and Moraga 2023).
- Spatial methods can also be extended to analyze areal data that are both spatially and temporally referenced.
## Modeling of lung cancer risk in Pennsylvania
Bayesian spatial model to estimate the risk of lung cancer and assess its relationship with smoking in Pennsylvania, USA, in 2002.
```{r message=FALSE, warning=FALSE}
library(tidyverse)
library(SpatialEpi)
data(pennLC)
names(pennLC)
```
```{r message=FALSE, warning=FALSE}
head(pennLC$data)
```
```{r}
library(sf)
map <- st_as_sf(pennLC$spatial.polygon)
countynames <- sapply(slot(pennLC$spatial.polygon, "polygons"),
function(x){slot(x, "ID")})
map$county <- countynames
head(map)
```
```{r}
d <- group_by(pennLC$data, county) %>%
summarize(Y = sum(cases))
head(d)
```
```{r}
p1 <- map %>%
right_join(d, by = c("county" = "county")) %>%
ggplot()+
geom_sf(aes(fill=Y), color="navy")+
scale_fill_continuous(low="white", high="navy")+
geom_sf_text(aes(label=county,alpha=Y,color="orange"), size=2)+
coord_sf()+
labs(title = "Lung cancer cases",
subtitle = "Pennsylvania 1990-1994",
caption = "Source: PennLC data",
fill = "Cases")+
theme_minimal()
p1
```
### Expected cases
$$
E_i = \sum_{j=1}^m r_j^{(s)} n_j^{(s)}
$$
where $r_j^{(s)}$ is the rate of disease in stratum $j$ and $n_j^{(s)}$ is the population in stratum $j$.
```{r}
pennLC$data <- pennLC$data[order(pennLC$data$county,
pennLC$data$race,
pennLC$data$gender,
pennLC$data$age), ]
E <- expected(population = pennLC$data$population,
cases = pennLC$data$cases,
# 2 races, 2 genders, and 4 age groups (2×2×4 = 16)
n.strata = 16)
d$E <- E
head(d)
```
Let's visualize the difference between observed and expected cases.
```{r message=FALSE, warning=FALSE}
map %>%
right_join(d, by = c("county" = "county")) %>%
pivot_longer(cols = c("Y", "E"),
names_to = "type",
values_to = "value") %>%
mutate(value=round(value))%>%
ggplot()+
geom_sf(aes(fill=value), color="navy")+
scale_fill_continuous(low="white", high="navy")+
geom_sf_text(aes(label=value,
alpha=value,
color="orange"),
fontface="bold",
size=2)+
coord_sf()+
facet_wrap(~type)+
guides(fill = guide_colorbar(title = "Cases"),alpha="none",color="none")+
labs(title = "Lung cancer Observed and Expected cases",
subtitle = "Pennsylvania 1990-1994",
caption = "Source: PennLC data",
fill = "Type")+
theme_minimal()+
theme(axis.text = element_blank(),
axis.title = element_blank(),
legend.position = "bottom")
```
### Standardized Mortality Ratios
$$
SMR_i = \frac{Y_i}{E_i}
$$
if $SMR_i > 1$, then the county has more cases than expected, and if $SMR_i < 1$, then the county has fewer cases than expected.
```{r}
# add the smoking data
d <- dplyr::left_join(d, pennLC$smoking, by = "county")
d$SMR <- d$Y/d$E
head(d)
```
```{r message=FALSE, warning=FALSE}
ggplot(d, aes(x=smoking, y=SMR))+
geom_point(aes(color=smoking))+
geom_smooth(se=FALSE)+
labs(title = "Lung cancer SMR vs Smoking",
subtitle = "Pennsylvania 1990-1994",
caption = "Source: PennLC data",
x = "Smoking",
y = "SMR")+
theme_minimal()
```
```{r}
map <- dplyr::left_join(map, d, by = "county")
```
```{r message=FALSE, warning=FALSE}
map %>%
ggplot()+
geom_sf(aes(fill=SMR), color="navy")+
scale_fill_continuous(low="white", high="navy")+
geom_sf_text(aes(label=county,
alpha=SMR,
color="orange"),
size=2)+
coord_sf()+
guides(fill = guide_colorbar(title = "Cases"),
alpha="none",
color="none")+
labs(title = "Lung cancer SMR",
subtitle = "Pennsylvania 1990-1994",
caption = "Source: PennLC data",
fill = "SMR")+
theme_minimal()
```
## Modeling diseased risk
$$
Y_i| \theta_i \sim Poisson(E_i \times \theta_i)
$$
where
- $\theta_i$ is the **relative risk** for county $i$,
- $u_i$ is the **structured random effect** for county $i$ modeled with an intrinsic conditional autoregressive (ICAR) model,
$$
u_i|u_{-i} \sim N(\bar{u}_{\delta_i} \frac{1}{\tau_u n_{\delta_i}})
$$
- $v_i$ is the random effect for stratum $i$
$$
v_i \sim N(0, \frac{1}{\tau_v})
$$
### Neighborhood structure
```{r message=FALSE, warning=FALSE}
library(spdep)
library(INLA)
nb <- poly2nb(map)
nb2INLA("map.adj", nb)
g <- inla.read.graph(filename = "map.adj")
```
### Model
```{r}
map$re_u <- 1:nrow(map)
map$re_v <- 1:nrow(map)
```
```{r}
formula <- Y ~ smoking +
f(re_u,
model = "besag",
graph = g,
scale.model = TRUE) +
f(re_v, model = "iid")
```
```{r eval=FALSE}
res <- inla(formula,
family = "poisson",
data = map,
E = E,
control.predictor = list(compute = TRUE),
control.compute = list(return.marginals.predictor = TRUE))
```
res$summary.fixed
mean sd 0.025quant 0.5quant
(Intercept) -0.3235 0.1498 -0.61925 -0.3233
smoking 1.1546 0.6226 -0.07569 1.1560
0.975quant mode kld
(Intercept) -0.02877 -0.3234 3.534e-08
smoking 2.37845 1.1563 3.545e-08
### Relative Risk
res$summary.fitted.values[1:3, ]
mean sd 0.025quant 0.5quant
fitted.Predictor.01 0.8781 0.05808 0.7648 0.8778
fitted.Predictor.02 1.0597 0.02750 1.0072 1.0592
fitted.Predictor.03 0.9646 0.05089 0.8604 0.9657
0.975quant mode
fitted.Predictor.01 0.9936 0.8778
fitted.Predictor.02 1.1150 1.0582
fitted.Predictor.03 1.0622 0.9681
# relative risk
map$RR <- res$summary.fitted.values[, "mean"]
# lower and upper limits 95% CI
map$LL <- res$summary.fitted.values[, "0.025quant"]
map$UL <- res$summary.fitted.values[, "0.975quant"]
See the map here:
<https://www.paulamoraga.com/book-spatial/disease-risk-modeling.html#mapping-smr>
## Meeting Videos {-}
### Cohort 1 {-}
`r knitr::include_url("https://www.youtube.com/embed/URL")`
<details>
<summary> Meeting chat log </summary>
```
LOG
```
</details>