Skip to content

Commit

Permalink
Fix NA values in allele frequency vector
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m-murphy committed Jun 30, 2024
1 parent 1e9a103 commit 0c927a8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down

0 comments on commit 0c927a8

Please sign in to comment.