ImperialCollegeLondon / epidemia

epidemia package
https://imperialcollegelondon.github.io/epidemia/index.html
47 stars 15 forks source link

error occurred during calling the sampler; sampling not done #42

Closed Spatial-R closed 4 years ago

Spatial-R commented 4 years ago

Hello, thanks for your nice package. When running the example, we got the following errors:

SAMPLING FOR MODEL 'epidemia_base' NOW (CHAIN 1).
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: neg_binomial_2_lpmf: Location parameter[1] is -2.79714e-13, but must be > 0!
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: neg_binomial_2_lpmf: Location parameter[1] is -1.22598e-13, but must be > 0!
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: neg_binomial_2_lpmf: Location parameter[1] is -7.98887e-14, but must be > 0!
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: neg_binomial_2_lpmf: Location parameter[1] is -1.1167e-13, but must be > 0!
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: neg_binomial_2_lpmf: Location parameter[1] is -3.19876e-15, but must be > 0!
Chain 1: empty_nested() must be true before calling recover_memory()
[1] "Error in sampler$call_sampler(args_list[[i]]) : "             
[2] "  empty_nested() must be true before calling recover_memory()"
error occurred during calling the sampler; sampling not done
Stan model 'epidemia_base' does not contain samples.
Error in stanmat[, x, drop = FALSE] : incorrect number of dimensions

Is there any solution to this problem?

agandy commented 4 years ago

This looks like a problem with the starting values of the samplers. Which example are you trying to run?

Spatial-R commented 4 years ago

The running codes are as followed:

data(EuropeCovid)
# Collect args for epim
args <- EuropeCovid
args$algorithm <- "sampling"
args$group_subset <- c("Germany", "United_Kingdom")
args$sampling_args <- list(iter=1e3,seed=12345)

# model for reproduction number
args$rt <- epirt(
  formula = R(country, date) ~ schools_universities + self_isolating_if_ill + 
    public_events + lockdown + social_distancing_encouraged,
  prior = shifted_gamma(shape = 1/6, scale = 1, shift = log(1.05)/6)
)

# model for daily death observations
deaths <- epiobs(
  formula = deaths(country, date) ~ 1,
  prior_intercept = rstanarm::normal(0.01, 0.0001),
  i2o = EuropeCovid$obs$deaths$i2o,
  prior_aux = rstanarm::normal(location=10, scale=2)
)

args$obs <- list(deaths = deaths)

fit <- do.call(epim, args)

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] epidemia_0.6.0    data.table_1.12.8 EpiNow2_1.1.0     readr_1.3.1       stringi_1.4.6    
 [6] spatPomp_0.1.2    cowplot_1.0.0     ggsci_2.9         gtable_0.3.0      reshape2_1.4.3   
[11] ggplot2_3.3.0     gdata_2.18.0      pomp_2.7          tidyr_1.0.2       lubridate_1.7.4  
[16] dplyr_0.8.5      
agandy commented 4 years ago

"[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] " empty_nested() must be true before calling recover_memory()" " This seems to be a problem with stan/rstanarm and your system; See https://cran.r-project.org/web/checks/check_results_rstanarm.html for another occurrence of this.

Unfortunately we will not be able to help you with this error. Maybe try things on a different system?

aitorme commented 1 year ago

@Spatial-R seems like you may have not specified the correct exponential family and link for your model