R/summarize-uniform-trees.R

Defines functions summarize_cond_trees

Documented in summarize_cond_trees

## Summarize uniformly sampled trees conditional on n,x
## SKG
## April 2, 2020
## Pandemic times



#' Summarize sampled trees
#'
#' @param trees output from \code{simulate_many_bp}
#' @return data frame with the following columns
#' \describe{
#' \item{i_pos}{number of transmissions from a positive smear}
#' \item{n_pos}{number of positive smears}
#' \item{n}{cluster size}
#' }
#' @export
summarize_cond_trees <- function(trees){
  out <- trees %>% dplyr::mutate(n1 = .data$cluster_size, n_pos1 = .data$cluster_pos) %>%
    dplyr::group_by(.data$cluster_id) %>%
    dplyr::summarize(i_pos = sum(.data$n_inf[.data$smear > 0]),
                     n_pos = .data$n_pos1[1],
                     n = .data$n1[1],
                     max_g = max(.data$gen)[1])
  return(out)
}
skgallagher/TBornotTB documentation built on April 21, 2020, 1:19 p.m.