NA(missing_data_per_pop)

23 views
Skip to first unread message

LUIS DAVID ENCALADA BUSTAMANTE

unread,
May 21, 2024, 8:23:28 AMMay 21
to dartR
Hello everyone. How can I know the number of NA (percentage) in a population before imputing?
Thanks,
David

Jose Luis Mijangos

unread,
May 21, 2024, 6:56:34 PMMay 21
to dartR
HI David,

One way to do it is:

library(dartRverse)
t1 <- platypus.gl
#separating populations
t1_by_pop <- seppop(t1)
#counting NAs
NAs <- lapply(t1_by_pop, function(x) {
    sum(sapply(x@gen, function(e) {
      length(e...@NA.posi)
    }))
  })
#total number of genotypes
total_geno <- nInd(t1_by_pop[[1]]) * nLoc(t1_by_pop[[1]])
# Nas by population
NAs_by_pop <-  lapply(NAs, "/" ,total_geno)


Cheers,
Luis

LUIS DAVID ENCALADA BUSTAMANTE

unread,
May 28, 2024, 10:55:10 AMMay 28
to da...@googlegroups.com
Thanks!
I used too:
#percentages

pop_data <- gl@pop

snp_data <- gl@SNPs #you_could_transform_gl_to_dataset_in_this_step

unique_pops <- unique(pop_data)

population_matrices <- list()

for (pop in unique_pops) {

  population_matrices[[pop]] <- snp_data[pop_data == pop, ]

}

na_percentages <- list()

for (pop in names(population_matrices)) {

  pop_matrix <- population_matrices[[pop]]  

  na_percentage <- sum(is.na(pop_matrix)) / (nrow(pop_matrix) * ncol(pop_matrix)) * 100

    na_percentages[[pop]] <- na_percentage

}

na_percentages



and for counting NA


pop_data <- gl@pop

snp_data <- gl@SNPs #you_could_transform_gl_to_dataset_in_this_step

unique_pops <- unique(pop_data)

population_matrices <- list()

for (pop in unique_pops) {

  population_matrices[[pop]] <- snp_data[pop_data == pop, ]

}

na_counts <- list()

for (pop in names(population_matrices)) {

  pop_matrix <- population_matrices[[pop]]

  na_count <- sum(is.na(pop_matrix))

  na_counts[[pop]] <- na_count

}

na_counts



--
You received this message because you are subscribed to the Google Groups "dartR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dartr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/f042d200-30db-4718-8d6b-6fa9b6f0e8acn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages