jgx65 / hierfstat

the hierfstat package
24 stars 14 forks source link

Basic Stats (and Ho/Hs/Fis) Require Population Name to be Numeric With A Single Population #65

Closed alexkrohn closed 1 year ago

alexkrohn commented 1 year ago

I noticed some odd behavior when there is only a single population. Ho, Hs and, by extension basic.stats, throw an error when the population name is a character instead of an integer. This only seems to happen when there is a single population. I can change my code accordingly to replace the population name with a 1 when there is only one population, but I figured I'd bring the issue to your attention.

Example:

  set.seed(24)
  df <- data.frame(pop = c(rep("B", 3), rep("C", 3)), 
                   locus1 = sample(c(0,1,2), 6, replace = TRUE), 
                   locus2 = sample(c(0,1,2), 6, replace = TRUE), 
                   locus3 = sample(c(0,1,2), 6, replace = TRUE))

  Ho(df) # Works

  df1 <- data.frame(pop = c(rep("B", 6)), 
                    locus1 = sample(c(0,1,2), 6, replace = TRUE), 
                    locus2 = sample(c(0,1,2), 6, replace = TRUE), 
                    locus3 = sample(c(0,1,2), 6, replace = TRUE))

  Ho(df1) # Gives: Error in data[dim(data)[1], 1] + 1 : non-numeric argument to binary operator

  df2 <- data.frame(pop = c(rep(1, 6)), 
                    locus1 = sample(c(0,1,2), 6, replace = TRUE), 
                    locus2 = sample(c(0,1,2), 6, replace = TRUE), 
                    locus3 = sample(c(0,1,2), 6, replace = TRUE))

  Ho(df2) # Works

  df3 <- data.frame(pop = c(rep(as.character("1"), 6)), 
                    locus1 = sample(c(0,1,2), 6, replace = TRUE), 
                    locus2 = sample(c(0,1,2), 6, replace = TRUE), 
                    locus3 = sample(c(0,1,2), 6, replace = TRUE))

  Ho(df3) # Gives: Error in data[dim(data)[1], 1] + 1 : non-numeric argument to binary operator
jgx65 commented 1 year ago

Just pushed a new version of basic.stats, problem should be solved, let me know if it works. Cheers

alexkrohn commented 1 year ago

This is close. In the above example, df2 and df3 work, but for any dataframes with >1 population (e.g. df), both basic.stats and the internal Ho and Hs fail. The error given is object dum.pop not found. I think an else{ dum.pop <- FALSE } might fix this.

sessionInfo()

R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] hierfstat_0.5-11

loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2 
jgx65 commented 1 year ago

should be solved, thanks

jaflury commented 9 months ago

Dear Jerome,

I had the same issue with the population name in basic.stats and it was resolved with the updated function, however I get the same error in boot.ppfis (error message "data[dim(data)[1], 1] + 1 : non-numeric argument to binary operator"). Unfortunately I could not figure out what needs to be changed, could you help me there?

Best, Jana