Skip to content

Commit 78fe0ac

Browse files
committed
The small districts are worse, but I still think the priors are wrong
1 parent 710c5a2 commit 78fe0ac

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

vignettes/ebola.Rmd

+59-7
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,21 @@ Sub-sample the data for speed.
178178
Use ADVI for speed.
179179

180180
```{r}
181+
set.seed(1)
182+
181183
N <- nrow(obs_cens)
182184
obs_cens <- obs_cens[complete.cases(obs_cens)]
183185
N_complete <- nrow(obs_cens)
184-
obs_cens <- obs_cens[sample(seq_len(.N), N_complete / 10, replace = FALSE)]
186+
N_complete / N
187+
obs_cens <- obs_cens[sample(seq_len(.N), N_complete / 5, replace = FALSE)]
185188
obs_prep <- as_latent_individual(obs_cens)
186189
187190
fit <- epidist::epidist(
188191
data = obs_prep,
189192
formula = brms::bf(mu ~ 1, sigma ~ 1),
190193
family = brms::lognormal(),
191-
algorithm = "laplace"
194+
algorithm = "laplace",
195+
refresh = 0
192196
)
193197
194198
summary(fit)
@@ -201,7 +205,8 @@ fit_sex <- epidist::epidist(
201205
data = obs_prep,
202206
formula = brms::bf(mu ~ 1 + sex, sigma ~ 1 + sex),
203207
family = brms::lognormal(),
204-
algorithm = "laplace"
208+
algorithm = "laplace",
209+
refresh = 0
205210
)
206211
207212
summary(fit_sex)
@@ -214,7 +219,8 @@ fit_sex_district <- epidist::epidist(
214219
data = obs_prep,
215220
formula = brms::bf(mu ~ 1 + sex + district, sigma ~ 1 + sex + district),
216221
family = brms::lognormal(),
217-
algorithm = "laplace"
222+
algorithm = "laplace",
223+
refresh = 0
218224
)
219225
220226
summary(fit_sex_district)
@@ -227,8 +233,16 @@ Posterior expectation of the delay distribution by covariate under no censoring
227233
```{r}
228234
epred_draws <- obs_prep |>
229235
as.data.frame() |>
236+
modelr::data_grid(NA) |>
237+
dplyr::mutate(obs_t = NA, pwindow_upr = NA, swindow_upr = NA) |>
230238
add_epred_draws(fit, dpar = TRUE)
231239
240+
epred_draws |>
241+
ggplot(aes(x = .epred)) +
242+
tidybayes::stat_slab() +
243+
labs(x = "Posterior expectation of the delay", y = "") +
244+
theme_minimal()
245+
232246
# We will probably want to add functionality for users to mutate these things
233247
# to the newdata themselves
234248
epred_draws_sex <- obs_prep |>
@@ -245,7 +259,7 @@ epred_draws_sex |>
245259
)
246260
) |>
247261
ggplot(aes(x = .epred, y = sex)) +
248-
stat_slab() +
262+
tidybayes::stat_slab() +
249263
labs(x = "Posterior expectation of the delay", y = "") +
250264
theme_minimal()
251265
@@ -255,9 +269,47 @@ epred_draws_sex_district <- obs_prep |>
255269
dplyr::mutate(obs_t = NA, pwindow_upr = NA, swindow_upr = NA) |>
256270
add_epred_draws(fit_sex_district, dpar = TRUE)
257271
258-
# Some strata that don't have much data?
259-
# Some very bad priors?
272+
epred_draws_sex_district |>
273+
dplyr::mutate(
274+
sex = dplyr::case_when(
275+
sex == "F" ~ "Female",
276+
sex == "M" ~ "Male"
277+
)
278+
) |>
279+
ggplot(aes(x = .epred, y = district)) +
280+
tidybayes::stat_slab() +
281+
facet_grid(. ~ sex) +
282+
labs(x = "Posterior expectation of the delay", y = "") +
283+
theme_minimal()
284+
285+
# Some strata that don't have much data? Some very bad priors?
260286
summary(epred_draws_sex_district$.epred)
287+
288+
obs_prep$district |>
289+
table()
290+
291+
epred_draws_sex_district |>
292+
dplyr::filter(district %in% c("Port Loko", "Western Urban")) |>
293+
dplyr::mutate(
294+
sex = dplyr::case_when(
295+
sex == "F" ~ "Female",
296+
sex == "M" ~ "Male"
297+
)
298+
) |>
299+
ggplot(aes(x = .epred, y = district)) +
300+
tidybayes::stat_slab() +
301+
facet_grid(. ~ sex) +
302+
labs(x = "Posterior expectation of the delay", y = "") +
303+
theme_minimal()
304+
305+
epred_draws_sex_district |>
306+
dplyr::group_by(district) |>
307+
dplyr::summarise(q90 = quantile(.epred, 0.9)) |>
308+
ggplot(aes(x = district, y = q90)) +
309+
geom_point()
310+
311+
obs_prep$district |>
312+
table()
261313
```
262314

263315
## Posterior predictions

0 commit comments

Comments
 (0)