Rank messages

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

Rank messages

mils
Hi

I would like to rank a number of "messages" based on consumer responses, where they have to rate from the messages they've seen the one they prefer most (1) and  the one they prefer least (-1) -- 0 will the messages they have seen but not selected and sysmis will be those that have not been shown -- .

I have the following data:

data list list
 /maxDiff1alt1 maxDiff1alt2 maxDiff1alt3 maxDiff2alt1 maxDiff2alt2 maxDiff2alt3 maxDiff3alt1 maxDiff3alt2 maxDiff3alt3.
begin data.
0 -1 0 0 . . . 0 .
1 0 -1 1 . . . 0 .
-1 0 0 -1 . . . 0 .
0 0 0 0 . . . 0 .
1 -1 0 1 . . . -1 .
0 1 -1 0 . . . 0 .
1 -1 0 1 . . . 0 .
0 0 -1 -1 . . . 0 .
0 0 -1 1 . . . 0 .
1 -1 0 1 . . . -1 .
0 0 -1 1 . . . 0 .
0 0 0 0 . . . 0 .
1 0 -1 1 . . . 0 .
end data.

compute nvalid1=count(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1).
compute suma1=sum(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1)/nvalid1.
compute nvalid2=nvalid(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2).
compute suma2=sum(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2)/nvalid2.
compute nvalid3=nvalid(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3).
compute suma3=sum(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3)/nvalid3.
EXECUTE.

desc suma1 to suma3/sort (d).


I would like to get the following table:

        Mean Rank
suma1 .3462 1
suma2 -.1923 2
suma3 -.4615 3

Please, let me know if you need more information.

mils
Reply | Threaded
Open this post in threaded view
|

Re: Rank messages

David Marso
Administrator
First off.
Count is NOT a valid function in COMPUTE command!
---
mils wrote
Hi

I would like to rank a number of "messages" based on consumer responses, where they have to rate from the messages they've seen the one they prefer most (1) and  the one they prefer least (-1) -- 0 will the messages they have seen but not selected and sysmis will be those that have not been shown -- .

I have the following data:

data list list
 /maxDiff1alt1 maxDiff1alt2 maxDiff1alt3 maxDiff2alt1 maxDiff2alt2 maxDiff2alt3 maxDiff3alt1 maxDiff3alt2 maxDiff3alt3.
begin data.
0 -1 0 0 . . . 0 .
1 0 -1 1 . . . 0 .
-1 0 0 -1 . . . 0 .
0 0 0 0 . . . 0 .
1 -1 0 1 . . . -1 .
0 1 -1 0 . . . 0 .
1 -1 0 1 . . . 0 .
0 0 -1 -1 . . . 0 .
0 0 -1 1 . . . 0 .
1 -1 0 1 . . . -1 .
0 0 -1 1 . . . 0 .
0 0 0 0 . . . 0 .
1 0 -1 1 . . . 0 .
end data.

compute nvalid1=count(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1).
compute suma1=sum(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1)/nvalid1.
compute nvalid2=nvalid(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2).
compute suma2=sum(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2)/nvalid2.
compute nvalid3=nvalid(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3).
compute suma3=sum(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3)/nvalid3.
EXECUTE.

desc suma1 to suma3/sort (d).


I would like to get the following table:

        Mean Rank
suma1 .3462 1
suma2 -.1923 2
suma3 -.4615 3

Please, let me know if you need more information.
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: Rank messages

Richard Ristow
In reply to this post by mils
At 11:54 AM 4/20/2015, mils wrote:

>I would like to rank a number of "messages" based on consumer
>responses, where they have to rate from the messages they've seen
>the one they prefer most (1) and  the one they prefer least (-1) --
>0 will the messages they have seen but not selected and sysmis will
>be those that have not been shown.

The following does what I *think* you're saying you want, but it's
not the same as what the code you posted seems to be trying to
do.  (For my convenience, it uses more datasets than are really necessary.)

DATASET ACTIVATE TestData WINDOW=FRONT.
DATASET COPY     Unroll.
DATASET ACTIVATE Unroll   WINDOW=FRONT.
VARSTOCASES
   /MAKE Value FROM maxDiff1alt1 TO maxDiff3alt3
   /INDEX = MsgName(Value)
   /KEEP =  CASEID
   /NULL = DROP.


