Skip to content

Commit

Permalink
add note about direct usage failing but tidybayes working
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Nov 20, 2024
1 parent 6302ac9 commit b246737
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
11 changes: 4 additions & 7 deletions tests/testthat/test-gen.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ test_that("epidist_gen_posterior_predict returns a function that predicts delays
test_that("epidist_gen_posterior_epred returns a function that creates arrays with correct dimensions", { # nolint: line_length_linter.
skip_on_cran()
# Test lognormal
prep <- brms::prepare_predictions(fit)
epred_fn <- epidist_gen_posterior_epred(lognormal())
epred <- epred_fn(prep)
expect_setequal(class(epred), c("matrix", "array"))
expect_identical(nrow(epred), prep$ndraws)
expect_identical(ncol(epred), length(prep$data$Y))
expect_gte(min(epred), 0)
epred <- prep_obs |>
tidybayes::add_epred_draws(fit)
expect_equal(mean(epred$.epred), 5.97, tolerance = 0.1)
expect_gte(min(epred$.epred), 0)

# Test gamma
prep_gamma <- brms::prepare_predictions(fit_gamma)
Expand Down
6 changes: 2 additions & 4 deletions tests/testthat/test-latent_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ test_that("epidist_gen_log_lik_latent returns a function that produces valid log
# Test lognormal
prep <- brms::prepare_predictions(fit)
i <- 1
family <- epidist_family(data = prep_obs, family = lognormal())
log_lik_fn <- epidist_gen_log_lik_latent(family)
log_lik_fn <- epidist_gen_log_lik_latent(lognormal())
log_lik <- log_lik_fn(i = i, prep)
expect_length(log_lik, prep$ndraws)
expect_false(anyNA(log_lik))
expect_true(all(is.finite(log_lik)))

# Test gamma
prep_gamma <- brms::prepare_predictions(fit_gamma)
family_gamma <- epidist_family(data = prep_obs, family = Gamma())
log_lik_fn_gamma <- epidist_gen_log_lik_latent(family_gamma)
log_lik_fn_gamma <- epidist_gen_log_lik_latent(Gamma())
log_lik_gamma <- log_lik_fn_gamma(i = i, prep_gamma)
expect_length(log_lik_gamma, prep_gamma$ndraws)
expect_false(anyNA(log_lik_gamma))
Expand Down
3 changes: 0 additions & 3 deletions vignettes/ebola.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ Figure \@ref(fig:epred)B illustrates the higher mean of men as compared with wom

```{r}
epred_draws <- obs_prep |>
as.data.frame() |>
data_grid(NA) |>
mutate(relative_obs_time = NA, pwindow = NA, swindow = NA) |>
add_epred_draws(fit, dpar = TRUE)
Expand All @@ -332,7 +331,6 @@ epred_base_figure <- epred_draws |>
theme_minimal()
epred_draws_sex <- obs_prep |>
as.data.frame() |>
data_grid(sex) |>
mutate(relative_obs_time = NA, pwindow = NA, swindow = NA) |>
add_epred_draws(fit_sex, dpar = TRUE)
Expand All @@ -344,7 +342,6 @@ epred_sex_figure <- epred_draws_sex |>
theme_minimal()
epred_draws_sex_district <- obs_prep |>
as.data.frame() |>
data_grid(sex, district) |>
mutate(relative_obs_time = NA, pwindow = NA, swindow = NA) |>
add_epred_draws(fit_sex_district, dpar = TRUE)
Expand Down

0 comments on commit b246737

Please sign in to comment.