emmanuelparadis / pegas

Population and Evolutionary Genetics Analysis System
GNU General Public License v2.0
27 stars 10 forks source link

Fst now runs in case of single population (fixes #51) #52

Closed courtiol closed 3 years ago

courtiol commented 3 years ago

This PR attempts at making Fst() run, even when a single population is provided as input:

library(pegas)
data(jaguar)
jaguar_corridor <- jaguar[jaguar$population == "Green Corridor", ]
Fst(jaguar_corridor)
      Fit Fst        Fis
FCA742   1 NaN 0.16760829
FCA723   1 NaN 0.41880342
FCA740   1 NaN 0.04946237
FCA441   1 NaN 0.30434783
FCA391   1 NaN 0.20930233
F98      1 NaN 0.02578797
F53      1 NaN 0.30612245
F124     1 NaN 0.01244813
F146     1 NaN 0.29350649
F85      1 NaN 0.18450185
F42      1 NaN 0.28625954
FCA453   1 NaN 0.25498008
FCA741   1 NaN 0.30434783

Please double check that the patch does not mess up the computation. Perhaps the NaN should be also be replaced by NAs.

emmanuelparadis commented 3 years ago

Thanks! I modified your fix a bit: Fst is NA in this case, as you suggested, and the same for Fit (or maybe we should have Fit = Fis since T = S in this case?)

Note that you have very close results with:

R> h <- H(jaguar_corridor, observed = TRUE)
R> 1 - h[, 2] / h[, 1]
    FCA742     FCA723     FCA740     FCA441     FCA391        F98        F53
0.16360294 0.41176471 0.04811715 0.29824561 0.20454545 0.02506964 0.30000000
      F124       F146        F85        F42     FCA453     FCA741
0.01209677 0.28753181 0.18018018 0.28037383 0.24951267 0.29824561