From 22112d443e345ae2e46dfc68ce23590746e7bbe9 Mon Sep 17 00:00:00 2001 From: jamesaazam Date: Mon, 4 Sep 2023 17:45:26 +0100 Subject: [PATCH] Rename serial_sampler argument to serial_dist --- R/simulate.r | 10 +++++----- man/simulate_tree_from_pop.Rd | 8 ++++---- tests/testthat/tests-sim.r | 2 +- vignettes/epichains.Rmd | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/simulate.r b/R/simulate.r index ea109275..49a294c7 100644 --- a/R/simulate.r +++ b/R/simulate.r @@ -300,7 +300,7 @@ simulate_summary <- function(nchains, statistic = c("size", "length"), #' secondary cases. Ignored if \code{offspring == "pois"}. Must be > 1 to #' avoid division by 0 when calculating the size. See details and #' \code{?rnbinom} for details on the parameterisation in Ecology. -#' @param serial_sampler The serial interval. A function that takes one +#' @param serial_dist The serial interval. A function that takes one #' parameter (`n`), the number of serial intervals to randomly sample. Value #' must be >= 0. #' @param initial_immune The number of initial immunes in the population. @@ -334,20 +334,20 @@ simulate_summary <- function(nchains, statistic = c("size", "length"), #' # Simulate with poisson offspring #' simulate_tree_from_pop( #' pop = 100, offspring_dist = "pois", -#' offspring_mean = 0.5, serial_sampler = function(x) 3 +#' offspring_mean = 0.5, serial_dist = function(x) 3 #' ) #' #' # Simulate with negative binomial offspring #' simulate_tree_from_pop( #' pop = 100, offspring_dist = "nbinom", -#' offspring_mean = 0.5, offspring_disp = 1.1, serial_sampler = function(x) 3 +#' offspring_mean = 0.5, offspring_disp = 1.1, serial_dist = function(x) 3 #' ) #' @export simulate_tree_from_pop <- function(pop, offspring_dist = c("pois", "nbinom"), offspring_mean, offspring_disp, - serial_sampler, + serial_dist, initial_immune = 0, t0 = 0, tf = Inf) { @@ -418,7 +418,7 @@ simulate_tree_from_pop <- function(pop, ## add to df if (n_offspring > 0) { ## draw serial times - new_times <- serial_sampler(n_offspring) + new_times <- serial_dist(n_offspring) if (any(new_times < 0)) { stop("Serial interval must be >= 0.") diff --git a/man/simulate_tree_from_pop.Rd b/man/simulate_tree_from_pop.Rd index c24aca50..019efc27 100644 --- a/man/simulate_tree_from_pop.Rd +++ b/man/simulate_tree_from_pop.Rd @@ -10,7 +10,7 @@ simulate_tree_from_pop( offspring_dist = c("pois", "nbinom"), offspring_mean, offspring_disp, - serial_sampler, + serial_dist, initial_immune = 0, t0 = 0, tf = Inf @@ -32,7 +32,7 @@ secondary cases. Ignored if \code{offspring == "pois"}. Must be > 1 to avoid division by 0 when calculating the size. See details and \code{?rnbinom} for details on the parameterisation in Ecology.} -\item{serial_sampler}{The serial interval. A function that takes one +\item{serial_dist}{The serial interval. A function that takes one parameter (\code{n}), the number of serial intervals to randomly sample. Value must be >= 0.} @@ -75,13 +75,13 @@ simulate_tree_from_pop() has a couple of key different from simulate_tree(): # Simulate with poisson offspring simulate_tree_from_pop( pop = 100, offspring_dist = "pois", - offspring_mean = 0.5, serial_sampler = function(x) 3 + offspring_mean = 0.5, serial_dist = function(x) 3 ) # Simulate with negative binomial offspring simulate_tree_from_pop( pop = 100, offspring_dist = "nbinom", - offspring_mean = 0.5, offspring_disp = 1.1, serial_sampler = function(x) 3 + offspring_mean = 0.5, offspring_disp = 1.1, serial_dist = function(x) 3 ) } \author{ diff --git a/tests/testthat/tests-sim.r b/tests/testthat/tests-sim.r index 30dca41a..9b5868d0 100644 --- a/tests/testthat/tests-sim.r +++ b/tests/testthat/tests-sim.r @@ -15,7 +15,7 @@ test_that("Simulators output epichains objects", { offspring_dist = "nbinom", offspring_mean = 0.5, offspring_disp = 1.1, - serial_sampler = function(x) 3 + serial_dist = function(x) 3 ), "epichains" ) diff --git a/vignettes/epichains.Rmd b/vignettes/epichains.Rmd index 1089f456..68c21807 100644 --- a/vignettes/epichains.Rmd +++ b/vignettes/epichains.Rmd @@ -91,7 +91,7 @@ tree_from_pop_pois <- simulate_tree_from_pop( pop = 1000, offspring_dist = "pois", offspring_mean = 0.5, - serial_sampler = function(x) 3 + serial_dist = function(x) 3 ) tree_from_pop_pois # print the output @@ -102,7 +102,7 @@ tree_from_pop_nbinom <- simulate_tree_from_pop( offspring_dist = "nbinom", offspring_mean = 0.5, offspring_disp = 1.1, - serial_sampler = function(x) 3 + serial_dist = function(x) 3 ) tree_from_pop_nbinom # print the output