Coder Social home page Coder Social logo

Comments (3)

jbracher avatar jbracher commented on June 28, 2024 2

Thanks @seabbs, the example worked without errors. Will let you know in case I have more issue. Also thanks for tweaking the code!

from epinowcast.

seabbs avatar seabbs commented on June 28, 2024

Thanks Johannes, this certainly seems like a bug related to the recent issues with cmdstan initialisation.

I'll investigate the reprex (thank you) and circle back.

from epinowcast.

seabbs avatar seabbs commented on June 28, 2024

Yup this was another initialisation issue. Thank you for reporting.

I slightly tweaked your code to make it a little simpler (I don't think your reporting model was very sensible in most settings I can imagine as it had a group-specific hazard intercept on top of group-specific log normal delay)).

# Load data.table and ggplot2
library(data.table)

# Use 2 cores
options(mc.cores = 2)

# Load and filter germany hospitalisations
nat_germany_hosp <-
  germany_covid19_hosp[location == "DE"][age_group %in% c("00+", "80+")]
nat_germany_hosp <- enw_filter_report_dates(
  nat_germany_hosp,
  latest_date = "2021-10-01"
)
# Make sure observations are complete
nat_germany_hosp <- enw_complete_dates(
  nat_germany_hosp,
  by = c("location", "age_group")
)
# Make a retrospective dataset
retro_nat_germany <- enw_filter_report_dates(
  nat_germany_hosp,
  remove_days = 40
)
retro_nat_germany <- enw_filter_reference_dates(
  retro_nat_germany,
  include_days = 40
)
# Get latest observations for the same time period
latest_obs <- enw_latest_data(nat_germany_hosp)
latest_obs <- enw_filter_reference_dates(
  latest_obs,
  remove_days = 40, include_days = 20
)
# Preprocess observations (note this maximum delay is likely too short)
pobs <- enw_preprocess_data(retro_nat_germany, by = "age_group", max_delay = 20)

# set reference time indexed reporting process model
reference_module <- enw_reference(
  ~ 1 + (1 | .group), distribution = "lognormal", data = pobs
)

# set reporting time indexed reporting process model
report_module <- enw_report(~ 1, data = pobs)

# set expectation module
expectation_module <- enw_expectation(
  ~ rw(week, by = .group),
  observation = ~ (1 | day_of_week:.group),
  data = pobs
)

# Fit the nowcast model and produce a nowcast
# Note that we have reduced samples for this example to reduce runtimes
nowcast <- epinowcast(pobs,
                      reference = reference_module,
                      report = report_module,
                      expectation = expectation_module,
                      fit = enw_fit_opts(
                        save_warmup = FALSE, pp = TRUE,
                        chains = 2, iter_warmup = 500, iter_sampling = 500,
                        max_treedepth = 12, adapt_delta = 0.95
                      )
)

plot(nowcast, latest_obs) + facet_wrap(vars(age_group), scales = "free")

The code for this is on seabbs/seabbs/issue281 - just assembling some unit tests for this now and then will PR.

FYI if you use multi-threading on this model you should get a linear speed up. Also the performance of daily random walks leaves a lot to be desired. Happy to hear suggests for improvements but ultimately likely needs a lot of profiling to work out how to do better.

from epinowcast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.