Variables to Cases
|----------------------------|---------------------------|
|Output Created              |20-APR-2015 17:57:23       |
|----------------------------|---------------------------|
  [Unroll]
Generated Variables
|-------|------|
|Name   |Label |
|-------|------|
|MsgName|<none>|
|Value  |<none>|
|-------|------|

Processing Statistics
|-------------|--|
|Variables In |10|
|Variables Out|3 |
|-------------|--|


DATASET DECLARE  Summary.
AGGREGATE OUTFILE=Summary
    /BREAK=MsgName
    /NSeen  'Number of times seen' = NU
    /Rating 'Mean rating'          = MEAN(Value).

DATASET ACTIVATE  Summary  WINDOW=FRONT.
SORT CASE BY Rating (D).
LIST.

List
|-----------------------------|--------------------------|
|Output Created               |20-APR-2015 7:57:23       |
|-----------------------------|--------------------------|
  [Summary]
MsgName        NSeen   Rating

maxDiff2alt1      13      .38
maxDiff1alt1      13      .31
maxDiff3alt2      13     -.15
maxDiff1alt2      13     -.23
maxDiff1alt3      13     -.46

Number of cases read:  5    Number of cases listed:  5
=================================
APPENDIX: Test data, and all code
=================================
NEW FILE.
PRESERVE.
SET MXWARNS 0.
data list list
   /CASEID
    maxDiff1alt1 maxDiff1alt2    maxDiff1alt3    maxDiff2alt1    maxDiff2alt2
    maxDiff2alt3 maxDiff3alt1    maxDiff3alt2    maxDiff3alt3.
begin data.
1    0  -1      0       0       .       .       .       0       .
2    1  0       -1      1       .       .       .       0       .
3    -1 0       0       -1      .       .       .       0       .
4    0  0       0       0       .       .       .       0       .
5    1  -1      0       1       .       .       .       -1      .
6    0  1       -1      0       .       .       .       0       .
7    1  -1      0       1       .       .       .       0       .
8    0  0       -1      -1      .       .       .       0       .
9    0  0       -1      1       .       .       .       0       .
10    1 -1      0       1       .       .       .       -1      .
11    0 0       -1      1       .       .       .       0       .
12    0 0       0       0       .       .       .       0       .
13    1 0       -1      1       .       .       .       0       .
end data.
RESTORE.

FORMATS CASEID                        (N3)
         maxDiff1alt1 to maxDiff3alt3  (F3).
DATASET NAME     TestData WINDOW=FRONT.


DATASET ACTIVATE TestData WINDOW=FRONT.
DATASET COPY     Unroll.
DATASET ACTIVATE Unroll   WINDOW=FRONT.

VARSTOCASES
   /MAKE Value FROM maxDiff1alt1 TO maxDiff3alt3
   /INDEX = MsgName(Value)
   /KEEP =  CASEID
   /NULL = DROP.

DATASET DECLARE  Summary.

AGGREGATE OUTFILE=Summary
    /BREAK=MsgName
    /NSeen  'Number of times seen' = NU
    /Rating 'Mean rating'          = MEAN(Value).


DATASET ACTIVATE  Summary  WINDOW=FRONT.
SORT CASE BY Rating (D).

LIST.

=====================
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: Rank messages

Richard Ristow
In reply to this post by mils
At 11:54 AM 4/20/2015, mils wrote:

>I would like to rank a number of "messages" based on consumer responses,

I should have done this in the first place, but below is revised code
that I think gives you, at least very nearly, what you asked for:

compute suma1=MEAN(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1).
compute suma2=MEAN(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2).
compute suma3=MEAN(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3).

DATASET COPY     Unroll.
DATASET ACTIVATE Unroll WINDOW=FRONT.
VARSTOCASES
   /MAKE    Score FROM suma1 TO suma3
   /INDEX = MsgName(Score)
   /NULL  = DROP.

Variables to Cases
|----------------------------|---------------------------|
|Output Created              |20-APR-2015 22:45:15       |
|----------------------------|---------------------------|
[messages suppressed]

DATASET DECLARE  Summary.
AGGREGATE OUTFILE=Summary
    /BREAK=MsgName
    /Mean 'Mean score'          = MEAN(Score).

DATASET ACTIVATE  Summary  WINDOW=FRONT.
SORT CASES BY Mean (D).
FORMATS  Mean (F7.4).

NUMERIC  Rank (F3).
COMPUTE  Rank = $CASENUM.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |20-APR-2015 22:45:16       |
|-----------------------------|---------------------------|
  [Summary]

MsgName    Mean Rank

suma1     .3462    1
suma2    -.1923    2
suma3    -.4615    3

Number of cases read:  3    Number of cases listed:  3
=================================
APPENDIX: Test data, and all code
=================================
NEW FILE.
PRESERVE.
SET MXWARNS 0.
data list list
  /maxDiff1alt1  maxDiff1alt2    maxDiff1alt3    maxDiff2alt1    maxDiff2alt2
maxDiff2alt3    maxDiff3alt1    maxDiff3alt2    maxDiff3alt3.
begin data.
0       -1      0       0       .       .       .       0       .
1       0       -1      1       .       .       .       0       .
-1      0       0       -1      .       .       .       0       .
0       0       0       0       .       .       .       0       .
1       -1      0       1       .       .       .       -1      .
0       1       -1      0       .       .       .       0       .
1       -1      0       1       .       .       .       0       .
0       0       -1      -1      .       .       .       0       .
0       0       -1      1       .       .       .       0       .
1       -1      0       1       .       .       .       -1      .
0       0       -1      1       .       .       .       0       .
0       0       0       0       .       .       .       0       .
1       0       -1      1       .       .       .       0       .
end data.
RESTORE.
DATASET NAME    TestData WINDOW=FRONT.

compute suma1=MEAN(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1).
compute suma2=MEAN(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2).
compute suma3=MEAN(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3).

DATASET COPY     Unroll.
DATASET ACTIVATE Unroll WINDOW=FRONT.


VARSTOCASES
   /MAKE    Score FROM suma1 TO suma3
   /INDEX = MsgName(Score)
   /NULL  = DROP.

DATASET DECLARE  Summary.

AGGREGATE OUTFILE=Summary
    /BREAK=MsgName
    /Mean 'Mean score'          = MEAN(Score).

DATASET ACTIVATE  Summary  WINDOW=FRONT.
SORT CASES BY Mean (D).
FORMATS  Mean (F7.4).

NUMERIC  Rank (F3).
COMPUTE  Rank = $CASENUM.

LIST.

=====================
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: Rank messages

mils


Thanks Richard, that's exactly want I wanted.
mils
Reply | Threaded
Open this post in threaded view
|

Re: Rank messages

mils
In reply to this post by Richard Ristow
Would it be possible also to see the individual rankings? Something like this:

MsgName    Mean Rank

suma1 .00         1
suma2 -.50        3
suma3 .00         2
suma1 1.00       1
suma2 .00         2
suma3 -1.00      3
suma1 -1.00      3
suma2 .00         1
suma3 .00         2
.
.
.
.
mils
Reply | Threaded
Open this post in threaded view
|

Re: Rank messages

Richard Ristow
At 08:01 AM 4/23/2015, mils wrote

>Would it be possible also to see the individual rankings?

Sure; I think this gives you what you want.  Notice that I've added a
variable ("CASEID") that identifies the rows in the data; this is
necessary for the logic to work.

DATASET ACTIVATE TestData WINDOW=FRONT.
DATASET COPY     Unroll.
DATASET ACTIVATE Unroll   WINDOW=FRONT.

compute suma1=MEAN(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1).
compute suma2=MEAN(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2).
compute suma3=MEAN(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3).

EXECUTE /* appears to be needed for VARSTOCASES to work */.

VARSTOCASES
   /MAKE    Score FROM suma1 TO suma3
   /INDEX = MsgName(Score)
   /KEEP  = CASEID
   /NULL  = KEEP.

Variables to Cases
|----------------------------|---------------------------|
|Output Created              |24-APR-2015 01:26:04       |
|----------------------------|---------------------------|
  [Unroll]

