I have a data set that gives me plant percent cover data for 2100 plots
(rows) and there are about 250 potential species that can be present in each plot (rows). I need to sort/rank each row so that the percent covers go from largest to smallest. For this purpose I do not need to retain the species name, I just need to rank the percent covers from greatest to least for EACH plot in order to create Species Rank-Abundance graphs. Can anyone help me with this task? Much Thanks! Erin _________________________________________________________________ Get free, personalized commercial-free online radio with MSN Radio powered by Pandora http://radio.msn.com/?icid=T002MSN03A07001 |
Erin,
I'm probably not understanding what you need to do but why doesn't the Sort cases command do what you need? Is there something about the structure of your dataset that prevents you from using this command to get what you need? Gene Maguin |
In reply to this post by Erin Miles
(Marta and Jan, I'm copying to you because you're probably the best
MATRIX whizzes among us.) At 03:00 PM 12/8/2006, Erin Miles wrote: >I have a data set that gives me plant percent cover data for 2100 >plots (rows) and there are about 250 potential species that can be >present in each plot (rows). I need to sort/rank each row so that the >percent covers go from largest to smallest. For sorting variables within cases, the best technique that seems to exist is to use the GRADE function in the MATRIX language, which apparently calls an internal sort routine; this has been noted as the Ristow-Peck algorithm. Below is an example, SPSS draft output. Only just out of testing. There doesn't seem to be a way to do it without a LOOP in MATRIX. There's a lot of matrix tracing that could be omitted in production. The MATRIX SAVE wipes the working file. To join to the pre-existing file, save the latter and re-attach using MATCH FILES. And, here goes: LIST. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |-----------------------------|---------------------------| PLOT_ID COVR01 COVR02 COVR03 COVR04 COVR05 PLOT001 7% 26% 44% 16% 8% PLOT002 51% 18% 25% 2% 5% PLOT003 6% 2% 38% 6% 48% PLOT004 51% 17% 6% 25% 1% PLOT005 4% 46% 9% 9% 33% PLOT006 60% 5% 8% 1% 26% PLOT007 8% 4% 13% 6% 69% PLOT008 21% 36% 8% 12% 22% PLOT009 6% 41% 2% 21% 30% PLOT010 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 MATRIX. GET PLOT_ID /FILE=*/VARIABLES=PLOT_ID. GET COVER /FILE=*/VARIABLES=COVR01 TO COVR05. PRINT PLOT_ID /FORMAT='A8'. PRINT COVER/FORMAT='F5.1'/RNAMES=PLOT_ID. COMPUTE CVR_SORT = 0*COVER. COMPUTE CVR_ORDR = 0*COVER. LOOP ROW = 1 TO NROW(COVER). PRINT ROW. COMPUTE ROW_ORDR = GRADE(-1*COVER(ROW,:)). COMPUTE CVR_ORDR(ROW,:) = Row_ORDR. COMPUTE CVR_SORT(ROW,Row_Ordr) = COVER(Row,:). COMPUTE ROW_RSLT ={COVER(ROW,:) ; CVR_ORDR(ROW,:); CVR_SORT(ROW,:)}. PRINT ROW_RSLT /FORMAT=F5.1 /RLABELS='Input','Order','Sorted'. END LOOP. PRINT CVR_ORDR/RNAMES=PLOT_ID. PRINT CVR_SORT/FORMAT='F5.1'/RNAMES=PLOT_ID. SAVE {PLOT_ID,CVR_SORT,CVR_ORDR,COVER} /OUTFILE=* /VARIABLES=PLOT_ID,SORTED01 TO SORTED05, ORDER01 TO ORDER05, COVER01 To COVER05 /STRINGS=PLOT_ID. END MATRIX. Notes |--------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |--------------------------|---------------------------| Run MATRIX procedure: PLOT_ID PLOT001 PLOT002 PLOT003 PLOT004 PLOT005 PLOT006 PLOT007 PLOT008 PLOT009 PLOT010 COVER PLOT001 6.9 26.0 43.6 15.8 7.8 PLOT002 50.5 17.9 24.8 2.3 4.6 PLOT003 5.9 1.7 37.5 6.4 48.5 PLOT004 51.4 16.8 5.9 25.2 .7 PLOT005 3.7 45.9 8.9 8.7 32.8 PLOT006 59.7 5.2 8.0 1.1 26.0 PLOT007 7.8 3.7 12.8 6.4 69.2 PLOT008 21.4 36.5 7.8 12.4 21.9 PLOT009 6.4 41.0 1.9 20.7 30.0 PLOT010 50.4 7.0 13.6 26.6 2.5 ROW 1 ROW_RSLT Input 6.9 26.0 43.6 15.8 7.8 Order 5.0 2.0 1.0 3.0 4.0 Sorted 43.6 26.0 15.8 7.8 6.9 ROW 2 ROW_RSLT Input 50.5 17.9 24.8 2.3 4.6 Order 1.0 3.0 2.0 5.0 4.0 Sorted 50.5 24.8 17.9 4.6 2.3 ROW 3 ROW_RSLT Input 5.9 1.7 37.5 6.4 48.5 Order 4.0 5.0 2.0 3.0 1.0 Sorted 48.5 37.5 6.4 5.9 1.7 ROW 4 ROW_RSLT Input 51.4 16.8 5.9 25.2 .7 Order 1.0 3.0 4.0 2.0 5.0 Sorted 51.4 25.2 16.8 5.9 .7 ROW 5 ROW_RSLT Input 3.7 45.9 8.9 8.7 32.8 Order 5.0 1.0 3.0 4.0 2.0 Sorted 45.9 32.8 8.9 8.7 3.7 ROW 6 ROW_RSLT Input 59.7 5.2 8.0 1.1 26.0 Order 1.0 4.0 3.0 5.0 2.0 Sorted 59.7 26.0 8.0 5.2 1.1 ROW 7 ROW_RSLT Input 7.8 3.7 12.8 6.4 69.2 Order 3.0 5.0 2.0 4.0 1.0 Sorted 69.2 12.8 7.8 6.4 3.7 ROW 8 ROW_RSLT Input 21.4 36.5 7.8 12.4 21.9 Order 3.0 1.0 5.0 4.0 2.0 Sorted 36.5 21.9 21.4 12.4 7.8 ROW 9 ROW_RSLT Input 6.4 41.0 1.9 20.7 30.0 Order 4.0 1.0 5.0 3.0 2.0 Sorted 41.0 30.0 20.7 6.4 1.9 ROW 10 ROW_RSLT Input 50.4 7.0 13.6 26.6 2.5 Order 1.0 4.0 3.0 2.0 5.0 Sorted 50.4 26.6 13.6 7.0 2.5 CVR_ORDR PLOT001 5 2 1 3 4 PLOT002 1 3 2 5 4 PLOT003 4 5 2 3 1 PLOT004 1 3 4 2 5 PLOT005 5 1 3 4 2 PLOT006 1 4 3 5 2 PLOT007 3 5 2 4 1 PLOT008 3 1 5 4 2 PLOT009 4 1 5 3 2 PLOT010 1 4 3 2 5 CVR_SORT PLOT001 43.6 26.0 15.8 7.8 6.9 PLOT002 50.5 24.8 17.9 4.6 2.3 PLOT003 48.5 37.5 6.4 5.9 1.7 PLOT004 51.4 25.2 16.8 5.9 .7 PLOT005 45.9 32.8 8.9 8.7 3.7 PLOT006 59.7 26.0 8.0 5.2 1.1 PLOT007 69.2 12.8 7.8 6.4 3.7 PLOT008 36.5 21.9 21.4 12.4 7.8 PLOT009 41.0 30.0 20.7 6.4 1.9 PLOT010 50.4 26.6 13.6 7.0 2.5 ------ END MATRIX ----- FORMATS ORDER01 TO ORDER05 (F3) /SORTED01 TO SORTED05 (PCT3), /COVER01 TO COVER05 (PCT3). TEMPORARY. STRING SPACE(A8). LIST VARIABLES=PLOT_ID SORTED01 TO SORTED05 ORDER01 TO ORDER05 COVER01 TO COVER05 SPACE. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:30 | |-----------------------------|---------------------------| SOR SOR SOR SOR SOR ORD ORD ORD ORD ORD COV COV TED TED TED TED TED ER0 ER0 ER0 ER0 ER0 ER0 ER0 COVE COVE COVE PLOT_ID 01 02 03 04 05 1 2 3 4 5 1 2 R03 R04 R05 SPACE PLOT001 44% 26% 16% 8% 7% 5 2 1 3 4 7% 26% 44% 16% 8% PLOT002 51% 25% 18% 5% 2% 1 3 2 5 4 51% 18% 25% 2% 5% PLOT003 48% 38% 6% 6% 2% 4 5 2 3 1 6% 2% 38% 6% 48% PLOT004 51% 25% 17% 6% 1% 1 3 4 2 5 51% 17% 6% 25% 1% PLOT005 46% 33% 9% 9% 4% 5 1 3 4 2 4% 46% 9% 9% 33% PLOT006 60% 26% 8% 5% 1% 1 4 3 5 2 60% 5% 8% 1% 26% PLOT007 69% 13% 8% 6% 4% 3 5 2 4 1 8% 4% 13% 6% 69% PLOT008 36% 22% 21% 12% 8% 3 1 5 4 2 21% 36% 8% 12% 22% PLOT009 41% 30% 21% 6% 2% 4 1 5 3 2 6% 41% 2% 21% 30% PLOT010 50% 27% 14% 7% 2% 1 4 3 2 5 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 =================== APPENDIX: TEST DATA =================== * ............ Test data ............ . * 05 species, 10 cases (plots) . * Abundances exponentially distributed with mean 100, . * normalized to total abundance 1 and converted to (UGH!) . * SPSS 'percents' for display. . NEW FILE. INPUT PROGRAM. . STRING PLOT_ID (A8). . NUMERIC COVR01 TO COVR05 (F4). . VECTOR COVER = COVR01 TO COVR05. . LOOP #PLOT = 1 TO 10. . COMPUTE PLOT_ID = CONCAT('PLOT',STRING(#PLOT,N3)). . LOOP #PLANT = 1 TO 5. . COMPUTE COVER(#PLANT)=RV.EXP(.01). . END LOOP. * Normalize, to total cover = 1 . . . COMPUTE #TOTAL = SUM(COVR01 TO COVR05). . LOOP #PLANT = 1 TO 05. * The multiplication by 100, below, is because of . * SPSS's very unfortunate implementation of PCT . * formats. Sigh. . . COMPUTE COVER(#PLANT)=100*COVER(#PLANT)/#TOTAL. . END LOOP. . END CASE. . END LOOP. . FORMATS COVR01 TO COVR05 (PCT3). END FILE. END INPUT PROGRAM. |
Here is a Python solution assuming SPSS 15 and programmability are installed.
First it defines a general function for this task and then it calls it with two variables as an example. The part in triple quotes is the documentation for the function. sysmis values sort low. It creates new variables with the sorted values. The "for v in varlist" loop creates new variables; the "for case in curs" loops over the cases begin program. import spss, spssdata def vsort(varlist, direction='a', suffix='_sorted'): """sort variables, assumed to be numeric, within cases creating new variables varlist is the list of variables to sort. direction can be 'a' or 'd' for ascending or descending. suffix is the string to append to the original name for the corresponding new variable.""" rev = direction =='d' curs = spssdata.Spssdata(indexes=varlist, names=False, accessType='w') for v in varlist: curs.append(v + suffix) curs.commitdict() for case in curs: curs.casevalues(sorted(case, reverse = rev)) curs.Cclose() vsort(['salbegin','salary']) end program. -Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Monday, December 11, 2006 12:14 PM To: [hidden email] Subject: Re: [SPSSX-L] Ranking within cases individually (Marta and Jan, I'm copying to you because you're probably the best MATRIX whizzes among us.) At 03:00 PM 12/8/2006, Erin Miles wrote: >I have a data set that gives me plant percent cover data for 2100 >plots (rows) and there are about 250 potential species that can be >present in each plot (rows). I need to sort/rank each row so that the >percent covers go from largest to smallest. For sorting variables within cases, the best technique that seems to exist is to use the GRADE function in the MATRIX language, which apparently calls an internal sort routine; this has been noted as the Ristow-Peck algorithm. Below is an example, SPSS draft output. Only just out of testing. There doesn't seem to be a way to do it without a LOOP in MATRIX. There's a lot of matrix tracing that could be omitted in production. The MATRIX SAVE wipes the working file. To join to the pre-existing file, save the latter and re-attach using MATCH FILES. And, here goes: LIST. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |-----------------------------|---------------------------| PLOT_ID COVR01 COVR02 COVR03 COVR04 COVR05 PLOT001 7% 26% 44% 16% 8% PLOT002 51% 18% 25% 2% 5% PLOT003 6% 2% 38% 6% 48% PLOT004 51% 17% 6% 25% 1% PLOT005 4% 46% 9% 9% 33% PLOT006 60% 5% 8% 1% 26% PLOT007 8% 4% 13% 6% 69% PLOT008 21% 36% 8% 12% 22% PLOT009 6% 41% 2% 21% 30% PLOT010 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 MATRIX. GET PLOT_ID /FILE=*/VARIABLES=PLOT_ID. GET COVER /FILE=*/VARIABLES=COVR01 TO COVR05. PRINT PLOT_ID /FORMAT='A8'. PRINT COVER/FORMAT='F5.1'/RNAMES=PLOT_ID. COMPUTE CVR_SORT = 0*COVER. COMPUTE CVR_ORDR = 0*COVER. LOOP ROW = 1 TO NROW(COVER). PRINT ROW. COMPUTE ROW_ORDR = GRADE(-1*COVER(ROW,:)). COMPUTE CVR_ORDR(ROW,:) = Row_ORDR. COMPUTE CVR_SORT(ROW,Row_Ordr) = COVER(Row,:). COMPUTE ROW_RSLT ={COVER(ROW,:) ; CVR_ORDR(ROW,:); CVR_SORT(ROW,:)}. PRINT ROW_RSLT /FORMAT=F5.1 /RLABELS='Input','Order','Sorted'. END LOOP. PRINT CVR_ORDR/RNAMES=PLOT_ID. PRINT CVR_SORT/FORMAT='F5.1'/RNAMES=PLOT_ID. SAVE {PLOT_ID,CVR_SORT,CVR_ORDR,COVER} /OUTFILE=* /VARIABLES=PLOT_ID,SORTED01 TO SORTED05, ORDER01 TO ORDER05, COVER01 To COVER05 /STRINGS=PLOT_ID. END MATRIX. Notes |--------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |--------------------------|---------------------------| Run MATRIX procedure: PLOT_ID PLOT001 PLOT002 PLOT003 PLOT004 PLOT005 PLOT006 PLOT007 PLOT008 PLOT009 PLOT010 COVER PLOT001 6.9 26.0 43.6 15.8 7.8 PLOT002 50.5 17.9 24.8 2.3 4.6 PLOT003 5.9 1.7 37.5 6.4 48.5 PLOT004 51.4 16.8 5.9 25.2 .7 PLOT005 3.7 45.9 8.9 8.7 32.8 PLOT006 59.7 5.2 8.0 1.1 26.0 PLOT007 7.8 3.7 12.8 6.4 69.2 PLOT008 21.4 36.5 7.8 12.4 21.9 PLOT009 6.4 41.0 1.9 20.7 30.0 PLOT010 50.4 7.0 13.6 26.6 2.5 ROW 1 ROW_RSLT Input 6.9 26.0 43.6 15.8 7.8 Order 5.0 2.0 1.0 3.0 4.0 Sorted 43.6 26.0 15.8 7.8 6.9 ROW 2 ROW_RSLT Input 50.5 17.9 24.8 2.3 4.6 Order 1.0 3.0 2.0 5.0 4.0 Sorted 50.5 24.8 17.9 4.6 2.3 ROW 3 ROW_RSLT Input 5.9 1.7 37.5 6.4 48.5 Order 4.0 5.0 2.0 3.0 1.0 Sorted 48.5 37.5 6.4 5.9 1.7 ROW 4 ROW_RSLT Input 51.4 16.8 5.9 25.2 .7 Order 1.0 3.0 4.0 2.0 5.0 Sorted 51.4 25.2 16.8 5.9 .7 ROW 5 ROW_RSLT Input 3.7 45.9 8.9 8.7 32.8 Order 5.0 1.0 3.0 4.0 2.0 Sorted 45.9 32.8 8.9 8.7 3.7 ROW 6 ROW_RSLT Input 59.7 5.2 8.0 1.1 26.0 Order 1.0 4.0 3.0 5.0 2.0 Sorted 59.7 26.0 8.0 5.2 1.1 ROW 7 ROW_RSLT Input 7.8 3.7 12.8 6.4 69.2 Order 3.0 5.0 2.0 4.0 1.0 Sorted 69.2 12.8 7.8 6.4 3.7 ROW 8 ROW_RSLT Input 21.4 36.5 7.8 12.4 21.9 Order 3.0 1.0 5.0 4.0 2.0 Sorted 36.5 21.9 21.4 12.4 7.8 ROW 9 ROW_RSLT Input 6.4 41.0 1.9 20.7 30.0 Order 4.0 1.0 5.0 3.0 2.0 Sorted 41.0 30.0 20.7 6.4 1.9 ROW 10 ROW_RSLT Input 50.4 7.0 13.6 26.6 2.5 Order 1.0 4.0 3.0 2.0 5.0 Sorted 50.4 26.6 13.6 7.0 2.5 CVR_ORDR PLOT001 5 2 1 3 4 PLOT002 1 3 2 5 4 PLOT003 4 5 2 3 1 PLOT004 1 3 4 2 5 PLOT005 5 1 3 4 2 PLOT006 1 4 3 5 2 PLOT007 3 5 2 4 1 PLOT008 3 1 5 4 2 PLOT009 4 1 5 3 2 PLOT010 1 4 3 2 5 CVR_SORT PLOT001 43.6 26.0 15.8 7.8 6.9 PLOT002 50.5 24.8 17.9 4.6 2.3 PLOT003 48.5 37.5 6.4 5.9 1.7 PLOT004 51.4 25.2 16.8 5.9 .7 PLOT005 45.9 32.8 8.9 8.7 3.7 PLOT006 59.7 26.0 8.0 5.2 1.1 PLOT007 69.2 12.8 7.8 6.4 3.7 PLOT008 36.5 21.9 21.4 12.4 7.8 PLOT009 41.0 30.0 20.7 6.4 1.9 PLOT010 50.4 26.6 13.6 7.0 2.5 ------ END MATRIX ----- FORMATS ORDER01 TO ORDER05 (F3) /SORTED01 TO SORTED05 (PCT3), /COVER01 TO COVER05 (PCT3). TEMPORARY. STRING SPACE(A8). LIST VARIABLES=PLOT_ID SORTED01 TO SORTED05 ORDER01 TO ORDER05 COVER01 TO COVER05 SPACE. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:30 | |-----------------------------|---------------------------| SOR SOR SOR SOR SOR ORD ORD ORD ORD ORD COV COV TED TED TED TED TED ER0 ER0 ER0 ER0 ER0 ER0 ER0 COVE COVE COVE PLOT_ID 01 02 03 04 05 1 2 3 4 5 1 2 R03 R04 R05 SPACE PLOT001 44% 26% 16% 8% 7% 5 2 1 3 4 7% 26% 44% 16% 8% PLOT002 51% 25% 18% 5% 2% 1 3 2 5 4 51% 18% 25% 2% 5% PLOT003 48% 38% 6% 6% 2% 4 5 2 3 1 6% 2% 38% 6% 48% PLOT004 51% 25% 17% 6% 1% 1 3 4 2 5 51% 17% 6% 25% 1% PLOT005 46% 33% 9% 9% 4% 5 1 3 4 2 4% 46% 9% 9% 33% PLOT006 60% 26% 8% 5% 1% 1 4 3 5 2 60% 5% 8% 1% 26% PLOT007 69% 13% 8% 6% 4% 3 5 2 4 1 8% 4% 13% 6% 69% PLOT008 36% 22% 21% 12% 8% 3 1 5 4 2 21% 36% 8% 12% 22% PLOT009 41% 30% 21% 6% 2% 4 1 5 3 2 6% 41% 2% 21% 30% PLOT010 50% 27% 14% 7% 2% 1 4 3 2 5 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 =================== APPENDIX: TEST DATA =================== * ............ Test data ............ . * 05 species, 10 cases (plots) . * Abundances exponentially distributed with mean 100, . * normalized to total abundance 1 and converted to (UGH!) . * SPSS 'percents' for display. . NEW FILE. INPUT PROGRAM. . STRING PLOT_ID (A8). . NUMERIC COVR01 TO COVR05 (F4). . VECTOR COVER = COVR01 TO COVR05. . LOOP #PLOT = 1 TO 10. . COMPUTE PLOT_ID = CONCAT('PLOT',STRING(#PLOT,N3)). . LOOP #PLANT = 1 TO 5. . COMPUTE COVER(#PLANT)=RV.EXP(.01). . END LOOP. * Normalize, to total cover = 1 . . . COMPUTE #TOTAL = SUM(COVR01 TO COVR05). . LOOP #PLANT = 1 TO 05. * The multiplication by 100, below, is because of . * SPSS's very unfortunate implementation of PCT . * formats. Sigh. . . COMPUTE COVER(#PLANT)=100*COVER(#PLANT)/#TOTAL. . END LOOP. . END CASE. . END LOOP. . FORMATS COVR01 TO COVR05 (PCT3). END FILE. END INPUT PROGRAM. |
In reply to this post by Erin Miles
Assuming that each observation represents a separate record something
like: ObservationID PlotNumber SpeciesCode PctCover Then: SORT CASES BY PlotNumber PctCover (D) . Puts records in descending order of PctCover within Plot Alternatively you could use split file processing with RANK: SORT CASES BY Plot SPLIT FILE BY Plot RANK Vars= PctCover D . Check RANK syntax for desired subcommands. Dennis Deck, PhD RMC Research Corporation [hidden email] -----Original Message----- From: Erin Miles [mailto:[hidden email]] Sent: Friday, December 08, 2006 12:01 PM Subject: Ranking within cases individually I have a data set that gives me plant percent cover data for 2100 plots (rows) and there are about 250 potential species that can be present in each plot (rows). I need to sort/rank each row so that the percent covers go from largest to smallest. For this purpose I do not need to retain the species name, I just need to rank the percent covers from greatest to least for EACH plot in order to create Species Rank-Abundance graphs. Can anyone help me with this task? Much Thanks! Erin _________________________________________________________________ Get free, personalized commercial-free online radio with MSN Radio powered by Pandora http://radio.msn.com/?icid=T002MSN03A07001 |
In reply to this post by Erin Miles
A postscript:
First, the other approach I'd consider is to 'unroll' the data with VARSTOCASES, so each abundance value is in a separate case, and use SORT CASES. Second, I've tried out a variation on the code I posted. Here, "Sourcexx" gives which plant is in the position in the sorted sequence; formerly, "ORDERxx" gave which position in the sorted sequence the original plant would have. Here's the output; I won't post the code, now. List |-----------------------------|---------------------------| |Output Created |11-DEC-2006 14:49:51 | |-----------------------------|---------------------------| SOR SOR SOR SOR SOR Sou Sou Sou Sou Sou COV COV COV COV TED TED TED TED TED rce rce rce rce rce ER0 ER0 ER0 ER0 COVE PLOT_ID 01 02 03 04 05 01 02 03 04 05 1 2 3 4 R05 PLOT001 57% 18% 11% 7% 7% 4 5 1 3 2 11% 7% 7% 57% 18% PLOT002 67% 14% 14% 5% 0% 3 1 5 2 4 14% 5% 67% 0% 14% PLOT003 38% 23% 17% 16% 7% 1 3 5 4 2 38% 7% 23% 16% 17% PLOT004 50% 24% 11% 9% 6% 5 1 3 2 4 24% 9% 11% 6% 50% PLOT005 40% 27% 23% 7% 3% 4 5 2 1 3 7% 23% 3% 40% 27% PLOT006 34% 24% 23% 15% 5% 3 4 2 1 5 15% 23% 34% 24% 5% PLOT007 49% 20% 18% 13% 0% 4 5 2 3 1 0% 18% 13% 49% 20% PLOT008 34% 19% 16% 16% 15% 4 5 2 3 1 15% 16% 16% 34% 19% PLOT009 49% 25% 20% 4% 2% 2 4 1 5 3 20% 49% 2% 25% 4% PLOT010 62% 14% 13% 10% 1% 5 4 2 3 1 1% 13% 10% 14% 62% Number of cases read: 10 Number of cases listed: 10 |
In reply to this post by Peck, Jon
Jon,
What would I have to do to make this work in version 14.0.1? I tried running the code but 'accessType' appears to generate a problem! Thank You Mike -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peck, Jon Sent: Monday, December 11, 2006 1:52 PM To: [hidden email] Subject: Re: Ranking within cases individually Here is a Python solution assuming SPSS 15 and programmability are installed. First it defines a general function for this task and then it calls it with two variables as an example. The part in triple quotes is the documentation for the function. sysmis values sort low. It creates new variables with the sorted values. The "for v in varlist" loop creates new variables; the "for case in curs" loops over the cases begin program. import spss, spssdata def vsort(varlist, direction='a', suffix='_sorted'): """sort variables, assumed to be numeric, within cases creating new variables varlist is the list of variables to sort. direction can be 'a' or 'd' for ascending or descending. suffix is the string to append to the original name for the corresponding new variable.""" rev = direction =='d' curs = spssdata.Spssdata(indexes=varlist, names=False, accessType='w') for v in varlist: curs.append(v + suffix) curs.commitdict() for case in curs: curs.casevalues(sorted(case, reverse = rev)) curs.Cclose() vsort(['salbegin','salary']) end program. -Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Monday, December 11, 2006 12:14 PM To: [hidden email] Subject: Re: [SPSSX-L] Ranking within cases individually (Marta and Jan, I'm copying to you because you're probably the best MATRIX whizzes among us.) At 03:00 PM 12/8/2006, Erin Miles wrote: >I have a data set that gives me plant percent cover data for 2100 plots >(rows) and there are about 250 potential species that can be present in >each plot (rows). I need to sort/rank each row so that the percent >covers go from largest to smallest. For sorting variables within cases, the best technique that seems to exist is to use the GRADE function in the MATRIX language, which apparently calls an internal sort routine; this has been noted as the Ristow-Peck algorithm. Below is an example, SPSS draft output. Only just out of testing. There doesn't seem to be a way to do it without a LOOP in MATRIX. There's a lot of matrix tracing that could be omitted in production. The MATRIX SAVE wipes the working file. To join to the pre-existing file, save the latter and re-attach using MATCH FILES. And, here goes: LIST. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |-----------------------------|---------------------------| PLOT_ID COVR01 COVR02 COVR03 COVR04 COVR05 PLOT001 7% 26% 44% 16% 8% PLOT002 51% 18% 25% 2% 5% PLOT003 6% 2% 38% 6% 48% PLOT004 51% 17% 6% 25% 1% PLOT005 4% 46% 9% 9% 33% PLOT006 60% 5% 8% 1% 26% PLOT007 8% 4% 13% 6% 69% PLOT008 21% 36% 8% 12% 22% PLOT009 6% 41% 2% 21% 30% PLOT010 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 MATRIX. GET PLOT_ID /FILE=*/VARIABLES=PLOT_ID. GET COVER /FILE=*/VARIABLES=COVR01 TO COVR05. PRINT PLOT_ID /FORMAT='A8'. PRINT COVER/FORMAT='F5.1'/RNAMES=PLOT_ID. COMPUTE CVR_SORT = 0*COVER. COMPUTE CVR_ORDR = 0*COVER. LOOP ROW = 1 TO NROW(COVER). PRINT ROW. COMPUTE ROW_ORDR = GRADE(-1*COVER(ROW,:)). COMPUTE CVR_ORDR(ROW,:) = Row_ORDR. COMPUTE CVR_SORT(ROW,Row_Ordr) = COVER(Row,:). COMPUTE ROW_RSLT ={COVER(ROW,:) ; CVR_ORDR(ROW,:); CVR_SORT(ROW,:)}. PRINT ROW_RSLT /FORMAT=F5.1 /RLABELS='Input','Order','Sorted'. END LOOP. PRINT CVR_ORDR/RNAMES=PLOT_ID. PRINT CVR_SORT/FORMAT='F5.1'/RNAMES=PLOT_ID. SAVE {PLOT_ID,CVR_SORT,CVR_ORDR,COVER} /OUTFILE=* /VARIABLES=PLOT_ID,SORTED01 TO SORTED05, ORDER01 TO ORDER05, COVER01 To COVER05 /STRINGS=PLOT_ID. END MATRIX. Notes |--------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |--------------------------|---------------------------| Run MATRIX procedure: PLOT_ID PLOT001 PLOT002 PLOT003 PLOT004 PLOT005 PLOT006 PLOT007 PLOT008 PLOT009 PLOT010 COVER PLOT001 6.9 26.0 43.6 15.8 7.8 PLOT002 50.5 17.9 24.8 2.3 4.6 PLOT003 5.9 1.7 37.5 6.4 48.5 PLOT004 51.4 16.8 5.9 25.2 .7 PLOT005 3.7 45.9 8.9 8.7 32.8 PLOT006 59.7 5.2 8.0 1.1 26.0 PLOT007 7.8 3.7 12.8 6.4 69.2 PLOT008 21.4 36.5 7.8 12.4 21.9 PLOT009 6.4 41.0 1.9 20.7 30.0 PLOT010 50.4 7.0 13.6 26.6 2.5 ROW 1 ROW_RSLT Input 6.9 26.0 43.6 15.8 7.8 Order 5.0 2.0 1.0 3.0 4.0 Sorted 43.6 26.0 15.8 7.8 6.9 ROW 2 ROW_RSLT Input 50.5 17.9 24.8 2.3 4.6 Order 1.0 3.0 2.0 5.0 4.0 Sorted 50.5 24.8 17.9 4.6 2.3 ROW 3 ROW_RSLT Input 5.9 1.7 37.5 6.4 48.5 Order 4.0 5.0 2.0 3.0 1.0 Sorted 48.5 37.5 6.4 5.9 1.7 ROW 4 ROW_RSLT Input 51.4 16.8 5.9 25.2 .7 Order 1.0 3.0 4.0 2.0 5.0 Sorted 51.4 25.2 16.8 5.9 .7 ROW 5 ROW_RSLT Input 3.7 45.9 8.9 8.7 32.8 Order 5.0 1.0 3.0 4.0 2.0 Sorted 45.9 32.8 8.9 8.7 3.7 ROW 6 ROW_RSLT Input 59.7 5.2 8.0 1.1 26.0 Order 1.0 4.0 3.0 5.0 2.0 Sorted 59.7 26.0 8.0 5.2 1.1 ROW 7 ROW_RSLT Input 7.8 3.7 12.8 6.4 69.2 Order 3.0 5.0 2.0 4.0 1.0 Sorted 69.2 12.8 7.8 6.4 3.7 ROW 8 ROW_RSLT Input 21.4 36.5 7.8 12.4 21.9 Order 3.0 1.0 5.0 4.0 2.0 Sorted 36.5 21.9 21.4 12.4 7.8 ROW 9 ROW_RSLT Input 6.4 41.0 1.9 20.7 30.0 Order 4.0 1.0 5.0 3.0 2.0 Sorted 41.0 30.0 20.7 6.4 1.9 ROW 10 ROW_RSLT Input 50.4 7.0 13.6 26.6 2.5 Order 1.0 4.0 3.0 2.0 5.0 Sorted 50.4 26.6 13.6 7.0 2.5 CVR_ORDR PLOT001 5 2 1 3 4 PLOT002 1 3 2 5 4 PLOT003 4 5 2 3 1 PLOT004 1 3 4 2 5 PLOT005 5 1 3 4 2 PLOT006 1 4 3 5 2 PLOT007 3 5 2 4 1 PLOT008 3 1 5 4 2 PLOT009 4 1 5 3 2 PLOT010 1 4 3 2 5 CVR_SORT PLOT001 43.6 26.0 15.8 7.8 6.9 PLOT002 50.5 24.8 17.9 4.6 2.3 PLOT003 48.5 37.5 6.4 5.9 1.7 PLOT004 51.4 25.2 16.8 5.9 .7 PLOT005 45.9 32.8 8.9 8.7 3.7 PLOT006 59.7 26.0 8.0 5.2 1.1 PLOT007 69.2 12.8 7.8 6.4 3.7 PLOT008 36.5 21.9 21.4 12.4 7.8 PLOT009 41.0 30.0 20.7 6.4 1.9 PLOT010 50.4 26.6 13.6 7.0 2.5 ------ END MATRIX ----- FORMATS ORDER01 TO ORDER05 (F3) /SORTED01 TO SORTED05 (PCT3), /COVER01 TO COVER05 (PCT3). TEMPORARY. STRING SPACE(A8). LIST VARIABLES=PLOT_ID SORTED01 TO SORTED05 ORDER01 TO ORDER05 COVER01 TO COVER05 SPACE. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:30 | |-----------------------------|---------------------------| SOR SOR SOR SOR SOR ORD ORD ORD ORD ORD COV COV TED TED TED TED TED ER0 ER0 ER0 ER0 ER0 ER0 ER0 COVE COVE COVE PLOT_ID 01 02 03 04 05 1 2 3 4 5 1 2 R03 R04 R05 SPACE PLOT001 44% 26% 16% 8% 7% 5 2 1 3 4 7% 26% 44% 16% 8% PLOT002 51% 25% 18% 5% 2% 1 3 2 5 4 51% 18% 25% 2% 5% PLOT003 48% 38% 6% 6% 2% 4 5 2 3 1 6% 2% 38% 6% 48% PLOT004 51% 25% 17% 6% 1% 1 3 4 2 5 51% 17% 6% 25% 1% PLOT005 46% 33% 9% 9% 4% 5 1 3 4 2 4% 46% 9% 9% 33% PLOT006 60% 26% 8% 5% 1% 1 4 3 5 2 60% 5% 8% 1% 26% PLOT007 69% 13% 8% 6% 4% 3 5 2 4 1 8% 4% 13% 6% 69% PLOT008 36% 22% 21% 12% 8% 3 1 5 4 2 21% 36% 8% 12% 22% PLOT009 41% 30% 21% 6% 2% 4 1 5 3 2 6% 41% 2% 21% 30% PLOT010 50% 27% 14% 7% 2% 1 4 3 2 5 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 =================== APPENDIX: TEST DATA =================== * ............ Test data ............ . * 05 species, 10 cases (plots) . * Abundances exponentially distributed with mean 100, . * normalized to total abundance 1 and converted to (UGH!) . * SPSS 'percents' for display. . NEW FILE. INPUT PROGRAM. . STRING PLOT_ID (A8). . NUMERIC COVR01 TO COVR05 (F4). . VECTOR COVER = COVR01 TO COVR05. . LOOP #PLOT = 1 TO 10. . COMPUTE PLOT_ID = CONCAT('PLOT',STRING(#PLOT,N3)). . LOOP #PLANT = 1 TO 5. . COMPUTE COVER(#PLANT)=RV.EXP(.01). . END LOOP. * Normalize, to total cover = 1 . . . COMPUTE #TOTAL = SUM(COVR01 TO COVR05). . LOOP #PLANT = 1 TO 05. * The multiplication by 100, below, is because of . * SPSS's very unfortunate implementation of PCT . * formats. Sigh. . . COMPUTE COVER(#PLANT)=100*COVER(#PLANT)/#TOTAL. . END LOOP. . END CASE. . END LOOP. . FORMATS COVR01 TO COVR05 (PCT3). END FILE. END INPUT PROGRAM. |
accessType is a parameter new to SPSS 15, which added the ability to write new variables to the active file (accessType='w') or to append new cases (accessType='a'). In SPSS 14, you would need to do this indirectly by, for example, writing the cases to a text file and then reading that with a DATA LIST command.
I could post syntax for that if this is too mysterious and there is interest. -Jon Peck -----Original Message----- From: Roberts, Michael [mailto:[hidden email]] Sent: Monday, December 11, 2006 4:22 PM To: Peck, Jon; [hidden email] Subject: RE: Re: Ranking within cases individually Jon, What would I have to do to make this work in version 14.0.1? I tried running the code but 'accessType' appears to generate a problem! Thank You Mike -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peck, Jon Sent: Monday, December 11, 2006 1:52 PM To: [hidden email] Subject: Re: Ranking within cases individually Here is a Python solution assuming SPSS 15 and programmability are installed. First it defines a general function for this task and then it calls it with two variables as an example. The part in triple quotes is the documentation for the function. sysmis values sort low. It creates new variables with the sorted values. The "for v in varlist" loop creates new variables; the "for case in curs" loops over the cases begin program. import spss, spssdata def vsort(varlist, direction='a', suffix='_sorted'): """sort variables, assumed to be numeric, within cases creating new variables varlist is the list of variables to sort. direction can be 'a' or 'd' for ascending or descending. suffix is the string to append to the original name for the corresponding new variable.""" rev = direction =='d' curs = spssdata.Spssdata(indexes=varlist, names=False, accessType='w') for v in varlist: curs.append(v + suffix) curs.commitdict() for case in curs: curs.casevalues(sorted(case, reverse = rev)) curs.Cclose() vsort(['salbegin','salary']) end program. -Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Monday, December 11, 2006 12:14 PM To: [hidden email] Subject: Re: [SPSSX-L] Ranking within cases individually (Marta and Jan, I'm copying to you because you're probably the best MATRIX whizzes among us.) At 03:00 PM 12/8/2006, Erin Miles wrote: >I have a data set that gives me plant percent cover data for 2100 plots >(rows) and there are about 250 potential species that can be present in >each plot (rows). I need to sort/rank each row so that the percent >covers go from largest to smallest. For sorting variables within cases, the best technique that seems to exist is to use the GRADE function in the MATRIX language, which apparently calls an internal sort routine; this has been noted as the Ristow-Peck algorithm. Below is an example, SPSS draft output. Only just out of testing. There doesn't seem to be a way to do it without a LOOP in MATRIX. There's a lot of matrix tracing that could be omitted in production. The MATRIX SAVE wipes the working file. To join to the pre-existing file, save the latter and re-attach using MATCH FILES. And, here goes: LIST. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |-----------------------------|---------------------------| PLOT_ID COVR01 COVR02 COVR03 COVR04 COVR05 PLOT001 7% 26% 44% 16% 8% PLOT002 51% 18% 25% 2% 5% PLOT003 6% 2% 38% 6% 48% PLOT004 51% 17% 6% 25% 1% PLOT005 4% 46% 9% 9% 33% PLOT006 60% 5% 8% 1% 26% PLOT007 8% 4% 13% 6% 69% PLOT008 21% 36% 8% 12% 22% PLOT009 6% 41% 2% 21% 30% PLOT010 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 MATRIX. GET PLOT_ID /FILE=*/VARIABLES=PLOT_ID. GET COVER /FILE=*/VARIABLES=COVR01 TO COVR05. PRINT PLOT_ID /FORMAT='A8'. PRINT COVER/FORMAT='F5.1'/RNAMES=PLOT_ID. COMPUTE CVR_SORT = 0*COVER. COMPUTE CVR_ORDR = 0*COVER. LOOP ROW = 1 TO NROW(COVER). PRINT ROW. COMPUTE ROW_ORDR = GRADE(-1*COVER(ROW,:)). COMPUTE CVR_ORDR(ROW,:) = Row_ORDR. COMPUTE CVR_SORT(ROW,Row_Ordr) = COVER(Row,:). COMPUTE ROW_RSLT ={COVER(ROW,:) ; CVR_ORDR(ROW,:); CVR_SORT(ROW,:)}. PRINT ROW_RSLT /FORMAT=F5.1 /RLABELS='Input','Order','Sorted'. END LOOP. PRINT CVR_ORDR/RNAMES=PLOT_ID. PRINT CVR_SORT/FORMAT='F5.1'/RNAMES=PLOT_ID. SAVE {PLOT_ID,CVR_SORT,CVR_ORDR,COVER} /OUTFILE=* /VARIABLES=PLOT_ID,SORTED01 TO SORTED05, ORDER01 TO ORDER05, COVER01 To COVER05 /STRINGS=PLOT_ID. END MATRIX. Notes |--------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:27 | |--------------------------|---------------------------| Run MATRIX procedure: PLOT_ID PLOT001 PLOT002 PLOT003 PLOT004 PLOT005 PLOT006 PLOT007 PLOT008 PLOT009 PLOT010 COVER PLOT001 6.9 26.0 43.6 15.8 7.8 PLOT002 50.5 17.9 24.8 2.3 4.6 PLOT003 5.9 1.7 37.5 6.4 48.5 PLOT004 51.4 16.8 5.9 25.2 .7 PLOT005 3.7 45.9 8.9 8.7 32.8 PLOT006 59.7 5.2 8.0 1.1 26.0 PLOT007 7.8 3.7 12.8 6.4 69.2 PLOT008 21.4 36.5 7.8 12.4 21.9 PLOT009 6.4 41.0 1.9 20.7 30.0 PLOT010 50.4 7.0 13.6 26.6 2.5 ROW 1 ROW_RSLT Input 6.9 26.0 43.6 15.8 7.8 Order 5.0 2.0 1.0 3.0 4.0 Sorted 43.6 26.0 15.8 7.8 6.9 ROW 2 ROW_RSLT Input 50.5 17.9 24.8 2.3 4.6 Order 1.0 3.0 2.0 5.0 4.0 Sorted 50.5 24.8 17.9 4.6 2.3 ROW 3 ROW_RSLT Input 5.9 1.7 37.5 6.4 48.5 Order 4.0 5.0 2.0 3.0 1.0 Sorted 48.5 37.5 6.4 5.9 1.7 ROW 4 ROW_RSLT Input 51.4 16.8 5.9 25.2 .7 Order 1.0 3.0 4.0 2.0 5.0 Sorted 51.4 25.2 16.8 5.9 .7 ROW 5 ROW_RSLT Input 3.7 45.9 8.9 8.7 32.8 Order 5.0 1.0 3.0 4.0 2.0 Sorted 45.9 32.8 8.9 8.7 3.7 ROW 6 ROW_RSLT Input 59.7 5.2 8.0 1.1 26.0 Order 1.0 4.0 3.0 5.0 2.0 Sorted 59.7 26.0 8.0 5.2 1.1 ROW 7 ROW_RSLT Input 7.8 3.7 12.8 6.4 69.2 Order 3.0 5.0 2.0 4.0 1.0 Sorted 69.2 12.8 7.8 6.4 3.7 ROW 8 ROW_RSLT Input 21.4 36.5 7.8 12.4 21.9 Order 3.0 1.0 5.0 4.0 2.0 Sorted 36.5 21.9 21.4 12.4 7.8 ROW 9 ROW_RSLT Input 6.4 41.0 1.9 20.7 30.0 Order 4.0 1.0 5.0 3.0 2.0 Sorted 41.0 30.0 20.7 6.4 1.9 ROW 10 ROW_RSLT Input 50.4 7.0 13.6 26.6 2.5 Order 1.0 4.0 3.0 2.0 5.0 Sorted 50.4 26.6 13.6 7.0 2.5 CVR_ORDR PLOT001 5 2 1 3 4 PLOT002 1 3 2 5 4 PLOT003 4 5 2 3 1 PLOT004 1 3 4 2 5 PLOT005 5 1 3 4 2 PLOT006 1 4 3 5 2 PLOT007 3 5 2 4 1 PLOT008 3 1 5 4 2 PLOT009 4 1 5 3 2 PLOT010 1 4 3 2 5 CVR_SORT PLOT001 43.6 26.0 15.8 7.8 6.9 PLOT002 50.5 24.8 17.9 4.6 2.3 PLOT003 48.5 37.5 6.4 5.9 1.7 PLOT004 51.4 25.2 16.8 5.9 .7 PLOT005 45.9 32.8 8.9 8.7 3.7 PLOT006 59.7 26.0 8.0 5.2 1.1 PLOT007 69.2 12.8 7.8 6.4 3.7 PLOT008 36.5 21.9 21.4 12.4 7.8 PLOT009 41.0 30.0 20.7 6.4 1.9 PLOT010 50.4 26.6 13.6 7.0 2.5 ------ END MATRIX ----- FORMATS ORDER01 TO ORDER05 (F3) /SORTED01 TO SORTED05 (PCT3), /COVER01 TO COVER05 (PCT3). TEMPORARY. STRING SPACE(A8). LIST VARIABLES=PLOT_ID SORTED01 TO SORTED05 ORDER01 TO ORDER05 COVER01 TO COVER05 SPACE. Notes |-----------------------------|---------------------------| |Output Created |11-DEC-2006 13:03:30 | |-----------------------------|---------------------------| SOR SOR SOR SOR SOR ORD ORD ORD ORD ORD COV COV TED TED TED TED TED ER0 ER0 ER0 ER0 ER0 ER0 ER0 COVE COVE COVE PLOT_ID 01 02 03 04 05 1 2 3 4 5 1 2 R03 R04 R05 SPACE PLOT001 44% 26% 16% 8% 7% 5 2 1 3 4 7% 26% 44% 16% 8% PLOT002 51% 25% 18% 5% 2% 1 3 2 5 4 51% 18% 25% 2% 5% PLOT003 48% 38% 6% 6% 2% 4 5 2 3 1 6% 2% 38% 6% 48% PLOT004 51% 25% 17% 6% 1% 1 3 4 2 5 51% 17% 6% 25% 1% PLOT005 46% 33% 9% 9% 4% 5 1 3 4 2 4% 46% 9% 9% 33% PLOT006 60% 26% 8% 5% 1% 1 4 3 5 2 60% 5% 8% 1% 26% PLOT007 69% 13% 8% 6% 4% 3 5 2 4 1 8% 4% 13% 6% 69% PLOT008 36% 22% 21% 12% 8% 3 1 5 4 2 21% 36% 8% 12% 22% PLOT009 41% 30% 21% 6% 2% 4 1 5 3 2 6% 41% 2% 21% 30% PLOT010 50% 27% 14% 7% 2% 1 4 3 2 5 50% 7% 14% 27% 2% Number of cases read: 10 Number of cases listed: 10 =================== APPENDIX: TEST DATA =================== * ............ Test data ............ . * 05 species, 10 cases (plots) . * Abundances exponentially distributed with mean 100, . * normalized to total abundance 1 and converted to (UGH!) . * SPSS 'percents' for display. . NEW FILE. INPUT PROGRAM. . STRING PLOT_ID (A8). . NUMERIC COVR01 TO COVR05 (F4). . VECTOR COVER = COVR01 TO COVR05. . LOOP #PLOT = 1 TO 10. . COMPUTE PLOT_ID = CONCAT('PLOT',STRING(#PLOT,N3)). . LOOP #PLANT = 1 TO 5. . COMPUTE COVER(#PLANT)=RV.EXP(.01). . END LOOP. * Normalize, to total cover = 1 . . . COMPUTE #TOTAL = SUM(COVR01 TO COVR05). . LOOP #PLANT = 1 TO 05. * The multiplication by 100, below, is because of . * SPSS's very unfortunate implementation of PCT . * formats. Sigh. . . COMPUTE COVER(#PLANT)=100*COVER(#PLANT)/#TOTAL. . END LOOP. . END CASE. . END LOOP. . FORMATS COVR01 TO COVR05 (PCT3). END FILE. END INPUT PROGRAM. |
In reply to this post by Roberts, Michael
Colleagues
I am checking some of the variables in my correlation data to get a graph of the percentage of responses at each of the seven items on a Likert scale. I am using the following command: GRAPH /BAR(SIMPLE)=PCT BY <NAME OF VARIABLE> . In this syntax I have to run the command for each variable separately. Is there a way of including all the variable names in the one command or must I have a separate command syntax for each variable. Warm regards/gary Unit Co-ordinator for Business Information Systems (A Postgraduate Master of Commerce and Master of Business unit) School of Business The University of Sydney ------------------------ ,-_|\ Building H69, Office 437 / \ Corner Codrington Street \_,-._* & Rose Street Darlington 2006 @ Australia -------------------------------------- E-mail: [hidden email] ------------------------ Location details: Travelling from Broadway, turn south off City Road Navigate toward the Acquatic Centre ------------------------ University Map: http://db.auth.usyd.edu.au/directories/map/index.stm University Website: www.usyd.edu.au Faculty Website www.econ.usyd.edu.au ------------------------ Faculty Student Information Office (Timetables, Special Consideration) Merewether Building Enter from City Road side e-mail: [hidden email] Phone: 9351-3076 ---------------------------------- Executive Officer for Business Information Systems Katy Roy Room 347, Building H69 E-mail: [hidden email] Phone: 9036 9432 --------------------------------- >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]] >>On Behalf Of Roberts, Michael >>Sent: Tuesday, December 12, 2006 9:22 AM >>To: [hidden email] >>Subject: Re: Ranking within cases individually >> >> Jon, >> >>What would I have to do to make this work in version 14.0.1? >>I tried running the code but 'accessType' appears to generate >>a problem! >> >>Thank You >> >>Mike >> >> >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]] >>On Behalf Of Peck, Jon >>Sent: Monday, December 11, 2006 1:52 PM >>To: [hidden email] >>Subject: Re: Ranking within cases individually >> >>Here is a Python solution assuming SPSS 15 and >>programmability are installed. >>First it defines a general function for this task and then it >>calls it with two variables as an example. >>The part in triple quotes is the documentation for the >>function. sysmis values sort low. >>It creates new variables with the sorted values. >> >>The "for v in varlist" loop creates new variables; the "for >>case in curs" loops over the cases >> >>begin program. >>import spss, spssdata >> >>def vsort(varlist, direction='a', suffix='_sorted'): >> """sort variables, assumed to be numeric, within >>cases creating new variables >> >> varlist is the list of variables to sort. >> direction can be 'a' or 'd' for ascending or descending. >> suffix is the string to append to the original name for the >> corresponding new variable.""" >> >> rev = direction =='d' >> curs = spssdata.Spssdata(indexes=varlist, names=False, >>accessType='w') >> for v in varlist: >> curs.append(v + suffix) >> curs.commitdict() >> for case in curs: >> curs.casevalues(sorted(case, reverse = rev)) >> curs.Cclose() >> >>vsort(['salbegin','salary']) >>end program. >> >>-Jon Peck >> >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]] >>On Behalf Of Richard Ristow >>Sent: Monday, December 11, 2006 12:14 PM >>To: [hidden email] >>Subject: Re: [SPSSX-L] Ranking within cases individually >> >>(Marta and Jan, I'm copying to you because you're probably >>the best MATRIX whizzes among us.) >> >>At 03:00 PM 12/8/2006, Erin Miles wrote: >> >>>I have a data set that gives me plant percent cover data for >>2100 plots >> >>>(rows) and there are about 250 potential species that can be >>present in >> >>>each plot (rows). I need to sort/rank each row so that the percent >>>covers go from largest to smallest. >> >>For sorting variables within cases, the best technique that >>seems to exist is to use the GRADE function in the MATRIX >>language, which apparently calls an internal sort routine; >>this has been noted as the Ristow-Peck algorithm. Below is an >>example, SPSS draft output. Only just out of testing. There >>doesn't seem to be a way to do it without a LOOP in MATRIX. >> >>There's a lot of matrix tracing that could be omitted in production. >> >>The MATRIX SAVE wipes the working file. To join to the >>pre-existing file, save the latter and re-attach using MATCH >>FILES. And, here goes: >> >>LIST. >> >>Notes >>|-----------------------------|---------------------------| >>|Output Created |11-DEC-2006 13:03:27 | >>|-----------------------------|---------------------------| >>PLOT_ID COVR01 COVR02 COVR03 COVR04 COVR05 >> >>PLOT001 7% 26% 44% 16% 8% >>PLOT002 51% 18% 25% 2% 5% >>PLOT003 6% 2% 38% 6% 48% >>PLOT004 51% 17% 6% 25% 1% >>PLOT005 4% 46% 9% 9% 33% >>PLOT006 60% 5% 8% 1% 26% >>PLOT007 8% 4% 13% 6% 69% >>PLOT008 21% 36% 8% 12% 22% >>PLOT009 6% 41% 2% 21% 30% >>PLOT010 50% 7% 14% 27% 2% >> >>Number of cases read: 10 Number of cases listed: 10 >> >> >>MATRIX. >>GET PLOT_ID /FILE=*/VARIABLES=PLOT_ID. >>GET COVER /FILE=*/VARIABLES=COVR01 TO COVR05. >>PRINT PLOT_ID /FORMAT='A8'. >>PRINT COVER/FORMAT='F5.1'/RNAMES=PLOT_ID. >> >>COMPUTE CVR_SORT = 0*COVER. >>COMPUTE CVR_ORDR = 0*COVER. >> >>LOOP ROW = 1 TO NROW(COVER). >>PRINT ROW. >>COMPUTE ROW_ORDR = GRADE(-1*COVER(ROW,:)). >>COMPUTE CVR_ORDR(ROW,:) = Row_ORDR. >>COMPUTE CVR_SORT(ROW,Row_Ordr) = COVER(Row,:). >> >> >>COMPUTE ROW_RSLT ={COVER(ROW,:) ; >> CVR_ORDR(ROW,:); >> CVR_SORT(ROW,:)}. >>PRINT ROW_RSLT /FORMAT=F5.1 >> /RLABELS='Input','Order','Sorted'. >> >>END LOOP. >> >>PRINT CVR_ORDR/RNAMES=PLOT_ID. >>PRINT CVR_SORT/FORMAT='F5.1'/RNAMES=PLOT_ID. >> >>SAVE {PLOT_ID,CVR_SORT,CVR_ORDR,COVER} >> /OUTFILE=* >> /VARIABLES=PLOT_ID,SORTED01 TO SORTED05, >> ORDER01 TO ORDER05, >> COVER01 To COVER05 >> /STRINGS=PLOT_ID. >>END MATRIX. >> >>Notes >>|--------------------------|---------------------------| >>|Output Created |11-DEC-2006 13:03:27 | >>|--------------------------|---------------------------| >>Run MATRIX procedure: >> >>PLOT_ID >> PLOT001 >> PLOT002 >> PLOT003 >> PLOT004 >> PLOT005 >> PLOT006 >> PLOT007 >> PLOT008 >> PLOT009 >> PLOT010 >> >>COVER >>PLOT001 6.9 26.0 43.6 15.8 7.8 >>PLOT002 50.5 17.9 24.8 2.3 4.6 >>PLOT003 5.9 1.7 37.5 6.4 48.5 >>PLOT004 51.4 16.8 5.9 25.2 .7 >>PLOT005 3.7 45.9 8.9 8.7 32.8 >>PLOT006 59.7 5.2 8.0 1.1 26.0 >>PLOT007 7.8 3.7 12.8 6.4 69.2 >>PLOT008 21.4 36.5 7.8 12.4 21.9 >>PLOT009 6.4 41.0 1.9 20.7 30.0 >>PLOT010 50.4 7.0 13.6 26.6 2.5 >> >>ROW >> 1 >> >>ROW_RSLT >>Input 6.9 26.0 43.6 15.8 7.8 >>Order 5.0 2.0 1.0 3.0 4.0 >>Sorted 43.6 26.0 15.8 7.8 6.9 >> >>ROW >> 2 >> >>ROW_RSLT >>Input 50.5 17.9 24.8 2.3 4.6 >>Order 1.0 3.0 2.0 5.0 4.0 >>Sorted 50.5 24.8 17.9 4.6 2.3 >> >>ROW >> 3 >> >>ROW_RSLT >>Input 5.9 1.7 37.5 6.4 48.5 >>Order 4.0 5.0 2.0 3.0 1.0 >>Sorted 48.5 37.5 6.4 5.9 1.7 >> >>ROW >> 4 >> >>ROW_RSLT >>Input 51.4 16.8 5.9 25.2 .7 >>Order 1.0 3.0 4.0 2.0 5.0 >>Sorted 51.4 25.2 16.8 5.9 .7 >> >>ROW >> 5 >> >>ROW_RSLT >>Input 3.7 45.9 8.9 8.7 32.8 >>Order 5.0 1.0 3.0 4.0 2.0 >>Sorted 45.9 32.8 8.9 8.7 3.7 >> >>ROW >> 6 >> >>ROW_RSLT >>Input 59.7 5.2 8.0 1.1 26.0 >>Order 1.0 4.0 3.0 5.0 2.0 >>Sorted 59.7 26.0 8.0 5.2 1.1 >> >>ROW >> 7 >> >>ROW_RSLT >>Input 7.8 3.7 12.8 6.4 69.2 >>Order 3.0 5.0 2.0 4.0 1.0 >>Sorted 69.2 12.8 7.8 6.4 3.7 >> >>ROW >> 8 >> >>ROW_RSLT >>Input 21.4 36.5 7.8 12.4 21.9 >>Order 3.0 1.0 5.0 4.0 2.0 >>Sorted 36.5 21.9 21.4 12.4 7.8 >> >>ROW >> 9 >> >>ROW_RSLT >>Input 6.4 41.0 1.9 20.7 30.0 >>Order 4.0 1.0 5.0 3.0 2.0 >>Sorted 41.0 30.0 20.7 6.4 1.9 >> >>ROW >> 10 >> >>ROW_RSLT >>Input 50.4 7.0 13.6 26.6 2.5 >>Order 1.0 4.0 3.0 2.0 5.0 >>Sorted 50.4 26.6 13.6 7.0 2.5 >> >>CVR_ORDR >>PLOT001 5 2 1 3 4 >>PLOT002 1 3 2 5 4 >>PLOT003 4 5 2 3 1 >>PLOT004 1 3 4 2 5 >>PLOT005 5 1 3 4 2 >>PLOT006 1 4 3 5 2 >>PLOT007 3 5 2 4 1 >>PLOT008 3 1 5 4 2 >>PLOT009 4 1 5 3 2 >>PLOT010 1 4 3 2 5 >> >>CVR_SORT >>PLOT001 43.6 26.0 15.8 7.8 6.9 >>PLOT002 50.5 24.8 17.9 4.6 2.3 >>PLOT003 48.5 37.5 6.4 5.9 1.7 >>PLOT004 51.4 25.2 16.8 5.9 .7 >>PLOT005 45.9 32.8 8.9 8.7 3.7 >>PLOT006 59.7 26.0 8.0 5.2 1.1 >>PLOT007 69.2 12.8 7.8 6.4 3.7 >>PLOT008 36.5 21.9 21.4 12.4 7.8 >>PLOT009 41.0 30.0 20.7 6.4 1.9 >>PLOT010 50.4 26.6 13.6 7.0 2.5 >> >>------ END MATRIX ----- >> >> >>FORMATS ORDER01 TO ORDER05 (F3) >> /SORTED01 TO SORTED05 (PCT3), >> /COVER01 TO COVER05 (PCT3). >>TEMPORARY. >>STRING SPACE(A8). >>LIST VARIABLES=PLOT_ID >> SORTED01 TO SORTED05 >> ORDER01 TO ORDER05 >> COVER01 TO COVER05 >> SPACE. >> >>Notes >>|-----------------------------|---------------------------| >>|Output Created |11-DEC-2006 13:03:30 | >>|-----------------------------|---------------------------| >> SOR SOR SOR SOR SOR ORD ORD ORD ORD ORD COV COV >> TED TED TED TED TED ER0 ER0 ER0 ER0 ER0 ER0 ER0 >>COVE COVE COVE >>PLOT_ID 01 02 03 04 05 1 2 3 4 5 1 2 R03 R04 R05 >>SPACE >> >>PLOT001 44% 26% 16% 8% 7% 5 2 1 3 4 7% 26% 44% >> 16% 8% >>PLOT002 51% 25% 18% 5% 2% 1 3 2 5 4 51% 18% 25% >> 2% 5% >>PLOT003 48% 38% 6% 6% 2% 4 5 2 3 1 6% 2% 38% >> 6% 48% >>PLOT004 51% 25% 17% 6% 1% 1 3 4 2 5 51% 17% 6% >> 25% 1% >>PLOT005 46% 33% 9% 9% 4% 5 1 3 4 2 4% 46% 9% >> 9% 33% >>PLOT006 60% 26% 8% 5% 1% 1 4 3 5 2 60% 5% 8% >> 1% 26% >>PLOT007 69% 13% 8% 6% 4% 3 5 2 4 1 8% 4% 13% >> 6% 69% >>PLOT008 36% 22% 21% 12% 8% 3 1 5 4 2 21% 36% 8% >> 12% 22% >>PLOT009 41% 30% 21% 6% 2% 4 1 5 3 2 6% 41% 2% >> 21% 30% >>PLOT010 50% 27% 14% 7% 2% 1 4 3 2 5 50% 7% 14% >> 27% 2% >> >>Number of cases read: 10 Number of cases listed: 10 >> >>=================== >>APPENDIX: TEST DATA >>=================== >>* ............ Test data ............ . >>* 05 species, 10 cases (plots) . >>* Abundances exponentially distributed with mean 100, . >>* normalized to total abundance 1 and converted to (UGH!) . >>* SPSS 'percents' for display. . >> >>NEW FILE. >>INPUT PROGRAM. >>. STRING PLOT_ID (A8). >>. NUMERIC COVR01 TO COVR05 (F4). >>. VECTOR COVER = >> COVR01 TO COVR05. >>. LOOP #PLOT = 1 TO 10. >>. COMPUTE PLOT_ID = CONCAT('PLOT',STRING(#PLOT,N3)). >>. LOOP #PLANT = 1 TO 5. >>. COMPUTE COVER(#PLANT)=RV.EXP(.01). >>. END LOOP. >>* Normalize, to total cover = 1 . . >>. COMPUTE #TOTAL = SUM(COVR01 TO COVR05). >>. LOOP #PLANT = 1 TO 05. >>* The multiplication by 100, below, is because of . >>* SPSS's very unfortunate implementation of PCT . >>* formats. Sigh. . >>. COMPUTE COVER(#PLANT)=100*COVER(#PLANT)/#TOTAL. >>. END LOOP. >>. END CASE. >>. END LOOP. >>. FORMATS COVR01 TO COVR05 (PCT3). >>END FILE. >>END INPUT PROGRAM. >> |
In reply to this post by Roberts, Michael
Colleagues
In my last inquiry I was trying to make the simple bar graph syntax work for more than one variable. Having looked at the output for both the GRAPH and the FREQUENCIES command, it seems to me that SPSS will only report for each of the scale points within my Likert if there is a case using that value. That is, it will report: extremely undesirable=101, neutral=183 but not: undesirable=0, desirable=0, extremely desirable=0. My question is: Is it possible to force SPSS to report where the percentage (or count) is none? Warm regards/gary Unit Co-ordinator for Business Information Systems (A Postgraduate Master of Commerce and Master of Business unit) School of Business The University of Sydney ------------------------ ,-_|\ Building H69, Office 437 / \ Corner Codrington Street \_,-._* & Rose Street Darlington 2006 @ Australia -------------------------------------- E-mail: [hidden email] ------------------------ Location details: Travelling from Broadway, turn south off City Road Navigate toward the Acquatic Centre ------------------------ University Map: http://db.auth.usyd.edu.au/directories/map/index.stm University Website: www.usyd.edu.au Faculty Website www.econ.usyd.edu.au ------------------------ Faculty Student Information Office (Timetables, Special Consideration) Merewether Building Enter from City Road side e-mail: [hidden email] Phone: 9351-3076 ---------------------------------- Executive Officer for Business Information Systems Katy Roy Room 347, Building H69 E-mail: [hidden email] Phone: 9036 9432 --------------------------------- >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]] >>On Behalf Of Roberts, Michael >>Sent: Tuesday, December 12, 2006 9:22 AM >>To: [hidden email] >>Subject: Re: Ranking within cases individually >> >> Jon, >> >>What would I have to do to make this work in version 14.0.1? >>I tried running the code but 'accessType' appears to generate >>a problem! >> >>Thank You >> >>Mike >> >> >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]] >>On Behalf Of Peck, Jon >>Sent: Monday, December 11, 2006 1:52 PM >>To: [hidden email] >>Subject: Re: Ranking within cases individually >> >>Here is a Python solution assuming SPSS 15 and >>programmability are installed. >>First it defines a general function for this task and then it >>calls it with two variables as an example. >>The part in triple quotes is the documentation for the >>function. sysmis values sort low. >>It creates new variables with the sorted values. >> >>The "for v in varlist" loop creates new variables; the "for >>case in curs" loops over the cases >> >>begin program. >>import spss, spssdata >> >>def vsort(varlist, direction='a', suffix='_sorted'): >> """sort variables, assumed to be numeric, within >>cases creating new variables >> >> varlist is the list of variables to sort. >> direction can be 'a' or 'd' for ascending or descending. >> suffix is the string to append to the original name for the >> corresponding new variable.""" >> >> rev = direction =='d' >> curs = spssdata.Spssdata(indexes=varlist, names=False, >>accessType='w') >> for v in varlist: >> curs.append(v + suffix) >> curs.commitdict() >> for case in curs: >> curs.casevalues(sorted(case, reverse = rev)) >> curs.Cclose() >> >>vsort(['salbegin','salary']) >>end program. >> >>-Jon Peck >> >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]] >>On Behalf Of Richard Ristow >>Sent: Monday, December 11, 2006 12:14 PM >>To: [hidden email] >>Subject: Re: [SPSSX-L] Ranking within cases individually >> >>(Marta and Jan, I'm copying to you because you're probably >>the best MATRIX whizzes among us.) >> >>At 03:00 PM 12/8/2006, Erin Miles wrote: >> >>>I have a data set that gives me plant percent cover data for >>2100 plots >> >>>(rows) and there are about 250 potential species that can be >>present in >> >>>each plot (rows). I need to sort/rank each row so that the percent >>>covers go from largest to smallest. >> >>For sorting variables within cases, the best technique that >>seems to exist is to use the GRADE function in the MATRIX >>language, which apparently calls an internal sort routine; >>this has been noted as the Ristow-Peck algorithm. Below is an >>example, SPSS draft output. Only just out of testing. There >>doesn't seem to be a way to do it without a LOOP in MATRIX. >> >>There's a lot of matrix tracing that could be omitted in production. >> >>The MATRIX SAVE wipes the working file. To join to the >>pre-existing file, save the latter and re-attach using MATCH >>FILES. And, here goes: >> >>LIST. >> >>Notes >>|-----------------------------|---------------------------| >>|Output Created |11-DEC-2006 13:03:27 | >>|-----------------------------|---------------------------| >>PLOT_ID COVR01 COVR02 COVR03 COVR04 COVR05 >> >>PLOT001 7% 26% 44% 16% 8% >>PLOT002 51% 18% 25% 2% 5% >>PLOT003 6% 2% 38% 6% 48% >>PLOT004 51% 17% 6% 25% 1% >>PLOT005 4% 46% 9% 9% 33% >>PLOT006 60% 5% 8% 1% 26% >>PLOT007 8% 4% 13% 6% 69% >>PLOT008 21% 36% 8% 12% 22% >>PLOT009 6% 41% 2% 21% 30% >>PLOT010 50% 7% 14% 27% 2% >> >>Number of cases read: 10 Number of cases listed: 10 >> >> >>MATRIX. >>GET PLOT_ID /FILE=*/VARIABLES=PLOT_ID. >>GET COVER /FILE=*/VARIABLES=COVR01 TO COVR05. >>PRINT PLOT_ID /FORMAT='A8'. >>PRINT COVER/FORMAT='F5.1'/RNAMES=PLOT_ID. >> >>COMPUTE CVR_SORT = 0*COVER. >>COMPUTE CVR_ORDR = 0*COVER. >> >>LOOP ROW = 1 TO NROW(COVER). >>PRINT ROW. >>COMPUTE ROW_ORDR = GRADE(-1*COVER(ROW,:)). >>COMPUTE CVR_ORDR(ROW,:) = Row_ORDR. >>COMPUTE CVR_SORT(ROW,Row_Ordr) = COVER(Row,:). >> >> >>COMPUTE ROW_RSLT ={COVER(ROW,:) ; >> CVR_ORDR(ROW,:); >> CVR_SORT(ROW,:)}. >>PRINT ROW_RSLT /FORMAT=F5.1 >> /RLABELS='Input','Order','Sorted'. >> >>END LOOP. >> >>PRINT CVR_ORDR/RNAMES=PLOT_ID. >>PRINT CVR_SORT/FORMAT='F5.1'/RNAMES=PLOT_ID. >> >>SAVE {PLOT_ID,CVR_SORT,CVR_ORDR,COVER} >> /OUTFILE=* >> /VARIABLES=PLOT_ID,SORTED01 TO SORTED05, >> ORDER01 TO ORDER05, >> COVER01 To COVER05 >> /STRINGS=PLOT_ID. >>END MATRIX. >> >>Notes >>|--------------------------|---------------------------| >>|Output Created |11-DEC-2006 13:03:27 | >>|--------------------------|---------------------------| >>Run MATRIX procedure: >> >>PLOT_ID >> PLOT001 >> PLOT002 >> PLOT003 >> PLOT004 >> PLOT005 >> PLOT006 >> PLOT007 >> PLOT008 >> PLOT009 >> PLOT010 >> >>COVER >>PLOT001 6.9 26.0 43.6 15.8 7.8 >>PLOT002 50.5 17.9 24.8 2.3 4.6 >>PLOT003 5.9 1.7 37.5 6.4 48.5 >>PLOT004 51.4 16.8 5.9 25.2 .7 >>PLOT005 3.7 45.9 8.9 8.7 32.8 >>PLOT006 59.7 5.2 8.0 1.1 26.0 >>PLOT007 7.8 3.7 12.8 6.4 69.2 >>PLOT008 21.4 36.5 7.8 12.4 21.9 >>PLOT009 6.4 41.0 1.9 20.7 30.0 >>PLOT010 50.4 7.0 13.6 26.6 2.5 >> >>ROW >> 1 >> >>ROW_RSLT >>Input 6.9 26.0 43.6 15.8 7.8 >>Order 5.0 2.0 1.0 3.0 4.0 >>Sorted 43.6 26.0 15.8 7.8 6.9 >> >>ROW >> 2 >> >>ROW_RSLT >>Input 50.5 17.9 24.8 2.3 4.6 >>Order 1.0 3.0 2.0 5.0 4.0 >>Sorted 50.5 24.8 17.9 4.6 2.3 >> >>ROW >> 3 >> >>ROW_RSLT >>Input 5.9 1.7 37.5 6.4 48.5 >>Order 4.0 5.0 2.0 3.0 1.0 >>Sorted 48.5 37.5 6.4 5.9 1.7 >> >>ROW >> 4 >> >>ROW_RSLT >>Input 51.4 16.8 5.9 25.2 .7 >>Order 1.0 3.0 4.0 2.0 5.0 >>Sorted 51.4 25.2 16.8 5.9 .7 >> >>ROW >> 5 >> >>ROW_RSLT >>Input 3.7 45.9 8.9 8.7 32.8 >>Order 5.0 1.0 3.0 4.0 2.0 >>Sorted 45.9 32.8 8.9 8.7 3.7 >> >>ROW >> 6 >> >>ROW_RSLT >>Input 59.7 5.2 8.0 1.1 26.0 >>Order 1.0 4.0 3.0 5.0 2.0 >>Sorted 59.7 26.0 8.0 5.2 1.1 >> >>ROW >> 7 >> >>ROW_RSLT >>Input 7.8 3.7 12.8 6.4 69.2 >>Order 3.0 5.0 2.0 4.0 1.0 >>Sorted 69.2 12.8 7.8 6.4 3.7 >> >>ROW >> 8 >> >>ROW_RSLT >>Input 21.4 36.5 7.8 12.4 21.9 >>Order 3.0 1.0 5.0 4.0 2.0 >>Sorted 36.5 21.9 21.4 12.4 7.8 >> >>ROW >> 9 >> >>ROW_RSLT >>Input 6.4 41.0 1.9 20.7 30.0 >>Order 4.0 1.0 5.0 3.0 2.0 >>Sorted 41.0 30.0 20.7 6.4 1.9 >> >>ROW >> 10 >> >>ROW_RSLT >>Input 50.4 7.0 13.6 26.6 2.5 >>Order 1.0 4.0 3.0 2.0 5.0 >>Sorted 50.4 26.6 13.6 7.0 2.5 >> >>CVR_ORDR >>PLOT001 5 2 1 3 4 >>PLOT002 1 3 2 5 4 >>PLOT003 4 5 2 3 1 >>PLOT004 1 3 4 2 5 >>PLOT005 5 1 3 4 2 >>PLOT006 1 4 3 5 2 >>PLOT007 3 5 2 4 1 >>PLOT008 3 1 5 4 2 >>PLOT009 4 1 5 3 2 >>PLOT010 1 4 3 2 5 >> >>CVR_SORT >>PLOT001 43.6 26.0 15.8 7.8 6.9 >>PLOT002 50.5 24.8 17.9 4.6 2.3 >>PLOT003 48.5 37.5 6.4 5.9 1.7 >>PLOT004 51.4 25.2 16.8 5.9 .7 >>PLOT005 45.9 32.8 8.9 8.7 3.7 >>PLOT006 59.7 26.0 8.0 5.2 1.1 >>PLOT007 69.2 12.8 7.8 6.4 3.7 >>PLOT008 36.5 21.9 21.4 12.4 7.8 >>PLOT009 41.0 30.0 20.7 6.4 1.9 >>PLOT010 50.4 26.6 13.6 7.0 2.5 >> >>------ END MATRIX ----- >> >> >>FORMATS ORDER01 TO ORDER05 (F3) >> /SORTED01 TO SORTED05 (PCT3), >> /COVER01 TO COVER05 (PCT3). >>TEMPORARY. >>STRING SPACE(A8). >>LIST VARIABLES=PLOT_ID >> SORTED01 TO SORTED05 >> ORDER01 TO ORDER05 >> COVER01 TO COVER05 >> SPACE. >> >>Notes >>|-----------------------------|---------------------------| >>|Output Created |11-DEC-2006 13:03:30 | >>|-----------------------------|---------------------------| >> SOR SOR SOR SOR SOR ORD ORD ORD ORD ORD COV COV >> TED TED TED TED TED ER0 ER0 ER0 ER0 ER0 ER0 ER0 >>COVE COVE COVE >>PLOT_ID 01 02 03 04 05 1 2 3 4 5 1 2 R03 R04 R05 >>SPACE >> >>PLOT001 44% 26% 16% 8% 7% 5 2 1 3 4 7% 26% 44% >> 16% 8% >>PLOT002 51% 25% 18% 5% 2% 1 3 2 5 4 51% 18% 25% >> 2% 5% >>PLOT003 48% 38% 6% 6% 2% 4 5 2 3 1 6% 2% 38% >> 6% 48% >>PLOT004 51% 25% 17% 6% 1% 1 3 4 2 5 51% 17% 6% >> 25% 1% >>PLOT005 46% 33% 9% 9% 4% 5 1 3 4 2 4% 46% 9% >> 9% 33% >>PLOT006 60% 26% 8% 5% 1% 1 4 3 5 2 60% 5% 8% >> 1% 26% >>PLOT007 69% 13% 8% 6% 4% 3 5 2 4 1 8% 4% 13% >> 6% 69% >>PLOT008 36% 22% 21% 12% 8% 3 1 5 4 2 21% 36% 8% >> 12% 22% >>PLOT009 41% 30% 21% 6% 2% 4 1 5 3 2 6% 41% 2% >> 21% 30% >>PLOT010 50% 27% 14% 7% 2% 1 4 3 2 5 50% 7% 14% >> 27% 2% >> >>Number of cases read: 10 Number of cases listed: 10 >> >>=================== >>APPENDIX: TEST DATA >>=================== >>* ............ Test data ............ . >>* 05 species, 10 cases (plots) . >>* Abundances exponentially distributed with mean 100, . >>* normalized to total abundance 1 and converted to (UGH!) . >>* SPSS 'percents' for display. . >> >>NEW FILE. >>INPUT PROGRAM. >>. STRING PLOT_ID (A8). >>. NUMERIC COVR01 TO COVR05 (F4). >>. VECTOR COVER = >> COVR01 TO COVR05. >>. LOOP #PLOT = 1 TO 10. >>. COMPUTE PLOT_ID = CONCAT('PLOT',STRING(#PLOT,N3)). >>. LOOP #PLANT = 1 TO 5. >>. COMPUTE COVER(#PLANT)=RV.EXP(.01). >>. END LOOP. >>* Normalize, to total cover = 1 . . >>. COMPUTE #TOTAL = SUM(COVR01 TO COVR05). >>. LOOP #PLANT = 1 TO 05. >>* The multiplication by 100, below, is because of . >>* SPSS's very unfortunate implementation of PCT . >>* formats. Sigh. . >>. COMPUTE COVER(#PLANT)=100*COVER(#PLANT)/#TOTAL. >>. END LOOP. >>. END CASE. >>. END LOOP. >>. FORMATS COVR01 TO COVR05 (PCT3). >>END FILE. >>END INPUT PROGRAM. >> |
Hi Gary
Wednesday, December 13, 2006, 7:39:22 AM, You wrote: GO> In my last inquiry I was trying to make the simple bar graph syntax work GO> for more than one variable. GO> Having looked at the output for both the GRAPH and the FREQUENCIES GO> command, it seems to me that SPSS will only report for each of the scale GO> points within my Likert if there is a case using that value. That is, it GO> will report: extremely undesirable=101, neutral=183 but not: GO> undesirable=0, desirable=0, extremely desirable=0. GO> My question is: Is it possible to force SPSS to report where the GO> percentage (or count) is none? You can to your file 5 cases corresponding to each of the categories, give them a very low weight and then runn the frequencies/graph you want. The following code solves it assuming that your likert scale goes from 1 to 5: * Fake data (replace by your own) *. DATA LIST LIST/var1 TO var7 (7 F8). BEGIN DATA 1 2 4 1 5 1 3 3 5 3 5 4 4 2 END DATA. VALUE LABEL var1 TO var4 1 'Extremely undesirable' 2 'Undesirable' 3 'Neutral' 4 'Desirable' 5 'Extremely desirable'. FREQ VAR=ALL. MATRIX. GET data /VAR=ALL /NAMES=vnames /MISSING=OMIT. COMPUTE k=NCOL(data). COMPUTE Emptycat=T(MAKE(k,1,1)*{1:5}). COMPUTE weight=MAKE(5,1,0.000001). Compute AllNames={vnames,'weight'}. SAVE {EmptyCat,weight} /OUTFILE='C:\Temp\EmptyCategories.sav' /NAMES=AllNames. END MATRIX. COMPUTE WEIGHT=1. ADD FILES /FILE=* /FILE='C:\temp\EmptyCategories.sav'. WEIGHT BY weight. * See result *. FREQ VAR=ALL. GRAPH /BAR(SIMPLE)=PCT BY var1. Regards, Marta |
In reply to this post by Peck, Jon
Dear List,
Please pardon my posing this question here, but apparently the answer is so obvious (to everyone but me) that it is not worthy of discussion in any of the survival analysis material I have at hand. Q: For cases that are (right) censored is the time variable set to missing, or to date of data collection / end of study? Thanks in advance, John |
Set it to the last chance of knowing whether the terminal event occurred
(e.g. so you can say that as of MM/DD/YYYY, the terminal event had NOT occurred.) I am not sure if that is the end of the study or the last date of data collection for the client? Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of John Painter Sent: Thursday, January 04, 2007 2:47 PM To: [hidden email] Subject: [SPSSX-L] survival analysis question Dear List, Please pardon my posing this question here, but apparently the answer is so obvious (to everyone but me) that it is not worthy of discussion in any of the survival analysis material I have at hand. Q: For cases that are (right) censored is the time variable set to missing, or to date of data collection / end of study? Thanks in advance, John PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
In reply to this post by John Painter
The time variable should be set at the date of end of study, and the
event variable to zero. This means that at the end of the study the subject had not yet undergone the event (e.g. he/she was still alive). If the time variable is missing, the case would be excluded from the analysis, instead of been treated as censored. Hector -----Mensaje original----- De: SPSSX(r) Discussion [mailto:[hidden email]] En nombre de John Painter Enviado el: 04 January 2007 17:47 Para: [hidden email] Asunto: survival analysis question Dear List, Please pardon my posing this question here, but apparently the answer is so obvious (to everyone but me) that it is not worthy of discussion in any of the survival analysis material I have at hand. Q: For cases that are (right) censored is the time variable set to missing, or to date of data collection / end of study? Thanks in advance, John |
In reply to this post by Melissa Ives
Melissa is right. In my answer I implicitly assumed continuous
observation, so the last time of observation was also the end of the study, but for discrete observations the last time a subject was observed or checked may have been before the official end of the study. Hector -----Mensaje original----- De: SPSSX(r) Discussion [mailto:[hidden email]] En nombre de Melissa Ives Enviado el: 04 January 2007 17:53 Para: [hidden email] Asunto: Re: survival analysis question Set it to the last chance of knowing whether the terminal event occurred (e.g. so you can say that as of MM/DD/YYYY, the terminal event had NOT occurred.) I am not sure if that is the end of the study or the last date of data collection for the client? Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of John Painter Sent: Thursday, January 04, 2007 2:47 PM To: [hidden email] Subject: [SPSSX-L] survival analysis question Dear List, Please pardon my posing this question here, but apparently the answer is so obvious (to everyone but me) that it is not worthy of discussion in any of the survival analysis material I have at hand. Q: For cases that are (right) censored is the time variable set to missing, or to date of data collection / end of study? Thanks in advance, John PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
Free forum by Nabble | Edit this page |