RfastOfficial / Rfast

A collection of Rfast functions for data analysis. Note 1: The vast majority of the functions accept matrices only, not data.frames. Note 2: Do not have matrices or vectors with have missing data (i.e NAs). We do no check about them and C++ internally transforms them into zeros (0), so you may get wrong results. Note 3: In general, make sure you give the correct input, in order to get the correct output. We do no checks and this is one of the many reasons we are fast.
139 stars 19 forks source link

colRanks & rowRanks bug if column (or row, respectively) is all zeros and method set to "average" #40

Closed vonGameTheory closed 2 years ago

vonGameTheory commented 3 years ago

Describe the bug colRanks ranks columns in a matrix -- if you have a constant column, it should still rank it. It does, unless that constant happens to be zero, and method is set to "average" (the default) Same bug in rowRanks, except for rows.

To Reproduce Steps to reproduce the behavior:

proper behavior

x <- as.matrix(rep(1,5)) # 1 can be any number but 0 here colRanks(x) result: 3 3 3 3 3 (as matrix)

bad behavior

x <- as.matrix(rep(0,5)) # constant column of zeros colRanks(x) result: 0 0 0 0 0

(Same bug for rowRanks if you do that with rows instead of columns)

Expected behavior Second result should also be 3 3 3 3 3 -- a constant column should always get same result, even if it is all 0s.

Desktop (please complete the following information): Rfast v 2.0.1 R version 4.0.3

ManosPapadakis95 commented 3 years ago

I agree with you. I use zero as a gard to a condition in my algorithm. Perhaps I could change it with NA.

vonGameTheory commented 3 years ago

Why NA? Why should it be different than any other number (if constant) when ranking? A constant column of 0s should rank exactly the same as a constant column of 1s or anything else (i.e. the average rank if method is set to average). Otherwise I can't trust the function and have to do a check to make sure I have no columns of all 0s and getting faulty result. (Which is how I discovered bug.)

ManosPapadakis95 commented 3 years ago

As I told you, I use zero as a guard condition number. I meed to change my guard with a number that the users want use. NA for the specific algorithm, when not use NA's, it is the best solution.

Στις Κυρ, 7 Φεβ 2021, 00:22 ο χρήστης vonGameTheory < notifications@github.com> έγραψε:

Why NA? Why should it be different than any other number (if constant) when ranking? A constant column of 0s should rank exactly the same as a constant column of 1s or anything else (i.e. the average rank if method is set to average). Otherwise I can't trust the function and have to do a check to make sure I have no columns of all 0s and getting faulty result. (Which is how I discovered bug.)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/RfastOfficial/Rfast/issues/40#issuecomment-774552217, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANPP3FMO3SVBYWIHVD4FDM3S5W6IPANCNFSM4XFOTPMQ .

vonGameTheory commented 3 years ago

Oh, so it would fail (or be rank 0s) if input had NAs? That makes sense. But 0s are legit inputs, so should have legit output.

ManosPapadakis95 commented 3 years ago

No it would not fail because I have implemented different algorithm for NAs.

Στις Κυρ, 7 Φεβ 2021, 00:33 ο χρήστης vonGameTheory < notifications@github.com> έγραψε:

Oh, so it would fail (or be rank 0s) if input had NAs? That makes sense. But 0s are legit inputs, so should have legit output.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/RfastOfficial/Rfast/issues/40#issuecomment-774553432, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANPP3FP3IV7QJ5AWIECYG63S5W7R5ANCNFSM4XFOTPMQ .

vonGameTheory commented 3 years ago

Well, ok, I guess I don't know what you are saying but it should work for 0s!