Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Imports:
purrr,
rlang,
ggplot2
URL: https://github.com/EPPIcenter/moire, https://eppicenter.github.io/moire/, https://eppicenter.ucsf.edu/resources
URL: https://github.com/EPPIcenter/moire, https://EPPIcenter.github.io/moire/, https://eppicenter.ucsf.edu/resources
BugReports: https://github.com/EPPIcenter/moire/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Suggests:
knitr,
rmarkdown,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(calculate_eda)
export(calculate_he)
export(calculate_med_allele_freqs)
export(calculate_naive_allele_frequencies)
Expand All @@ -19,6 +20,7 @@ export(simulate_sample_genotype)
export(summarize_allele_freq_fn)
export(summarize_allele_freqs)
export(summarize_coi)
export(summarize_eda)
export(summarize_effective_coi)
export(summarize_epsilon_neg)
export(summarize_epsilon_pos)
Expand All @@ -28,6 +30,8 @@ import(RcppProgress)
import(purrr)
importFrom(Rcpp,sourceCpp)
importFrom(RcppParallel,RcppParallelLibs)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_cartesian)
importFrom(ggplot2,geom_point)
Expand Down
48 changes: 47 additions & 1 deletion R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ calculate_he <- function(allele_freqs) {
return(1 - sum(allele_freqs**2))
}

#' Calcuate the expected number of distinct alleles under a given multiplicity of infection (n)
#'
#' @export
#'
#' @param allele_freqs Simplex of allele frequencies
#' @param n multiplicity of infection
calculate_eda <- function(allele_freqs, n) {
sum(1 - (1 - allele_freqs)^n)
}


#' Summarize COI
#'
#' @details Summarize complexity of infection results from MCMC. Returns
Expand Down Expand Up @@ -443,6 +454,42 @@ summarize_he <- function(mcmc_results,
return(res)
}

#' Summarize expected number of distinct alleles
#'
#' @details Summarize expected number of distinct alleles results from MCMC estimates of allele frequencies.
#' Returns a dataframe that contains summaries of the posterior distribution of expected number of distinct alleles
#'
#' @export
#'
#' @importFrom dplyr bind_rows
#' @importFrom dplyr arrange
#' @importFrom rlang .data
#'
#' @param mcmc_results Result of calling run_mcmc()
#' @param n values of multiplicity of infection to evaluate the expected number of distinct alleles
#' @param lower_quantile The lower quantile of the posterior distribution
#' to return
#' @param upper_quantile The upper quantile of the posterior distribution
#' to return
#' @param merge_chains boolean indicating that all chain results should be merged
summarize_eda <- function(mcmc_results, n, lower_quantile = .025, upper_quantile = .975, merge_chains = TRUE) {
res <- lapply(n, function(n_) {
out <- summarize_allele_freq_fn(
mcmc_results,
fn = function(x) calculate_eda(x, n_),
lower_quantile = lower_quantile,
upper_quantile = upper_quantile,
merge_chains = merge_chains
)
out$n <- n_
return(out)
}) |>
dplyr::bind_rows() |>
dplyr::arrange(.data$locus, n)

return(res)
}

names_or_idxs <- function(vec) {
if (is.null(names(vec))) {
return(sapply(seq(1, length(vec)), as.character))
Expand All @@ -451,7 +498,6 @@ names_or_idxs <- function(vec) {
}
}


#' Summarize allele frequencies
#'
#' @details Summarize individual allele frequencies from the posterior
Expand Down
16 changes: 16 additions & 0 deletions man/calculate_eda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/summarize_eda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading