R Under development (unstable) (2024-04-23 r86473 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(epigrowthfit) > options(warn = 2L, error = if (interactive()) recover) > > latent <- c(0.026, 0.104, 0.182, 0.246, 0.318, 0.104, + 0.013, 0.004, 0.003) > m <- length(latent) > > infectious <- c(0.138, 0.462, 0.256, 0.078, 0.041, 0.007, + 0.004, 0.004, 0.006, 0.004) > n <- length(infectious) > > > ## dgi ################################################################# > > dgi1 <- function(x) dgi(x = x, latent = latent, infectious = infectious) > > stopifnot(exprs = { + ## Supported on interval [1, m + n) + identical(dgi1(c(1 - 1e-06, m + n)), c(0, 0)) + ## Constant on intervals [i, i+1) + identical(dgi1(seq_len(m + n - 1L)), + dgi1(seq_len(m + n - 1L) + runif(m + n - 1L, 0, 1))) + ## Integrates to 1 + all.equal(sum(dgi1(seq_len(m + n - 1L))), 1) + }) > > > ## rgi ################################################################# > > set.seed(411422L) > x <- rgi(1e+06L, latent = latent, infectious = infectious) > x.bin <- .bincode(x, breaks = seq_len(m + n), right = FALSE) > stopifnot(!anyNA(x.bin)) > > freqs <- tabulate(x.bin, m + n - 1L) / length(x.bin) > probs <- dgi(seq_len(m + n - 1L), latent = latent, infectious = infectious) > stopifnot(all.equal(freqs, probs, tolerance = 1e-02)) > > proc.time() user system elapsed 1.43 0.29 1.71