Skip to content

Commit

Permalink
Merge branch 'main' into approximate-inference-vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs authored Jul 15, 2024
2 parents c28e6da + 86da8ae commit d0effbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Imports:
posterior,
purrr,
ggridges,
here,
stats,
cli,
checkmate,
Expand Down
15 changes: 10 additions & 5 deletions tests/testthat/test-int-latent_individual.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ extract_normal_parameters_brms <- function(prior) {

test_that("epidist.epidist_latent_individual samples from the prior according to marginal Kolmogorov-Smirnov tests in the default case", { # nolint: line_length_linter.
skip_on_cran()
set.seed(1)
prior_samples <- epidist(data = prep_obs, fn = brms::brm,
sample_prior = "only")
sample_prior = "only", seed = 1)
lognormal_draws <- extract_lognormal_draws(prior_samples)
prior <- epidist_prior(data = prep_obs)
param1 <- extract_normal_parameters_brms(prior[1, ])
Expand All @@ -35,15 +36,17 @@ test_that("epidist.epidist_latent_individual samples from the prior according to

test_that("epidist.epidist_latent_individual fits and the MCMC converges in the default case", { # nolint: line_length_linter.
skip_on_cran()
fit <- epidist(data = prep_obs)
set.seed(1)
fit <- epidist(data = prep_obs, seed = 1)
expect_s3_class(fit, "brmsfit")
expect_s3_class(fit, "epidist_fit")
expect_convergence(fit)
})

test_that("epidist.epidist_latent_individual recovers the simulation settings for the delay distribution in the default case", { # nolint: line_length_linter.
skip_on_cran()
fit <- epidist(data = prep_obs)
set.seed(1)
fit <- epidist(data = prep_obs, seed = 1)
lognormal_draws <- extract_lognormal_draws(fit)
# Unclear the extent to which we should expect parameter recovery here
expect_equal(mean(lognormal_draws$meanlog), meanlog, tolerance = 0.1)
Expand Down Expand Up @@ -78,21 +81,23 @@ test_that("epidist.epidist_latent_individual Stan code compiles for an alternati

test_that("epidist.epidist_latent_individual recovers no sex effect when none is simulated", { # nolint: line_length_linter.
skip_on_cran()
set.seed(1)
prep_obs$sex <- rbinom(n = nrow(prep_obs), size = 1, prob = 0.5)
formula_sex <- epidist_formula(prep_obs, delay_central = ~ 1 + sex,
sigma = ~ 1 + sex)
fit_sex <- epidist(data = prep_obs, formula = formula_sex)
fit_sex <- epidist(data = prep_obs, formula = formula_sex, seed = 1)
draws <- posterior::as_draws_df(fit_sex$fit)
expect_equal(mean(draws$b_sex), 0, tolerance = 0.2)
expect_equal(mean(draws$b_sigma_sex), 0, tolerance = 0.2)
})

test_that("epidist.epidist_latent_individual fits and the MCMC converges for an alternative formula", { # nolint: line_length_linter.
skip_on_cran()
set.seed(1)
prep_obs$sex <- rbinom(n = nrow(prep_obs), size = 1, prob = 0.5)
formula_sex <- epidist_formula(prep_obs, delay_central = ~ 1 + sex,
sigma = ~ 1 + sex)
fit_sex <- epidist(data = prep_obs, formula = formula_sex)
fit_sex <- epidist(data = prep_obs, formula = formula_sex, seed = 1)
expect_s3_class(fit_sex, "brmsfit")
expect_s3_class(fit_sex, "epidist_fit")
expect_convergence(fit_sex)
Expand Down

0 comments on commit d0effbf

Please sign in to comment.