Generated Variables
|-------|------|
|Name   |Label |
|-------|------|
|MsgName|<none>|
|Score  |<none>|
|-------|------|

Processing Statistics
|-------------|--|
|Variables In |13|
|Variables Out|3 |
|-------------|--|


SORT CASES BY CASEID(A) Score (D).
NUMERIC Rank (F3).

DO IF   $CASENUM EQ 1.
.  COMPUTE Rank = 1.
ELSE IF CASEID   NE LAG(CASEID).
.  COMPUTE Rank = 1.
ELSE.
.  COMPUTE Rank = LAG(Rank) + 1.
END IF.

SORT CASES BY CASEID(A) MsgName (A).
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |24-APR-2015 01:26:04       |
|-----------------------------|---------------------------|
  [Unroll]

CASEID MsgName    Score Rank

   001  suma1        .00    1
   001  suma2       -.50    3
   001  suma3        .00    2
   002  suma1       1.00    1
   002  suma2        .00    2
   002  suma3      -1.00    3
   003  suma1      -1.00    3
   003  suma2        .00    1
   003  suma3        .00    2
   004  suma1        .00    1
   004  suma2        .00    2
   004  suma3        .00    3
   005  suma1       1.00    1
   005  suma2      -1.00    3
   005  suma3        .00    2
   006  suma1        .00    2
   006  suma2        .50    1
   006  suma3      -1.00    3
   007  suma1       1.00    1
   007  suma2       -.50    3
   007  suma3        .00    2
   008  suma1       -.50    2
   008  suma2        .00    1
   008  suma3      -1.00    3
   009  suma1        .50    1
   009  suma2        .00    2
   009  suma3      -1.00    3
   010  suma1       1.00    1
   010  suma2      -1.00    3
   010  suma3        .00    2
   011  suma1        .50    1
   011  suma2        .00    2
   011  suma3      -1.00    3
   012  suma1        .00    1
   012  suma2        .00    2
   012  suma3        .00    3
   013  suma1       1.00    1
   013  suma2        .00    2
   013  suma3      -1.00    3

Number of cases read:  39    Number of cases listed:  39
=================================
APPENDIX: Test data, and all code
=================================

NEW FILE.
PRESERVE.
SET MXWARNS 0.
data list list
   /CASEID
    maxDiff1alt1 maxDiff1alt2    maxDiff1alt3    maxDiff2alt1    maxDiff2alt2
    maxDiff2alt3 maxDiff3alt1    maxDiff3alt2    maxDiff3alt3.
begin data.
1    0  -1      0       0       .       .       .       0       .
2    1  0       -1      1       .       .       .       0       .
3    -1 0       0       -1      .       .       .       0       .
4    0  0       0       0       .       .       .       0       .
5    1  -1      0       1       .       .       .       -1      .
6    0  1       -1      0       .       .       .       0       .
7    1  -1      0       1       .       .       .       0       .
8    0  0       -1      -1      .       .       .       0       .
9    0  0       -1      1       .       .       .       0       .
10    1 -1      0       1       .       .       .       -1      .
11    0 0       -1      1       .       .       .       0       .
12    0 0       0       0       .       .       .       0       .
13    1 0       -1      1       .       .       .       0       .
end data.
RESTORE.

FORMATS CASEID                        (N3)
         maxDiff1alt1 to maxDiff3alt3  (F3).
DATASET NAME     TestData WINDOW=FRONT.


DATASET ACTIVATE TestData WINDOW=FRONT.
DATASET COPY     Unroll.
DATASET ACTIVATE Unroll   WINDOW=FRONT.

compute suma1=MEAN(maxDiff1alt1,maxDiff2alt1,maxDiff3alt1).
compute suma2=MEAN(maxDiff1alt2,maxDiff2alt2,maxDiff3alt2).
compute suma3=MEAN(maxDiff1alt3,maxDiff2alt3,maxDiff3alt3).

EXECUTE /* appears to be needed for VARSTOCASES to work */.

VARSTOCASES
   /MAKE    Score FROM suma1 TO suma3
   /INDEX = MsgName(Score)
   /KEEP  = CASEID
   /NULL  = KEEP.

