From 20ed5d233d16f966937c634f09d54b605e29f247 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Thu, 27 Apr 2023 22:49:30 +0100 Subject: [PATCH 1/2] default to neg bin obs model --- R/create.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/create.R b/R/create.R index 7f5e8789f..6ef9ce2fc 100644 --- a/R/create.R +++ b/R/create.R @@ -396,7 +396,7 @@ create_gp_data <- function(gp = gp_opts(), data) { #' create_obs_model(obs_opts(week_length = 3), dates = dates) create_obs_model <- function(obs = obs_opts(), dates) { data <- list( - model_type = as.numeric(obs$family %in% "poisson"), + model_type = as.numeric(obs$family %in% "negbin"), phi_mean = obs$phi[1], phi_sd = obs$phi[2], week_effect = ifelse(obs$week_effect, obs$week_length, 1), From 35fd1d77caf955bcdf46323fa0790644875aec47 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Thu, 27 Apr 2023 22:49:57 +0100 Subject: [PATCH 2/2] forecast correct part of cases in test/example --- R/estimate_secondary.R | 6 ++++-- man/estimate_secondary.Rd | 6 ++++-- tests/testthat/test-estimate_secondary.R | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/R/estimate_secondary.R b/R/estimate_secondary.R index 1e9a6a59d..451bd8400 100644 --- a/R/estimate_secondary.R +++ b/R/estimate_secondary.R @@ -88,7 +88,9 @@ #' plot(inc, primary = TRUE) #' #' # forecast future secondary cases from primary -#' inc_preds <- forecast_secondary(inc, cases[seq_len(.N)][, value := primary]) +#' inc_preds <- forecast_secondary( +#' inc, cases[seq(61, .N)][, value := primary] +#' ) #' plot(inc_preds, new_obs = cases, from = "2020-05-01") #' #' #### Prevalence data example #### @@ -116,7 +118,7 @@ #' #' # forecast future secondary cases from primary #' prev_preds <- forecast_secondary( -#' prev, cases[10seq_len(.N)][, value := primary] +#' prev, cases[seq(101, .N)][, value := primary] #' ) #' plot(prev_preds, new_obs = cases, from = "2020-06-01") #' diff --git a/man/estimate_secondary.Rd b/man/estimate_secondary.Rd index 4ba8aa211..720262ed4 100644 --- a/man/estimate_secondary.Rd +++ b/man/estimate_secondary.Rd @@ -112,7 +112,9 @@ inc <- estimate_secondary(cases[1:60], plot(inc, primary = TRUE) # forecast future secondary cases from primary -inc_preds <- forecast_secondary(inc, cases[seq_len(.N)][, value := primary]) +inc_preds <- forecast_secondary( + inc, cases[seq(61, .N)][, value := primary] +) plot(inc_preds, new_obs = cases, from = "2020-05-01") #### Prevalence data example #### @@ -140,7 +142,7 @@ plot(prev, primary = TRUE) # forecast future secondary cases from primary prev_preds <- forecast_secondary( - prev, cases[10seq_len(.N)][, value := primary] + prev, cases[seq(101, .N)][, value := primary] ) plot(prev_preds, new_obs = cases, from = "2020-06-01") diff --git a/tests/testthat/test-estimate_secondary.R b/tests/testthat/test-estimate_secondary.R index 909aa5479..e155a913b 100644 --- a/tests/testthat/test-estimate_secondary.R +++ b/tests/testthat/test-estimate_secondary.R @@ -97,7 +97,7 @@ test_that("estimate_secondary can recover simulated parameters", { test_that("forecast_secondary can return values from simulated data and plot them", { - inc_preds <- forecast_secondary(inc, cases[seq_len(.N)][, value := primary]) + inc_preds <- forecast_secondary(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 = cases, from = "2020-05-01"), NA)