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 :
Hi everyone, I have used the pegas package to estimate HWE using a genind object. I got the results from chi-squared and exact test based on Monte Carlo for my whole set of loci (52 loci) across all my 29 populations. I wonder if there is any option to calculate HWE and get exact test Monte Carlo results, but for each population separately. Sorry if the question is so basic, but I would appreciate any helpful advice! Best, Felipe