composableIDModelR is an R interface to ComposableTuringIDModels.jl, the composable probabilistic infectious disease modelling package of the EpiAware ecosystem. You build a model in R from interchangeable latent process, infection and observation components, and Julia simulates from it and fits it with Turing.jl. You do not need to write any Julia, and as_julia() shows the Julia code that builds a model.

Installation

composableIDModelR needs Julia 1.12 or later. We recommend installing Julia with juliaup, which lets composableIDModelR use the Julia version its pinned dependencies were resolved with.

# install.packages("remotes")
remotes::install_github("sbfnk/composableIDModelR")

The Julia packages install on first use. To install them up front and watch the progress, run:

Quick start

Estimate the reproduction number from COVID-19 cases in South Korea, following Mishra et al. (2020): an AR(2) process on log RtR_t drives a renewal model, observed with negative binomial noise.

library(composableIDModelR)

cases <- read.csv(system.file("extdata", "south_korea_data.csv",
                              package = "composableIDModelR"))[45:80, ]

renewal <- Renewal(
  generation_time = Gamma(shape = 6.5, scale = 0.62),
  rt = AR(
    damp = list(truncated(Normal(0.8, 0.05), 0, 1),
                truncated(Normal(0.1, 0.05), 0, 1)),
    init = list(Normal(0, 0.2), Normal(0, 0.2)),
    epsilon_t = HierarchicalNormal(std = HalfNormal(0.1))
  ),
  initialisation = Normal(log(1), 0.1)
)
model <- IDModel(
  renewal,
  NegativeBinomialError(cluster_factor = HalfNormal(0.1))
)

fitted <- fit(model, cases$cases_new, dates = as.Date(cases$date))
fitted
summary(fitted)
plot(fitted, type = "Rt")
plot(fitted, type = "cases", horizon = 14)

To change an assumption, swap the component that encodes it. This model observes the same infections with Poisson noise after a reporting delay:

delayed <- IDModel(
  renewal,
  LatentDelay(PoissonError(), delay = LogNormal(1.6, 0.42))
)

julia_spec() calls any Julia constructor that has no R wrapper, and julia() inserts other Julia code, such as a function, verbatim.

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines.

License

MIT License. See LICENSE for details.

Contributors

All contributions to this project are gratefully acknowledged using the allcontributors package following the allcontributors specification. Contributions of any kind are welcome!

Code

sbfnk