Accumulate setting in EpiNow2 #886
-
Hello, I noticed there have been a lot of updates around the However, trying to use this as the data for
Any guidance on how to get the accumulate setting to accurately work in EpiNow2 1.6.1? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
Hi @nlinton It's great to see that you are already trying out the new accumulate feature. I tried to reconstruct your data and reproduce your error but I didn't get that (below). Could you provide a reprex to help us diagnose your issue? library(EpiNow2)
#>
#> Attaching package: 'EpiNow2'
#> The following object is masked from 'package:stats':
#>
#> Gamma
library(data.table)
packageVersion("EpiNow2")
#> [1] '1.6.1.9000'
data <- data.table::data.table(
date = as.Date(c("2024-08-24", "2024-08-31")),
confirm = c(2531, 2306)
)
# View the data
data
#> date confirm
#> <Date> <num>
#> 1: 2024-08-24 2531
#> 2: 2024-08-31 2306
data <- fill_missing(
data,
missing_dates = "accumulate",
initial_accumulate = 7
)
# View the data
data
#> Key: <date>
#> date confirm accumulate
#> <Date> <num> <lgcl>
#> 1: 2024-08-18 NA TRUE
#> 2: 2024-08-19 NA TRUE
#> 3: 2024-08-20 NA TRUE
#> 4: 2024-08-21 NA TRUE
#> 5: 2024-08-22 NA TRUE
#> 6: 2024-08-23 NA TRUE
#> 7: 2024-08-24 2531 FALSE
#> 8: 2024-08-25 NA TRUE
#> 9: 2024-08-26 NA TRUE
#> 10: 2024-08-27 NA TRUE
#> 11: 2024-08-28 NA TRUE
#> 12: 2024-08-29 NA TRUE
#> 13: 2024-08-30 NA TRUE
#> 14: 2024-08-31 2306 FALSE
# Specify other inputs
generation_time <- Gamma(
shape = Normal(1.3, 0.3),
rate = Normal(0.37, 0.09),
max = 14
)
incubation_period <- LogNormal(
meanlog = Normal(1.6, 0.06),
sdlog = Normal(0.4, 0.07),
max = 14
)
# set an example reporting delay. In practice this should use an estimate
# from the literature or be estimated from data
reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10)
# estimate Rt and nowcast/forecast cases by date of infection
out <- estimate_infections(
data = data,
generation_time = gt_opts(generation_time),
rt = rt_opts(prior = LogNormal(mean = 2, sd = 0.1)),
delays = delay_opts(incubation_period + reporting_delay)
)
#> ℹ As of version 1.5.0 missing dates or dates with `NA` cases are treated as
#> missing. This is in contrast to previous versions where these were
#> interpreted as dates with zero cases.
#> ℹ In order to treat missing or `NA` cases as zeroes, see solutions in
#> <https://github.com/epiforecasts/EpiNow2/issues/767#issuecomment-2348805272>
#> ℹ If the data is reported at non-daily intervals (for example weekly), consider
#> using `obs_opts(na="accumulate")`.
#> ℹ For more information on these options, see `?obs_opts`.
#> This message is displayed once every 8 hours.
#> Warning: There were 16 divergent transitions after warmup. See
#> https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
#> to find out why this is a problem and how to eliminate them.
#> Warning: Examine the pairs() plot to diagnose sampling problems
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
out$summarised
#> date variable strat type
#> <Date> <char> <char> <char>
#> 1: 2024-08-18 R <NA> estimate based on partial data
#> 2: 2024-08-19 R <NA> estimate based on partial data
#> 3: 2024-08-20 R <NA> estimate based on partial data
#> 4: 2024-08-21 R <NA> estimate based on partial data
#> 5: 2024-08-22 R <NA> estimate based on partial data
#> ---
#> 126: 2024-09-04 reported_cases <NA> forecast
#> 127: 2024-09-05 reported_cases <NA> forecast
#> 128: 2024-09-06 reported_cases <NA> forecast
#> 129: 2024-09-07 reported_cases <NA> forecast
#> 130: <NA> reporting_overdispersion <NA> <NA>
#> median mean sd lower_90 lower_50 lower_20
#> <num> <num> <num> <num> <num> <num>
#> 1: 1.9531002 1.957395 9.860917e-02 1.8060208 1.888709 1.9279919
#> 2: 1.9511507 1.956226 9.875206e-02 1.8054405 1.888070 1.9270143
#> 3: 1.9515471 1.954867 9.958806e-02 1.8015232 1.885639 1.9260132
#> 4: 1.9513628 1.953424 1.013485e-01 1.7962150 1.883408 1.9256043
#> 5: 1.9500809 1.951989 1.041336e-01 1.7857012 1.881186 1.9241806
#> ---
#> 126: 1507.0000000 2710.223500 4.015238e+03 102.9000000 595.750000 1086.2000000
#> 127: 1618.5000000 2972.081500 4.510027e+03 108.9000000 656.500000 1196.6000000
#> 128: 1801.0000000 3532.740000 6.239869e+03 123.8500000 679.750000 1312.2000000
#> 129: 2176.5000000 4148.669500 6.060557e+03 120.9500000 893.000000 1546.2000000
#> 130: 0.3560215 0.371260 1.453547e-01 0.1602343 0.266294 0.3187301
#> upper_20 upper_50 upper_90
#> <num> <num> <num>
#> 1: 1.9798608 2.0259564 2.118147
#> 2: 1.9804259 2.0254079 2.119610
#> 3: 1.9794639 2.0248136 2.118680
#> 4: 1.9793869 2.0238450 2.119698
#> 5: 1.9800565 2.0222187 2.123985
#> ---
#> 126: 2069.4000000 3311.2500000 9155.900000
#> 127: 2139.6000000 3511.2500000 9734.850000
#> 128: 2470.4000000 4082.2500000 11683.200000
#> 129: 2917.4000000 5071.7500000 14354.700000
#> 130: 0.3955891 0.4640018 0.632445 Created on 2024-12-10 with reprex v2.1.1 |
Beta Was this translation helpful? Give feedback.
-
My suspicion is perhaps it's a package version issue? I tried running the same code as @jamesmbaazam with `print(packageVersion("EpiNow2")) data <- data.table::data.table( data <- fill_missing( generation_time <- Gamma( incubation_period <- LogNormal( reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10) out <- estimate_infections( out$summarised` I received the error It seems from the posts by @jamesmbaazam this is succeeding on |
Beta Was this translation helpful? Give feedback.
The current functionality is not yet on CRAN, so you will need to install the development version from GitHub with