MesserLab / SLiM

SLiM is a genetically explicit forward simulation software package for population genetics and evolutionary biology. It is highly flexible, with a built-in scripting language, and has a cross-platform graphical modeling environment called SLiMgui.
https://messerlab.org/slim/
GNU General Public License v3.0
160 stars 33 forks source link

rank() function request #379

Closed ans6160 closed 1 year ago

ans6160 commented 1 year ago

Hello!

This was discussed on my slim-discussion post and I am following up here to make a formal feature request. If a rank() function could be added so that it can work with at least floats (other types would be helpful as well) that would be fantastic! Thanks!

bhaller commented 1 year ago

(@petrelharp So R is one-based and Eidos is zero-based. In R, rank(17) is 1. In Eidos, should it be 0 or 1? In other words, is this a one-based versus zero-based thing, such that Eidos should shift the results to being zero-based, or is there a broader mathematical convention here that Eidos ought to preserve?)

Never mind, I think I answered my own question: https://en.wikipedia.org/wiki/Ranking_(statistics). It should be 1, by convention.

bhaller commented 1 year ago

@ans6160 you say "other types would be helpful as well"; do you just mean integer? Or do you actually have a need for using rank() with string or logical?

ans6160 commented 1 year ago

Probably just integer. I can't really think of a reason to rank a string or logical. Sorry for the confusion!

bhaller commented 1 year ago

Probably just integer. I can't really think of a reason to rank a string or logical. Sorry for the confusion!

OK good, me too. (In a general programming context those other uses of rank() would also have their uses, but in the context of SLiM it seems unlikely. Anyhow they can be added later if needed.)

bhaller commented 1 year ago

OK, this is now in. Types logical and string are not supported, and tiesMethod of "random" is not supported. Otherwise, I believe it is identical to the R function of the same name.