Ranks calculation
|
10-31-2024, 01:39 PM
Post: #1
|
|||
|
|||
Ranks calculation
Hello everyone, some statistical tests, especially non-parametric ones, require the calculation of ranks. Is there a way to calculate them with HP PRIME?
For example, given a column vector: [[1],[3],[5],[1],[4],[5],[6],[1]] the ranks are: [[2],[4],[6.5],[2],[5],[6.5],[8],[2]]. Thanks for your help, Roberto |
|||
10-31-2024, 02:38 PM
Post: #2
|
|||
|
|||
RE: Ranks calculation
(10-31-2024 01:39 PM)robmio Wrote: For example, given a column vector: Is rank of matrix supposed to be a single number? What does above list of numbers mean? |
|||
10-31-2024, 02:46 PM
Post: #3
|
|||
|
|||
RE: Ranks calculation
(10-31-2024 02:38 PM)Albert Chan Wrote:(10-31-2024 01:39 PM)robmio Wrote: For example, given a column vector: It is not the rank of a matrix, but the scores to be given to the various values. For example, ranks are used in the statistical test "Wilcoxon signed-rank test": https://www.technologynetworks.com/infor...est-370384 |
|||
10-31-2024, 02:50 PM
Post: #4
|
|||
|
|||
RE: Ranks calculation | |||
10-31-2024, 04:41 PM
Post: #5
|
|||
|
|||
RE: Ranks calculation
Code: def ranking(m): p2> ranking([1,3,5,1,4,5,6,1]) [2.0, 4.0, 6.5, 2.0, 5.0, 6.5, 8.0, 2.0] |
|||
10-31-2024, 08:16 PM
Post: #6
|
|||
|
|||
RE: Ranks calculation
(10-31-2024 04:41 PM)Albert Chan Wrote: Thank you so much, Albert Chan. I really appreciate it! Kind regards, Roberto |
|||
10-31-2024, 08:42 PM
(This post was last modified: 10-31-2024 09:18 PM by Albert Chan.)
Post: #7
|
|||
|
|||
RE: Ranks calculation
Note that Python has 0-based array.
If code were for Python use, I would assign r back to the ranking list, instead of r+1 Lua array is 1-based, and probably easier to port to HP Prime Code: function ranking(m) lua> pprint( ranking{1,3,5,1,4,5,6,1} ) { 2, 4, 6.5, 2, 5, 6.5, 8, 2 } |
|||
11-01-2024, 07:41 AM
Post: #8
|
|||
|
|||
RE: Ranks calculation
(10-31-2024 08:42 PM)Albert Chan Wrote: Note that Python has 0-based array. Thank you very much, Albert Chan. I have translated your Python program into a Cas program: Code:
|
|||
11-01-2024, 09:04 AM
Post: #9
|
|||
|
|||
RE: Ranks calculation
Unfortunately, there is an error in the following program, and I can't figure out what it is:
Code:
ranking([7,5,7]) --> [2,1,3] instead of: ranking([7,5,7]) --> [2.5,1,2.5] |
|||
11-01-2024, 09:38 AM
(This post was last modified: 11-01-2024 10:13 AM by Albert Chan.)
Post: #10
|
|||
|
|||
RE: Ranks calculation
(11-01-2024 09:04 AM)robmio Wrote: Unfortunately, there is an error in the following program, and I can't figure out what it is: Off-by-1 error (Lua code use i<hi, with same effect) i≠hi guard is to *ALWAYS* update last ranking. (*) < IF j≠hi AND m2[ii][1]==m2[j][1] THEN > IF ii≠hi AND m2[ii][1]==m2[j][1] THEN (*) It is weird bad code does not generate Index outside range error, when j = hi+1 Update: fixed typo, should be ii instead of i |
|||
11-01-2024, 10:03 AM
Post: #11
|
|||
|
|||
RE: Ranks calculation
(11-01-2024 09:38 AM)Albert Chan Wrote:(11-01-2024 09:04 AM)robmio Wrote: Unfortunately, there is an error in the following program, and I can't figure out what it is: Hi Albert Chan, your fix works fine. Also, if we replace "i" with "j" in the following line: "FOR k FROM lo TO ii DO" the code generates Index outside range error. Thanks again, many thanks! |
|||
11-01-2024, 10:04 AM
Post: #12
|
|||
|
|||
RE: Ranks calculation
This version works fine.
Code:
|
|||
11-01-2024, 10:34 AM
(This post was last modified: 11-01-2024 11:14 AM by Albert Chan.)
Post: #13
|
|||
|
|||
RE: Ranks calculation
(11-01-2024 10:03 AM)robmio Wrote: the code generates Index outside range error. I mean when we do equality test, Index outside range not producing error Cas> m := [1,2,3] Cas> m[3] == m[4] → 0 Cas> m[4] == m[5] → 0 Cas> m[5] == m[6] → 0 m2[hi][1]==m2[hi+1][1] guard should also generate 0, i.e. always update last ranking. If we use this undefined behavior (not recommended), we can drop ii≠hi guard. Interestingly, I discovered this due to a typo , i≠hi instead of ii≠hi Since i = √(-1) is imaginary, i≠hi is always true, same as no guard. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)