SORT CASES BY CASEID(A) Score (D).

NUMERIC Rank (F3).

DO IF   $CASENUM EQ 1.
.  COMPUTE Rank = 1.
ELSE IF CASEID   NE LAG(CASEID).
.  COMPUTE Rank = 1.
ELSE.
.  COMPUTE Rank = LAG(Rank) + 1.
END IF.

SORT CASES BY CASEID(A) MsgName (A).

LIST.

=====================
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: Rank messages

mils
Hi,

I just realized that some of the scores are duplicated and we are assigning ranks based on the following syntax:

SORT CASES BY CASEID(A) Score (D).

I was wondering if this doesn't bias our final ranks?

I have two different solutions.

Add a random uniform number to each sum. That will make them unique:

compute a1=suma1+uniform(1)/100.
compute a2=suma2+uniform(1)/100.
compute a3=suma3+uniform(1)/100.

And create the ranking using Richard's syntax. Or

The second solution, which I don't know how to do it, will it be to assign ranks accounting for duplicate scores. Something like this:


   001  suma1        .00    1
   001  suma2       -.50    3
   001  suma3        .00    1

   002  suma1       1.00    1
   002  suma2        .00    2
   002  suma3      -1.00    3

   003  suma1      -1.00    3
   003  suma2        .00    1
   003  suma3        .00    1

   004  suma1        .00    1
   004  suma2        .00    1
   004  suma3        .00    1

So, if we have two duplicates in rank 1, we assign them 1, but the third score will be ranked 3, not 2.
If we have two duplicates in rank 2, we will assign for score one: rank1 and for scores two and three: rank 2.

Any suggestions on how to do it?
Thanks in advance?
mils
Reply | Threaded
Open this post in threaded view
|

Re: Rank messages

David Marso
Administrator
Simply reading up on RANK and trying out different options for ties will suffice.
--
RANK Score (D) BY CASEID/ RANK INTO R / TIES=LOW.
---

mils wrote
Hi,

I just realized that some of the scores are duplicated and we are assigning ranks based on the following syntax:

SORT CASES BY CASEID(A) Score (D).

I was wondering if this doesn't bias our final ranks?

I have two different solutions.

Add a random uniform number to each sum. That will make them unique:

compute a1=suma1+uniform(1)/100.
compute a2=suma2+uniform(1)/100.
compute a3=suma3+uniform(1)/100.

And create the ranking using Richard's syntax. Or

The second solution, which I don't know how to do it, will it be to assign ranks accounting for duplicate scores. Something like this:


   001  suma1        .00    1
   001  suma2       -.50    3
   001  suma3        .00    1

   002  suma1       1.00    1
   002  suma2        .00    2
   002  suma3      -1.00    3

   003  suma1      -1.00    3
   003  suma2        .00    1
   003  suma3        .00    1

   004  suma1        .00    1
   004  suma2        .00    1
   004  suma3        .00    1

So, if we have two duplicates in rank 1, we assign them 1, but the third score will be ranked 3, not 2.
If we have two duplicates in rank 2, we will assign for score one: rank1 and for scores two and three: rank 2.

Any suggestions on how to do it?
Thanks in advance?
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: Rank messages

Art Kendall
In reply to this post by mils
If you know why the value is missing (not shown) then the value is NOT missing because the machine is unable to follow your instructions.  I strongly suggest using a labeled user missing value.

Missing value myvar (-2).
Value labels
   1 'most preferred'
   0 'not selected'
  -1 'least preferred'
  -2 'not shown'.

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Rank messages

Art Kendall
In reply to this post by mils
If you know why the value is missing (not shown) then the value is NOT missing because the machine is unable to follow your instructions.  I strongly suggest using a labeled user missing value.

Missing value myvar (-2).
Value labels
   1 'most preferred'
   0 'not selected'
  -1 'least preferred'
  -2 'not shown'.

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Rank messages

mils
In reply to this post by David Marso
Aha, that did work. Thanks David.


RANK VARIABLES=Score (D) BY CASEID
  /RANK
  /PRINT=YES
  /TIES=low.

The only thing I had to change  was the CASEID variable into a numeric one.

Thanks
mils