From 163c093a372af085c6d156c166dd6fb78e1e3ee5 Mon Sep 17 00:00:00 2001 From: Maxwell Murphy Date: Sun, 30 Jun 2024 11:43:16 -0700 Subject: [PATCH] Fix NA values in allele frequency vector (#20) The code now checks for NA values in the allele frequency vector and replaces them with 0. A warning message is displayed if NA values are detected, indicating a potential problem with the MCMC chain or loci with no diversity. --- R/summary.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/summary.R b/R/summary.R index 278fd0d..51e030f 100644 --- a/R/summary.R +++ b/R/summary.R @@ -121,6 +121,10 @@ calculate_naive_allele_frequencies <- function(data) { #' #' @param allele_freqs Simplex of allele frequencies calculate_he <- function(allele_freqs) { + if (any(is.na(allele_freqs))) { + allele_freqs <- replace(allele_freqs, which(is.na(allele_freqs)), 0) + warning("NA values detected in allele frequency vector.This may indicate a problem with the MCMC chain or there are loci with no diversity. NA values will be replaced with 0.") + } return(1 - sum(allele_freqs**2)) }