Closed dani-davenport closed 7 years ago
Yes, the behaviour of tab
is no longer what you might have been used to with na.replace
. tab
does not replace missing values in a genind object, but extracts the data table from it. Check the input of hw.test
, it is most likely a genind or a loci object, not a data.frame as returned by tab
.
I think the problem is a bit more basic:
If you have dominant data, you cannot calculate Hardy-Weinberg Equilibrium. Case in point:
## Created with package reprex version 0.1.1
library("adegenet")
#> Loading required package: ade4
#>
#> /// adegenet 2.0.2 is loaded ////////////
#>
#> > overview: '?adegenet'
#> > tutorials/doc/questions: 'adegenetWeb()'
#> > bug reports/feature requests: adegenetIssues()
library("pegas")
#> Loading required package: ape
#>
#> Attaching package: 'pegas'
#> The following object is masked from 'package:ape':
#>
#> mst
#> The following object is masked from 'package:ade4':
#>
#> amova
dat <- read.table(system.file("files/AFLP.txt", package = "adegenet"), header = TRUE)
obj <- df2genind(dat, ploidy = 2, type = "PA", ncode = 1)
obj
#> /// GENIND OBJECT /////////
#>
#> // 7 individuals; 4 loci; 4 alleles; size: 4.2 Kb
#>
#> // Basic content
#> @tab: 7 x 4 matrix of allele counts
#> @loc.n.all: number of alleles per locus (range: 4-4)
#> @ploidy: ploidy of each individual (range: 2-2)
#> @type: PA
#> @call: df2genind(X = dat, ncode = 1, ploidy = 2, type = "PA")
#>
#> // Optional content
#> - empty -
obj <- obj[-4, ] # removing missing data
pop(obj) <- rep(letters[1:2], 3) # giving an arbitrary population
hw.test(obj, B = 0)
#> chi^2 df Pr(chi^2 >)
#> loc1 NA NA NA
#> loc2 NA NA NA
#> loc3 NA NA NA
#> loc4 NA NA NA
"AFLP". It did read "AFLP". My bad. Thanks @zkamvar ;)
Dear All,
I am using adegenet on AFLP-like data: Looks like...
Now trying to use hw.test and all values for more then 15,000 loci are NA. Initially I thought maybe some rows/cols of the genind@tab object may only have all 0, and was throwing off the calculations for some reason, but then shouldn't only that loci come out at NA? I tried using seppop(gemindi.obj.obj) %>% lapply(hw.test, B = 0) and was returned the same, all NA.
Am i missing something here?