From f46b0011d81904803fd54c30a4bcb1bfab2c0627 Mon Sep 17 00:00:00 2001 From: jamesaazam Date: Mon, 4 Dec 2023 15:27:38 +0000 Subject: [PATCH] Return offspring as part of object --- R/epichains.R | 12 ++++++++++++ R/simulate.r | 3 +++ man/epichains_summary.Rd | 6 ++++++ man/epichains_tree.Rd | 6 ++++++ man/new_epichains_summary.Rd | 6 ++++++ man/new_epichains_tree.Rd | 6 ++++++ 6 files changed, 39 insertions(+) diff --git a/R/epichains.R b/R/epichains.R index 1098eb7f..a4955e64 100644 --- a/R/epichains.R +++ b/R/epichains.R @@ -19,6 +19,7 @@ new_epichains_tree <- function(tree_df, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer(), track_pop = logical()) { # Assemble the elements of the object @@ -26,6 +27,7 @@ new_epichains_tree <- function(tree_df, tree_df, ntrees = ntrees, statistic = statistic, + offspring_dist = offspring_dist, stat_max = stat_max, track_pop = track_pop, class = c("epichains_tree", class(tree_df)) @@ -58,12 +60,15 @@ new_epichains_tree <- function(tree_df, epichains_tree <- function(tree_df, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer(), track_pop = logical()) { # Check that inputs are well specified checkmate::assert_data_frame(tree_df) checkmate::assert_integerish(ntrees, null.ok = TRUE) checkmate::assert_character(statistic, null.ok = TRUE) + check_offspring_valid(offspring_dist) + check_offspring_func_valid(paste0("r", offspring_dist)) checkmate::assert_logical(track_pop) checkmate::assert_number(stat_max, null.ok = TRUE) @@ -72,6 +77,7 @@ epichains_tree <- function(tree_df, tree_df = tree_df, ntrees = ntrees, statistic = statistic, + offspring_dist = offspring_dist, stat_max = stat_max, track_pop = track_pop ) @@ -103,12 +109,14 @@ epichains_tree <- function(tree_df, new_epichains_summary <- function(chains_summary, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer()) { # Assemble the elements of the object obj <- structure( chains_summary, ntrees = ntrees, statistic = statistic, + offspring_dist = offspring_dist, stat_max = stat_max, class = c("epichains_summary", class(chains_summary)) ) @@ -133,11 +141,14 @@ new_epichains_summary <- function(chains_summary, epichains_summary <- function(chains_summary, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer()) { # Check that inputs are well specified checkmate::assert_vector(chains_summary) checkmate::assert_integerish(ntrees, null.ok = TRUE) checkmate::assert_character(statistic) + check_offspring_valid(offspring_dist) + check_offspring_func_valid(paste0("r", offspring_dist)) checkmate::assert_number(stat_max, null.ok = TRUE) # Create object @@ -145,6 +156,7 @@ epichains_summary <- function(chains_summary, chains_summary, ntrees = ntrees, statistic = statistic, + offspring_dist = offspring_dist, stat_max = stat_max ) diff --git a/R/simulate.r b/R/simulate.r index 06e4bf0a..b899f3f6 100644 --- a/R/simulate.r +++ b/R/simulate.r @@ -242,6 +242,7 @@ simulate_tree <- function(ntrees, statistic = c("size", "length"), tree_df = tree_df, ntrees = ntrees, statistic = statistic, + offspring_dist = offspring_dist, stat_max = stat_max, track_pop = FALSE ) @@ -339,6 +340,7 @@ simulate_summary <- function(ntrees, statistic = c("size", "length"), chains_summary = stat_track, ntrees = ntrees, statistic = statistic, + offspring_dist = offspring_dist, stat_max = stat_max ) @@ -552,6 +554,7 @@ simulate_tree_from_pop <- function(pop, tree_df, ntrees = NULL, statistic = NULL, + offspring_dist = offspring_dist, stat_max = NULL, track_pop = TRUE ) diff --git a/man/epichains_summary.Rd b/man/epichains_summary.Rd index cfe5f290..adb2e31c 100644 --- a/man/epichains_summary.Rd +++ b/man/epichains_summary.Rd @@ -8,6 +8,7 @@ epichains_summary( chains_summary, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer() ) } @@ -24,6 +25,11 @@ Can be one of: \item "length": the total number of infectors. }} +\item{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 +numbers).} + \item{stat_max}{A cut off for the chain statistic (size/length) being computed. Results above the specified value, are set to this value. Defaults to \code{Inf}.} diff --git a/man/epichains_tree.Rd b/man/epichains_tree.Rd index 553efa36..e1389f60 100644 --- a/man/epichains_tree.Rd +++ b/man/epichains_tree.Rd @@ -8,6 +8,7 @@ epichains_tree( tree_df, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer(), track_pop = logical() ) @@ -27,6 +28,11 @@ Can be one of: \item "length": the total number of infectors. }} +\item{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 +numbers).} + \item{stat_max}{A cut off for the chain statistic (size/length) being computed. Results above the specified value, are set to this value. Defaults to \code{Inf}.} diff --git a/man/new_epichains_summary.Rd b/man/new_epichains_summary.Rd index 3b55586c..2a2301d0 100644 --- a/man/new_epichains_summary.Rd +++ b/man/new_epichains_summary.Rd @@ -8,6 +8,7 @@ new_epichains_summary( chains_summary, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer() ) } @@ -24,6 +25,11 @@ Can be one of: \item "length": the total number of infectors. }} +\item{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 +numbers).} + \item{stat_max}{A cut off for the chain statistic (size/length) being computed. Results above the specified value, are set to this value. Defaults to \code{Inf}.} diff --git a/man/new_epichains_tree.Rd b/man/new_epichains_tree.Rd index d321d100..0646ca72 100644 --- a/man/new_epichains_tree.Rd +++ b/man/new_epichains_tree.Rd @@ -8,6 +8,7 @@ new_epichains_tree( tree_df, ntrees = integer(), statistic = character(), + offspring_dist = character(), stat_max = integer(), track_pop = logical() ) @@ -27,6 +28,11 @@ Can be one of: \item "length": the total number of infectors. }} +\item{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 +numbers).} + \item{stat_max}{A cut off for the chain statistic (size/length) being computed. Results above the specified value, are set to this value. Defaults to \code{Inf}.}