jgx65 / hierfstat

the hierfstat package
24 stars 14 forks source link

pairwise.WCfst(genind2hierfstat(x)) and genet.dist(x, method = "WC84") do not yield the same result #57

Closed DaniEstevezBarcia closed 2 years ago

DaniEstevezBarcia commented 2 years ago

Hi,

I have just realized that these two functions do not give the same result when they both should be providing (according to the descriptions) pairwise estimated of Fst following Weir and Cockerham 1984.

Best regards

jgx65 commented 2 years ago

I'm puzzled, it does for me? (see below). Could you provide an example?

> library(hierfstat)
> data(gtrunchier)
> pairwise.WCfst(gtrunchier[,-2])
          1         2         3         4
1        NA 0.4695425 0.4194788 0.4486061
2 0.4695425        NA 0.7795719 0.7648904
3 0.4194788 0.7795719        NA 0.6321912
4 0.4486061 0.7648904 0.6321912        NA
5 0.3356973 0.5994008 0.5688411 0.5199231
6 0.3992087 0.7563057 0.5308519 0.4776794
          5         6
1 0.3356973 0.3992087
2 0.5994008 0.7563057
3 0.5688411 0.5308519
4 0.5199231 0.4776794
5        NA 0.5065197
6 0.5065197        NA

> genet.dist(gtrunchier[,-2],method="WC84")
          1         2         3         4         5
2 0.4695425                                        
3 0.4194788 0.7795719                              
4 0.4486061 0.7648904 0.6321912                    
5 0.3356973 0.5994008 0.5688411 0.5199231          
6 0.3992087 0.7563057 0.5308519 0.4776794 0.5065197
DaniEstevezBarcia commented 2 years ago

do you add the [, -2] to remove the population column?

DaniEstevezBarcia commented 2 years ago

Also, in the genet.dist option I used a genind object. When changed to hierfstat it works, but I thought it also did with genind (it does actually provide a result but it is different)

jgx65 commented 2 years ago

gtuncatula contains 2 populations column (hierarchical design), the [,-2] is just to remove one of them. With nancycats, the following give me TRUE:

all.equal(mat2vec(pairwise.WCfst(genind2hierfstat(nancycats))),mat2vec(as.matrix(genet.dist(nancycats,method="WC84"))))

jgx65 commented 2 years ago

Note that if you update hierfstat with the current version on github, you won't need the extra genind2hierfstat in pairwise.WCfst (see https://github.com/jgx65/hierfstat/issues/56)

DaniEstevezBarcia commented 2 years ago

The new version is not on cran yet right?

Thank you for the answers

jgx65 commented 2 years ago

no, on github

DaniEstevezBarcia commented 2 years ago

Ok, the problem was that the version on cran for some reason was doing something odd with the genind (it did not return error though). With the github version it works.