Skip to content

Commit

Permalink
Fix 701 (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk authored Jul 12, 2024
1 parent fc92e60 commit a183a27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

- `epinow()` now returns the "timing" output in a "time difference"" format that is easier to understand and work with. By @jamesmbaazam in #688 and reviewed by @sbfnk.

## Bug fixes

- a bug was fixed where `forecast_secondary()` did not work with fixed delays. By @sbfnk in #717 and reviewed by @sbfnk.

## Documentation

- Updated the documentation of the dots argument of the `stan_sampling_opts()` to add that the dots are passed to `cmdstanr::sample()`. By @jamesmbaazam in #699 and reviewed by @sbfnk.
Expand Down
2 changes: 1 addition & 1 deletion R/estimate_secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ forecast_secondary <- function(estimate,

# allocate empty parameters
data <- allocate_empty(
data, c("frac_obs", "delay_param", "rep_phi"),
data, c("frac_obs", "delay_params", "rep_phi"),
n = data$n
)
data$all_dates <- as.integer(all_dates)
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-estimate_secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ params <- c(

inc_posterior <- inc$posterior[variable %in% params]

# fit model to example data with a fixed delay
inc_fixed <- estimate_secondary(inc_cases[1:60],
delays = delay_opts(Gamma(mean = 15, sd = 5, max = 30)),
verbose = FALSE
)

#### Prevalence data example ####

# make some example prevalence data
Expand Down Expand Up @@ -178,6 +184,15 @@ test_that("forecast_secondary can return values from simulated data and plot
expect_error(plot(inc_preds, new_obs = inc_cases, from = "2020-05-01"), NA)
})

test_that("forecast_secondary works with fixed delays", {
inc_preds <- forecast_secondary(
inc_fixed, inc_cases[seq(61, .N)][, value := primary]
)
expect_equal(names(inc_preds), c("samples", "forecast", "predictions"))
# validation plot of observations vs estimates
expect_error(plot(inc_preds, new_obs = inc_cases, from = "2020-05-01"), NA)
})

test_that("forecast_secondary can return values from simulated data when using
the cmdstanr backend", {
skip_on_os("windows")
Expand Down

0 comments on commit a183a27

Please sign in to comment.