diff --git a/R/borel.r b/R/borel.r index c1a44065..43125f07 100644 --- a/R/borel.r +++ b/R/borel.r @@ -39,7 +39,7 @@ rborel <- function(n, mu, infinite = Inf) { ) # Run simulations simulate_summary( - nchains = n, + ntrees = n, offspring_dist = "pois", statistic = "size", stat_max = infinite, diff --git a/R/checks.R b/R/checks.R index e43f3910..5625922a 100644 --- a/R/checks.R +++ b/R/checks.R @@ -58,13 +58,13 @@ check_serial_valid <- function(serials_dist) { } -#' Check that nchains is greater than 0 and not infinity +#' Check that `ntrees` is greater than 0 and not infinity #' -#' @param nchains Number of chains to simulate. +#' @param ntrees Number of trees to simulate. #' #' @keywords internal -check_nchains_valid <- function(nchains) { - if (!checkmate::test_count(nchains, positive = TRUE)) { - stop("`nchains` must be > 0 but less than `Inf`") +check_ntrees_valid <- function(ntrees) { + if (!checkmate::test_count(ntrees, positive = TRUE)) { + stop("`ntrees` must be > 0 but less than `Inf`") } } diff --git a/R/epichains.R b/R/epichains.R index 269f83f8..3919dcf2 100644 --- a/R/epichains.R +++ b/R/epichains.R @@ -255,7 +255,7 @@ tail.epichains <- function(x, ...) { #' @examples #' set.seed(123) #' chains <- simulate_tree( -#' nchains = 10, +#' ntrees = 10, #' statistic = "size", #' offspring_dist = "pois", #' stat_max = 10, diff --git a/R/simulate.r b/R/simulate.r index ad969219..22af4b0f 100644 --- a/R/simulate.r +++ b/R/simulate.r @@ -1,6 +1,6 @@ #' Simulate transmission trees from an initial number of infections #' -#' @param nchains Number of chains to simulate. +#' @param ntrees Number of trees to simulate. #' @param offspring_dist Offspring distribution: a character string #' corresponding to the R distribution function (e.g., "pois" for Poisson, #' where \code{\link{rpois}} is the R function to generate Poisson random @@ -20,7 +20,7 @@ #' called `n`, that returns a numeric vector of `n` randomly sampled serial #' intervals. See details. #' @param t0 Start time (if serial interval is given); either a single value -#' or a vector of same length as `nchains` (number of simulations) with +#' or a vector of same length as `ntrees` (number of simulations) with #' initial times. Defaults to 0. #' @param tf End time (if serial interval is given). #' @param ... Parameters of the offspring distribution as required by R. @@ -91,7 +91,7 @@ #' @examples #' set.seed(123) #' chains <- simulate_tree( -#' nchains = 10, +#' ntrees = 10, #' statistic = "size", #' offspring_dist = "pois", #' stat_max = 10, @@ -112,14 +112,14 @@ #' Jacob C. (2010). Branching processes: their role in epidemiology. #' International journal of environmental research and public health, 7(3), #' 1186–1204. \doi{https://doi.org/10.3390/ijerph7031204} -simulate_tree <- function(nchains, statistic = c("size", "length"), +simulate_tree <- function(ntrees, statistic = c("size", "length"), offspring_dist, stat_max = Inf, serials_dist, t0 = 0, tf = Inf, ...) { statistic <- match.arg(statistic) # Input checking - check_nchains_valid(nchains = nchains) + check_ntrees_valid(ntrees = ntrees) checkmate::assert_character(statistic) # check that offspring is properly specified @@ -153,15 +153,15 @@ simulate_tree <- function(nchains, statistic = c("size", "length"), } # Initialisations - stat_track <- rep(1, nchains) # track length or size (depending on `statistic`) #nolint - n_offspring <- rep(1, nchains) # current number of offspring - sim <- seq_len(nchains) # track chains that are still being simulated - ancestor_ids <- rep(1, nchains) # all chains start in generation 1 + stat_track <- rep(1, ntrees) # track length or size (depending on `statistic`) #nolint + n_offspring <- rep(1, ntrees) # current number of offspring + sim <- seq_len(ntrees) # track chains that are still being simulated + ancestor_ids <- rep(1, ntrees) # all chains start in generation 1 # initialise data frame to hold the transmission trees generation <- 1L tree_df <- data.frame( - chain_id = seq_len(nchains), + chain_id = seq_len(ntrees), sim_id = 1L, ancestor = NA_integer_, generation = generation @@ -190,7 +190,7 @@ simulate_tree <- function(nchains, statistic = c("size", "length"), indices <- rep(sim, n_offspring[sim]) # initialise placeholder for the number of offspring - n_offspring <- rep(0, nchains) + n_offspring <- rep(0, ntrees) # assign offspring sum to indices still being simulated n_offspring[sim] <- tapply(next_gen, indices, sum) @@ -257,7 +257,7 @@ simulate_tree <- function(nchains, statistic = c("size", "length"), structure( tree_df, - chains = nchains, + chains = ntrees, chain_type = "chains_tree", rownames = NULL, track_pop = FALSE, @@ -282,20 +282,20 @@ simulate_tree <- function(nchains, statistic = c("size", "length"), #' susceptible or partially immune population. #' @examples #' simulate_summary( -#' nchains = 10, +#' ntrees = 10, #' statistic = "size", #' offspring_dist = "pois", #' stat_max = 10, #' lambda = 2 #' ) #' @export -simulate_summary <- function(nchains, statistic = c("size", "length"), +simulate_summary <- function(ntrees, statistic = c("size", "length"), offspring_dist, stat_max = Inf, ...) { statistic <- match.arg(statistic) # Input checking - check_nchains_valid(nchains = nchains) + check_ntrees_valid(ntrees = ntrees) checkmate::assert_character(statistic) # check that offspring is properly specified @@ -313,11 +313,11 @@ simulate_summary <- function(nchains, statistic = c("size", "length"), pars <- list(...) # Initialisations - stat_track <- rep(1, nchains) ## track length or size (depending on `stat`) - n_offspring <- rep(1, nchains) ## current number of offspring - sim <- seq_len(nchains) ## track chains that are still being simulated + stat_track <- rep(1, ntrees) ## track length or size (depending on `stat`) + n_offspring <- rep(1, ntrees) ## current number of offspring + sim <- seq_len(ntrees) ## track chains that are still being simulated - ## next, simulate nchains chains + ## next, simulate ntrees chains while (length(sim) > 0) { ## simulate next generation next_gen <- do.call( @@ -335,7 +335,7 @@ simulate_summary <- function(nchains, statistic = c("size", "length"), indices <- rep(sim, n_offspring[sim]) ## initialise number of offspring - n_offspring <- rep(0, nchains) + n_offspring <- rep(0, ntrees) ## assign offspring sum to indices still being simulated n_offspring[sim] <- tapply(next_gen, indices, sum) @@ -357,7 +357,7 @@ simulate_summary <- function(nchains, statistic = c("size", "length"), stat_track, chain_type = "chains_summary", statistic = statistic, - chains = nchains, + chains = ntrees, class = c("epichains", class(stat_track)) ) } diff --git a/R/stat_likelihoods.R b/R/stat_likelihoods.R index 176494e1..af5c18b8 100644 --- a/R/stat_likelihoods.R +++ b/R/stat_likelihoods.R @@ -181,7 +181,7 @@ offspring_ll <- function(x, offspring_dist, statistic, # Simulate the chains dist <- simulate_summary( - nchains = nsim_offspring, + ntrees = nsim_offspring, offspring_dist = offspring_dist, statistic = statistic, ... diff --git a/man/aggregate.epichains.Rd b/man/aggregate.epichains.Rd index b4797d85..1582c810 100644 --- a/man/aggregate.epichains.Rd +++ b/man/aggregate.epichains.Rd @@ -25,7 +25,7 @@ Aggregate cases in \verb{} objects by "time" or "generation" \examples{ set.seed(123) chains <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, diff --git a/man/check_nchains_valid.Rd b/man/check_nchains_valid.Rd deleted file mode 100644 index 1a20e8b5..00000000 --- a/man/check_nchains_valid.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/checks.R -\name{check_nchains_valid} -\alias{check_nchains_valid} -\title{Check that nchains is greater than 0 and not infinity} -\usage{ -check_nchains_valid(nchains) -} -\arguments{ -\item{nchains}{Number of chains to simulate.} -} -\description{ -Check that nchains is greater than 0 and not infinity -} -\keyword{internal} diff --git a/man/check_ntrees_valid.Rd b/man/check_ntrees_valid.Rd new file mode 100644 index 00000000..67b8dac6 --- /dev/null +++ b/man/check_ntrees_valid.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/checks.R +\name{check_ntrees_valid} +\alias{check_ntrees_valid} +\title{Check that \code{ntrees} is greater than 0 and not infinity} +\usage{ +check_ntrees_valid(ntrees) +} +\arguments{ +\item{ntrees}{Number of trees to simulate.} +} +\description{ +Check that \code{ntrees} is greater than 0 and not infinity +} +\keyword{internal} diff --git a/man/simulate_summary.Rd b/man/simulate_summary.Rd index a453d680..71c0af9f 100644 --- a/man/simulate_summary.Rd +++ b/man/simulate_summary.Rd @@ -5,7 +5,7 @@ \title{Simulate transmission chains sizes/lengths} \usage{ simulate_summary( - nchains, + ntrees, statistic = c("size", "length"), offspring_dist, stat_max = Inf, @@ -13,7 +13,7 @@ simulate_summary( ) } \arguments{ -\item{nchains}{Number of chains to simulate.} +\item{ntrees}{Number of trees to simulate.} \item{statistic}{String; Statistic (size/length) to calculate. Used to determine stopping criteria for simulations when \code{stat_max} is finite. @@ -92,7 +92,7 @@ where \code{...} are the other arguments to \verb{simulate_*()}. \examples{ simulate_summary( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, diff --git a/man/simulate_tree.Rd b/man/simulate_tree.Rd index 568d86e3..79954c2a 100644 --- a/man/simulate_tree.Rd +++ b/man/simulate_tree.Rd @@ -5,7 +5,7 @@ \title{Simulate transmission trees from an initial number of infections} \usage{ simulate_tree( - nchains, + ntrees, statistic = c("size", "length"), offspring_dist, stat_max = Inf, @@ -16,7 +16,7 @@ simulate_tree( ) } \arguments{ -\item{nchains}{Number of chains to simulate.} +\item{ntrees}{Number of trees to simulate.} \item{statistic}{String; Statistic (size/length) to calculate. Used to determine stopping criteria for simulations when \code{stat_max} is finite. @@ -41,7 +41,7 @@ called \code{n}, that returns a numeric vector of \code{n} randomly sampled seri intervals. See details.} \item{t0}{Start time (if serial interval is given); either a single value -or a vector of same length as \code{nchains} (number of simulations) with +or a vector of same length as \code{ntrees} (number of simulations) with initial times. Defaults to 0.} \item{tf}{End time (if serial interval is given).} @@ -115,7 +115,7 @@ where \code{...} are the other arguments to \verb{simulate_*()}. \examples{ set.seed(123) chains <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, diff --git a/tests/testthat/test-checks.R b/tests/testthat/test-checks.R index d0b619f0..a9d4313b 100644 --- a/tests/testthat/test-checks.R +++ b/tests/testthat/test-checks.R @@ -12,15 +12,7 @@ test_that("Checks work", { "must be a function" ) expect_error( - check_serial_valid(function(x) rep("a", 10)), - "numeric" - ) - expect_error( - check_serial_valid(function(x) 3), - "vector of length" - ) - expect_error( - check_nchains_valid(1.1), + check_ntrees_valid(1.1), "less than" ) }) diff --git a/tests/testthat/test-epichains.R b/tests/testthat/test-epichains.R index 58daf454..1232fcb9 100644 --- a/tests/testthat/test-epichains.R +++ b/tests/testthat/test-epichains.R @@ -22,14 +22,14 @@ test_that("Simulators return epichains objects", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -38,7 +38,7 @@ test_that("Simulators return epichains objects", { ) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -85,14 +85,14 @@ test_that("print.epichains works for simulation functions", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -101,7 +101,7 @@ test_that("print.epichains works for simulation functions", { ) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -133,14 +133,14 @@ test_that("summary.epichains works as expected", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -149,7 +149,7 @@ test_that("summary.epichains works as expected", { ) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -157,7 +157,7 @@ test_that("summary.epichains works as expected", { #' Simulate case where all the chain statistics are Inf set.seed(11223) epichains_summary_all_infs <- simulate_summary( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -239,14 +239,14 @@ test_that("validate_epichains works", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -255,7 +255,7 @@ test_that("validate_epichains works", { ) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -301,14 +301,14 @@ test_that("is_chains_tree works", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -317,7 +317,7 @@ test_that("is_chains_tree works", { ) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -359,14 +359,14 @@ test_that("is_chains_summary works", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -375,7 +375,7 @@ test_that("is_chains_summary works", { ) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -402,7 +402,7 @@ test_that("aggregate.epichains method returns correct objects", { set.seed(12) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -439,7 +439,7 @@ test_that("aggregate.epichains method throws errors", { expect_error( aggregate( simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -455,7 +455,7 @@ test_that("aggregate.epichains method is numerically correct", { set.seed(12) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -463,7 +463,7 @@ test_that("aggregate.epichains method is numerically correct", { ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -508,14 +508,14 @@ test_that("head and tail print output as expected", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -551,14 +551,14 @@ test_that("head and tail return data.frames", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, diff --git a/tests/testthat/test-simulate.R b/tests/testthat/test-simulate.R index 29354fda..8cc039ab 100644 --- a/tests/testthat/test-simulate.R +++ b/tests/testthat/test-simulate.R @@ -22,14 +22,14 @@ test_that("Simulators work", { ) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 ) #' Simulate a tree of infections with serials tree_sim_raw2 <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -38,7 +38,7 @@ test_that("Simulators work", { ) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -67,7 +67,7 @@ test_that("Simulators work", { expect_true( all( simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -82,7 +82,7 @@ test_that("Simulators work", { test_that("simulate_tree throws errors", { expect_error( simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "s", statistic = "length", lambda = 0.9 @@ -91,7 +91,7 @@ test_that("simulate_tree throws errors", { ) expect_error( simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "lnorm", statistic = "length", meanlog = 0.9, @@ -101,7 +101,7 @@ test_that("simulate_tree throws errors", { ) expect_error( simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = s, statistic = "length", meanlog = 0.9, @@ -111,7 +111,7 @@ test_that("simulate_tree throws errors", { ) expect_error( simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "size", lambda = 0.9, @@ -121,7 +121,7 @@ test_that("simulate_tree throws errors", { ) expect_error( simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = c(1, 2), statistic = "length", lambda = 0.9 @@ -130,7 +130,7 @@ test_that("simulate_tree throws errors", { ) expect_error( simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "size", lambda = 0.9, @@ -143,7 +143,7 @@ test_that("simulate_tree throws errors", { test_that("simulate_summary throws errors", { expect_error( simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "s", statistic = "length", lambda = 0.9 @@ -152,7 +152,7 @@ test_that("simulate_summary throws errors", { ) expect_error( simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "lnorm", statistic = "length", meanlog = 0.9, @@ -162,7 +162,7 @@ test_that("simulate_summary throws errors", { ) expect_error( simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = s, statistic = "length", meanlog = 0.9, @@ -172,7 +172,7 @@ test_that("simulate_summary throws errors", { ) expect_error( simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = c(1, 2), statistic = "length", lambda = 0.9 @@ -226,7 +226,7 @@ test_that("simulate_tree is numerically correct", { set.seed(12) #' Simulate a tree of infections without serials tree_sim_raw <- simulate_tree( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 @@ -297,7 +297,7 @@ test_that("simulate_summary is numerically correct", { set.seed(12) #' Simulate chain statistics chain_summary_raw <- simulate_summary( - nchains = 2, + ntrees = 2, offspring_dist = "pois", statistic = "length", lambda = 0.9 diff --git a/vignettes/epichains.Rmd b/vignettes/epichains.Rmd index 1c6fbf90..6d6c979f 100644 --- a/vignettes/epichains.Rmd +++ b/vignettes/epichains.Rmd @@ -199,7 +199,7 @@ serial_func <- function(x) { } sim_tree_eg <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -222,7 +222,7 @@ mean of $0.9$. set.seed(123) simulate_summary_eg <- simulate_summary( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -269,7 +269,7 @@ serial_func <- function(n) { } sim_tree_eg <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -283,7 +283,7 @@ summary(sim_tree_eg) set.seed(123) simulate_summary_eg <- simulate_summary( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -309,7 +309,7 @@ serial_func <- function(n) { } sim_tree_eg <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, @@ -334,7 +334,7 @@ serial_func <- function(n) { } sim_tree_eg <- simulate_tree( - nchains = 10, + ntrees = 10, statistic = "size", offspring_dist = "pois", stat_max = 10, diff --git a/vignettes/interventions.Rmd b/vignettes/interventions.Rmd index 2176283f..4b445c31 100644 --- a/vignettes/interventions.Rmd +++ b/vignettes/interventions.Rmd @@ -45,7 +45,7 @@ We simulate 200 chains tracking up to 99 infections: ```{r simulate_chains} sims <- simulate_summary( - nchains = 200, offspring_dist = "nbinom", stat_max = 99, mu = 1.2, size = 0.5 + ntrees = 200, offspring_dist = "nbinom", stat_max = 99, mu = 1.2, size = 0.5 ) ``` @@ -70,7 +70,7 @@ For example, to reduce R by 25% at the population level we scale the `mu` parame ```{r simulate_chains_pop_control} sims <- simulate_summary( - nchains = 200, offspring_dist = "nbinom", stat_max = 99, mu = 0.9, size = 0.5 + ntrees = 200, offspring_dist = "nbinom", stat_max = 99, mu = 0.9, size = 0.5 ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. ggplot(data.frame(x = sims), aes(x = x)) + @@ -107,7 +107,7 @@ Having defined this, we can generate simulations as before: ```{r simulate_chains_ind_control} sims <- simulate_summary( - nchains = 200, offspring_dist = "nbinom_ind", stat_max = 99, mu = 1.2, + ntrees = 200, offspring_dist = "nbinom_ind", stat_max = 99, mu = 1.2, size = 0.5, control = 0.25 ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. @@ -137,7 +137,7 @@ This can be likened to a disease control strategy where gatherings are limited t ```{r simulate_chains_truncated} sims <- simulate_summary( - nchains = 200, offspring_dist = "nbinom_truncated", stat_max = 99, mu = 1.2, + ntrees = 200, offspring_dist = "nbinom_truncated", stat_max = 99, mu = 1.2, size = 0.5, max = 10 ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. diff --git a/vignettes/projecting_incidence.Rmd b/vignettes/projecting_incidence.Rmd index 63f9eb53..b147ff72 100644 --- a/vignettes/projecting_incidence.Rmd +++ b/vignettes/projecting_incidence.Rmd @@ -227,7 +227,7 @@ sim_chain_sizes <- lapply( seq_len(sim_rep), function(sim) { simulate_tree( - nchains = length(t0), + ntrees = length(t0), offspring_dist = "nbinom", mu = mu, size = size,