Skip to content
Prev 154 / 489 Next

HWE calculation question

Hi Felipe,

Your question is simple but this is not so easy. First you need to 
convert your genind object into a loci object with as.loci. Then you can 
subset this object for each population and call hw.test() on each 
subset, but a problem is that in the "loci" class, each locus is stored 
as a factor, and I guess since you have many populations, not all 
alleles are observed in all populations. To solve this, you need to drop 
the extra levels for each subset. A way to do this is (using the jaguar 
data in pegas):

library(pegas)
data(jaguar)

for (i in levels(jaguar$population)) {
     dat <- jaguar[jaguar$population == i, ]
     for (j in attr(dat, "locicol"))
          dat[, j] <- factor(dat[, j])
     print(hw.test(dat))
}

Note that instead of printing the output of hw.test() you can store it 
in a list since this is a data frame.

HTH

Best,

Emmanuel

Le 02/03/2017 ? 17:46, Felipe Hern?ndez a ?crit :