Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alexkrohn opened this issue Feb 10, 2023 · 4 comments

Comments

@alexkrohn
Copy link

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
Copy link
Owner

jgx65 commented Feb 13, 2023

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

@alexkrohn
Copy link
Author

alexkrohn commented Feb 13, 2023

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
Copy link
Owner

jgx65 commented Feb 14, 2023

should be solved, thanks

@jgx65 jgx65 closed this as completed Feb 14, 2023
@jaflury
Copy link

jaflury commented Oct 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants