ranking a score

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

ranking a score

progster
dear all I would like to have a ranking of some some scores I calculated. The results that i would like to achive are shown in the column my_aim. If the score is repeated the ranking stays the same, otherwise it matches the id value. I could only exploit something with the lag function but could not figure out more.

any tip? thanks


data list list / score my_aim id.
begin data.
0,5 1 1
0,5 1 2
0,5 1 3
0,7 4 4
0,7 4 5
0,9 4 6
0,9 7 7
0,9 7 8
end data.



compute try = 1 .
do if score = lag(score) .
   compute try = lag(try) .
else .
   compute try = lag(try) + 1 .
end if .
execute .
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

vlad simion
hi,

have a look at RANK command
something like:

rank var = score
/rank
/ties=low.

hth,
vlad
This email has been sent from a virus-free computer protected by Avast.
www.avast.com

On Thu, Dec 17, 2015 at 9:09 AM, progster <[hidden email]> wrote:
dear all I would like to have a ranking of some some scores I calculated. The
results that i would like to achive are shown in the column my_aim. If the
score is repeated the ranking stays the same, otherwise it matches the id
value. I could only exploit something with the lag function but could not
figure out more.

any tip? thanks


data list list / score  my_aim  id.
begin data.
0,5     1       1
0,5     1       2
0,5     1       3
0,7     4       4
0,7     4       5
0,9     4       6
0,9     7       7
0,9     7       8
end data.



compute try = 1 .
do if score = lag(score) .
   compute try = lag(try) .
else .
   compute try = lag(try) + 1 .
end if .
execute .




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/ranking-a-score-tp5731137.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

David Marso
Administrator
In reply to this post by progster
I don't see why the 6th case value 9 gets the same 'rank' as the 5th value 7 and 7th case value 9 ( a repeat) gets incremented rather than repeated.  Your description of intent is inconsistent with the sample data.

progster wrote
dear all I would like to have a ranking of some some scores I calculated. The results that i would like to achive are shown in the column my_aim. If the score is repeated the ranking stays the same, otherwise it matches the id value. I could only exploit something with the lag function but could not figure out more.

any tip? thanks


data list list / score my_aim id.
begin data.
0,5 1 1
0,5 1 2
0,5 1 3
0,7 4 4
0,7 4 5
0,9 4 6
0,9 7 7
0,9 7 8
end data.



compute try = 1 .
do if score = lag(score) .
   compute try = lag(try) .
else .
   compute try = lag(try) + 1 .
end if .
execute .
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

progster
my bad sorry! it's ok as proposed by Vlad.

I would like to know, but just for the sake of knowing SPSS, if it would be possible to get the rank without the rank function, but working with lag or lead or any other function...

Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

Andy W
This post was updated on .
Here is how I would go about it for this particular example (correcting the error in the original dataset).

*************************************.
data list list / score my_aim id.
begin data.
0.5 1 1
0.5 1 2
0.5 1 3
0.7 4 4
0.7 4 5
0.7 4 6
0.9 7 7
0.9 7 8
end data.

sort cases by score.
compute rank = $casenum.
aggregate outfile=* mode=addvariables overwrite=yes /break score /rank = min(rank).
*************************************.

That being said I don't see why there would be an aversion to using the RANK command.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

David Marso
Administrator
This post was updated on .
In reply to this post by progster
Using Andy's 'corrected' data: Here are 3 slightly different ways.
Note how If /Else can be folded into a compound summation using the Booleans.
--
data list list / score my_aim id.
begin data.
0.5 1 1
0.5 1 2
0.5 1 3
0.7 4 4
0.7 4 5
0.7 4 6
0.9 7 7
0.9 7 8
end data.
SORT CASES BY score.
DO IF $CASENUM EQ 1 OR score NE LAG(score).
COMPUTE MyRank=$CASENUM.
ELSE.
COMPUTE MyRank=LAG(MyRank).
END IF.
**EDITED OOPS: had wrong variable in MyRank2 and Myrank3 on last LAG function**
COMPUTE MyRank2=SUM(($CASENUM EQ 1 OR score NE LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank2)).
COMPUTE MyRank3=SUM(ANY(1,$CASENUM EQ 1,score NE LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank3)).
LIST.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

vlad simion
In reply to this post by progster
you can give it a try as you started:

compute try = 1 .
do if score = lag(score) .
   compute try = lag(try) .
else .
   compute try =id .
end if .
execute .

but make sure the score is ordered and you have an id equal with the $casenum

hth,
vlad
This email has been sent from a virus-free computer protected by Avast.
www.avast.com

On Fri, Dec 18, 2015 at 1:58 PM, progster <[hidden email]> wrote:
my bad sorry! it's ok as proposed by Vlad.

I would like to know, but just for the sake of knowing SPSS, if it would be
possible to get the rank without the rank function, but working with lag or
lead or any other function...





--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/ranking-a-score-tp5731137p5731148.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

Bruce Weaver
Administrator
In reply to this post by David Marso
I'm responding for two reasons:

1. To make sure David's edit in Nabble is seen (in the quoted message below) by folks who do not use Nabble; and

2. To say that I would put some carriage returns in David's last two COMPUTE commands to clarify what is being summed.  E.g.,

COMPUTE MyRank2=SUM(
 ($CASENUM EQ 1 OR score NE LAG(score))*$CASENUM,
 (score EQ LAG(score))*LAG(MyRank2) ).

COMPUTE MyRank3=SUM(
 ANY(1,$CASENUM EQ 1,score NE LAG(score))*$CASENUM,
 (score EQ LAG(score))*LAG(MyRank3) ).


HTH.

David Marso wrote
Using Andy's 'corrected' data: Here are 3 slightly different ways.
Note how If /Else can be folded into a compound summation using the Booleans.
--
data list list / score my_aim id.
begin data.
0.5 1 1
0.5 1 2
0.5 1 3
0.7 4 4
0.7 4 5
0.7 4 6
0.9 7 7
0.9 7 8
end data.
SORT CASES BY score.
DO IF $CASENUM EQ 1 OR score NE LAG(score).
COMPUTE MyRank=$CASENUM.
ELSE.
COMPUTE MyRank=LAG(MyRank).
END IF.
**EDITED OOPS: had wrong variable in MyRank2 and Myrank3 on last LAG function**
COMPUTE MyRank2=SUM(($CASENUM EQ 1 OR score NE LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank2)).
COMPUTE MyRank3=SUM(ANY(1,$CASENUM EQ 1,score NE LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank3)).
LIST.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

Maguin, Eugene
I'm in awe of David's code quoted below. It's so compact it sparkles and is a little dimensional funhouse of expanding.
Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Friday, December 18, 2015 11:08 AM
To: [hidden email]
Subject: Re: ranking a score

I'm responding for two reasons:

1. To make sure David's edit in Nabble is seen (in the quoted message below) by folks who do not use Nabble; and

2. To say that I would put some carriage returns in David's last two COMPUTE commands to clarify what is being summed.  E.g.,

COMPUTE MyRank2=SUM(
 ($CASENUM EQ 1 OR score NE LAG(score))*$CASENUM,  (score EQ LAG(score))*LAG(MyRank2) ).

COMPUTE MyRank3=SUM(
 ANY(1,$CASENUM EQ 1,score NE LAG(score))*$CASENUM,  (score EQ LAG(score))*LAG(MyRank3) ).


HTH.


David Marso wrote

> Using Andy's 'corrected' data: Here are 3 slightly different ways.
> Note how If /Else can be folded into a compound summation using the
> Booleans.
> --
> data list list / score my_aim id.
> begin data.
> 0.5 1 1
> 0.5 1 2
> 0.5 1 3
> 0.7 4 4
> 0.7 4 5
> 0.7 4 6
> 0.9 7 7
> 0.9 7 8
> end data.
> SORT CASES BY score.
> DO IF $CASENUM EQ 1 OR score NE LAG(score).
> COMPUTE MyRank=$CASENUM.
> ELSE.
> COMPUTE MyRank=LAG(MyRank).
> END IF.
> **EDITED OOPS: had wrong variable in MyRank2 and Myrank3 on last LAG
> function**
> COMPUTE MyRank2=SUM(($CASENUM EQ 1 OR score NE
> LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank2)).
> COMPUTE MyRank3=SUM(ANY(1,$CASENUM EQ 1,score NE
> LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank3)).
> LIST.





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/ranking-a-score-tp5731137p5731152.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

David Marso
Administrator
Thank you Gene,
  The idea is used in a number of my previous postings.
Whenever one has a logical condition (true=1, 0=false) one can use that to compactly express any conditional by the sum of two Booleans multiplied by their respective result.  
Note that this can be also be expressed as an inner product of two vectors to evaluate which of possibly many conditions are satisfied.

DATA LIST FREE / CaseTrue .
BEGIN DATA
1 0 1  0 1 0 1 1
END DATA.
MATRIX.
GET booleans / FILE * / VARIABLES CaseTrue.
COMPUTE hash=MAKE(NROW(booleans),1,0).
LOOP #=1 TO NROW(hash).
COMPUTE hash(#)= 2**(#-1).
END LOOP.
COMPUTE Compound=T(booleans) * hash.
PRINT {booleans,hash}.
Print Compound.
END MATRIX.
 
{BOOLEANS,HASH}
    1    1
    0    2
    1    4
    0    8
    1   16
    0   32
    1   64
    1  128
 
COMPOUND
  213

Maguin, Eugene wrote
I'm in awe of David's code quoted below. It's so compact it sparkles and is a little dimensional funhouse of expanding.
Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Friday, December 18, 2015 11:08 AM
To: [hidden email]
Subject: Re: ranking a score

I'm responding for two reasons:

1. To make sure David's edit in Nabble is seen (in the quoted message below) by folks who do not use Nabble; and

2. To say that I would put some carriage returns in David's last two COMPUTE commands to clarify what is being summed.  E.g.,

COMPUTE MyRank2=SUM(
 ($CASENUM EQ 1 OR score NE LAG(score))*$CASENUM,  (score EQ LAG(score))*LAG(MyRank2) ).

COMPUTE MyRank3=SUM(
 ANY(1,$CASENUM EQ 1,score NE LAG(score))*$CASENUM,  (score EQ LAG(score))*LAG(MyRank3) ).


HTH.


David Marso wrote
> Using Andy's 'corrected' data: Here are 3 slightly different ways.
> Note how If /Else can be folded into a compound summation using the
> Booleans.
> --
> data list list / score my_aim id.
> begin data.
> 0.5 1 1
> 0.5 1 2
> 0.5 1 3
> 0.7 4 4
> 0.7 4 5
> 0.7 4 6
> 0.9 7 7
> 0.9 7 8
> end data.
> SORT CASES BY score.
> DO IF $CASENUM EQ 1 OR score NE LAG(score).
> COMPUTE MyRank=$CASENUM.
> ELSE.
> COMPUTE MyRank=LAG(MyRank).
> END IF.
> **EDITED OOPS: had wrong variable in MyRank2 and Myrank3 on last LAG
> function**
> COMPUTE MyRank2=SUM(($CASENUM EQ 1 OR score NE
> LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank2)).
> COMPUTE MyRank3=SUM(ANY(1,$CASENUM EQ 1,score NE
> LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank3)).
> LIST.





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/ranking-a-score-tp5731137p5731152.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

progster
In reply to this post by Andy W
I see your point Andy. it's not an aversion to using the RANK command, but I see that here there are some amazing and inspiring SPSS users that everytime push me to improve my knowledge and at the moment I would not come to something better in spite of one week hard work, (or month..or year who knows) :-)

so thanks to all for inspiration
Reply | Threaded
Open this post in threaded view
|

Re: ranking a score

David Marso
Administrator
In reply to this post by David Marso
For an example of this technique in action (as well as a step by step evolution of the application of the method see if you can follow the latter posts in this thread).
http://spssx-discussion.1045642.n5.nabble.com/Inclusion-of-IDF-functions-in-matrix-language-td4680040.html#a4682432

It starts with a ponderous DO IF ELSE.... ELSE..blah blah blah zzzzzz...END IF and ends up with a sublime Vector Product solution ;-)))

David Marso wrote
Thank you Gene,
  The idea is used in a number of my previous postings.
Whenever one has a logical condition (true=1, 0=false) one can use that to compactly express any conditional by the sum of two Booleans multiplied by their respective result.  
Note that this can be also be expressed as an inner product of two vectors to evaluate which of possibly many conditions are satisfied.

DATA LIST FREE / CaseTrue .
BEGIN DATA
1 0 1  0 1 0 1 1
END DATA.
MATRIX.
GET booleans / FILE * / VARIABLES CaseTrue.
COMPUTE hash=MAKE(NROW(booleans),1,0).
LOOP #=1 TO NROW(hash).
COMPUTE hash(#)= 2**(#-1).
END LOOP.
COMPUTE Compound=T(booleans) * hash.
PRINT {booleans,hash}.
Print Compound.
END MATRIX.
 
{BOOLEANS,HASH}
    1    1
    0    2
    1    4
    0    8
    1   16
    0   32
    1   64
    1  128
 
COMPOUND
  213

Maguin, Eugene wrote
I'm in awe of David's code quoted below. It's so compact it sparkles and is a little dimensional funhouse of expanding.
Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Friday, December 18, 2015 11:08 AM
To: [hidden email]
Subject: Re: ranking a score

I'm responding for two reasons:

1. To make sure David's edit in Nabble is seen (in the quoted message below) by folks who do not use Nabble; and

2. To say that I would put some carriage returns in David's last two COMPUTE commands to clarify what is being summed.  E.g.,

COMPUTE MyRank2=SUM(
 ($CASENUM EQ 1 OR score NE LAG(score))*$CASENUM,  (score EQ LAG(score))*LAG(MyRank2) ).

COMPUTE MyRank3=SUM(
 ANY(1,$CASENUM EQ 1,score NE LAG(score))*$CASENUM,  (score EQ LAG(score))*LAG(MyRank3) ).


HTH.


David Marso wrote
> Using Andy's 'corrected' data: Here are 3 slightly different ways.
> Note how If /Else can be folded into a compound summation using the
> Booleans.
> --
> data list list / score my_aim id.
> begin data.
> 0.5 1 1
> 0.5 1 2
> 0.5 1 3
> 0.7 4 4
> 0.7 4 5
> 0.7 4 6
> 0.9 7 7
> 0.9 7 8
> end data.
> SORT CASES BY score.
> DO IF $CASENUM EQ 1 OR score NE LAG(score).
> COMPUTE MyRank=$CASENUM.
> ELSE.
> COMPUTE MyRank=LAG(MyRank).
> END IF.
> **EDITED OOPS: had wrong variable in MyRank2 and Myrank3 on last LAG
> function**
> COMPUTE MyRank2=SUM(($CASENUM EQ 1 OR score NE
> LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank2)).
> COMPUTE MyRank3=SUM(ANY(1,$CASENUM EQ 1,score NE
> LAG(score))*$CASENUM,(score EQ LAG(score))*LAG(MyRank3)).
> LIST.





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/ranking-a-score-tp5731137p5731152.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"