Hello everyone,
I'm trying to change a matrix in a way so that very column is sorted by values. Ex.:
A1 1 7 3 5 2 6 4 4 3 5 5 3 4 4 6 2 5 3 7 1 6 2 8 0
=>
A2 1 2 3 0 2 3 4 1 3 4 5 2 4 5 6 3 5 6 7 4 6 7 8 5
a) Is there an easy way to do that? I could not find a sort function. b) How can I sort columns 1 and 3 in descending order and columns 2 and 4 in ascending order?
Thanks for any help!
GL, Mario
Mario Giesel
Munich, Germany |
Check that this is what you want. Just curious, what is the purpose of such a sort? Art Kendall Social Research Consultants data list list/col1 to col4 (4f1). begin data 1 7 3 5 2 6 4 4 3 5 5 3 4 4 6 2 5 3 7 1 6 2 8 0 end data. dataset name original. dataset copy column1. list. dataset copy column2. dataset copy column3. dataset copy column4. dataset activate column1. delete variables col2 col3 col4. sort cases by col1. dataset activate column2. delete variables col1 col3 col4. sort cases by col2. dataset activate column3. delete variables col1 col2 col4. sort cases by col3. dataset activate column4. delete variables col1 col2 col3. sort cases by col4. match files /file = column1 /file = column2 /file = column3 /file = column4. dataset name target. dataset activate target. list. On 1/20/2011 8:03 AM, Mario Giesel wrote: ===================== 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
Art Kendall
Social Research Consultants |
Administrator
|
In reply to this post by Mario Giesel
Mario,
I can't imagine ANY reason that you would want/need to do this. After all, data are arranged in rows and the rows have a logical connection (they constitute a case of data). At any rate MATRIX=END MATRIX does *NOT* have a SORT function. You will need to SORT in SPSS individually on the columns, keeping track of the new row positions ($CASENUM). Blast the data from WIDE to LONG and then reorganize the rows in accordance to the new indexes. SEE VARSTOCASES AND CASESTOVARS, or various applications of VECTOR/XSAVE/AGGREGATE I and others have posted over the years. HTH, David --- On Thu, 20 Jan 2011 13:03:17 +0000, Mario Giesel <[hidden email]> wrote: >Hello everyone, � I'm trying to change a matrix in a way so that very column is sorted by values. Ex.: � A1 1�7 3 5 2�6 4 4 3�5 5 3 4�4 6 2 5�3 7 1 6 2 8 0 � => A2 1�2 3 0 2�3 4 1 3�4 5 2 4�5 6 3 5�6 7 4 6�7 8 5 � a) Is there an easy way to do that? I could not find a sort function. b) How can I sort columns 1 and 3 in descending order and columns 2 and 4 in ascending order? � Thanks for any help! � GL, �Mario ===================== 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?" |
Administrator
|
In reply to this post by Mario Giesel
For Example:
DATA LIST FREE /X1 X2 X3 X4. begin data 1 2 3 0 2 3 4 1 3 4 5 2 4 5 6 3 5 6 7 4 6 7 8 5 end data. SORT CASES BY X1 (D). COMPUTE ID1=$CASENUM. SORT CASES BY X2 (A). COMPUTE ID2=$CASENUM. SORT CASES BY X3 (D). COMPUTE ID3=$CASENUM. SORT CASES BY X4 (A). COMPUTE ID4=$CASENUM. VARSTOCASES /MAKE X FROM X1 X2 X3 X4 /MAKE Index FROM ID1 ID2 ID3 ID4 /INDEX=VARID(4) . SORT CASES BY Index VARID. CASESTOVARS /ID=Index /INDEX= VARID /GROUPBY=VARIABLE. On Thu, 20 Jan 2011 10:05:44 -0500, David Marso <[hidden email]> wrote: >Mario, >I can't imagine ANY reason that you would want/need to do this. >After all, data are arranged in rows and the rows have a logical connection >(they constitute a case of data). >At any rate MATRIX=END MATRIX does *NOT* have a SORT function. >You will need to SORT in SPSS individually on the columns, keeping track of >the new row positions ($CASENUM). Blast the data from WIDE to LONG and then >reorganize the rows in accordance to the new indexes. SEE VARSTOCASES AND >CASESTOVARS, or various applications of VECTOR/XSAVE/AGGREGATE I and others >have posted over the years. >HTH, David >--- >On Thu, 20 Jan 2011 13:03:17 +0000, Mario Giesel <[hidden email]> wrote: > >>Hello everyone, >� >I'm trying to change a matrix in a way so that very column is sorted by values. >Ex.: >� >A1 >1�7 3 5 >2�6 4 4 >3�5 5 3 >4�4 6 2 >5�3 7 1 >6 2 8 0 >� >=> >A2 >1�2 3 0 >2�3 4 1 >3�4 5 2 >4�5 6 3 >5�6 7 4 >6�7 8 5 >� >a) Is there an easy way to do that? I could not find a sort function. >b) How can I sort columns 1 and 3 in descending order and columns 2 and 4 in >ascending order? >� >Thanks for any help! >� >GL, >�Mario > ===================== 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?" |
In reply to this post by David Marso
At 10:05 AM 1/20/2011, David Marso wrote:
>At any rate MATRIX=END MATRIX does *NOT* have a SORT function. As a matter of fact, it does; more precisely, it has a function, GRADE, which will generate a sort order that can be used to sort the matrix. Sorting using GRADE has been discussed on the list as the Ristow-Peck algorithm. Here's an illustration, by Jon Peck(1): >* Example dataset (3 variables & 5 rows) *. >INPUT PROGRAM. >- VECTOR x(3). >- LOOP #I = 1 TO 5. >- LOOP #J = 1 TO 3. >- compute x(#J) = 10 -#i-#j. >- END LOOP. >- END CASE. >- END LOOP. >- END FILE. >END INPUT PROGRAM. >EXEC. >FORMAT ALL (F8.0). > >MATRIX. >GET A/FILE=*. >PRINT A. >compute b = a. >compute b(grade(a(:,2)),:) = a. >print b. >END MATRIX. Below, my original discussion(2); which, however, had to be corrected by Jon Peck, because MATRIX's definition of GRADE is not the same as APL's: >Marta jogged my memory on this one: >>COMPUTE order=GRADE(A(:,2)) will create a vector (order) with the >>position of every data in the second column of matrix A. > >I think that GRADE is meant as the sorting command for MATRIX: don't >return the sorted array; return the index vector that *will* sort the >array. (This is one of the 'footprints' that make me think that >MATRIX was influenced by the programming language APL.) It has its >points; for example, you can sort the rows of an array by a key >vector that's in a different array. > >It's somewhat buried in the documentation, but MATRIX (like APL) >allows a vector as an array index, applying the elements of the >vector individually to give a vector (or array) result. I think this >is how the developers expected you'd sort a matrix ====================================================== (1) Date: Wed, 16 Mar 2005 08:31:27 -0600 From: "Peck, Jon" <[hidden email]> Subject: Re: Sorting matrices To: [hidden email] (2) Date: Wed, 16 Mar 2005 00:44:39 -0500 From: Richard Ristow <[hidden email]> Subject: Re: Sorting matrices To: [hidden email] X-ELNK-AV: 0 ===================== 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 |
Administrator
|
In reply to this post by Mario Giesel
Thanks Richard,
I Don't know how I missed that ;=). Especially since I've been tangling with MATRIX over the past several days on a consulting project. OTOH: My MultiSort/Data dismemberment/Resmack method seems slightly more intuitive. Wonder why they just didn't call it SORT? David -- On Thu, 20 Jan 2011 12:11:02 -0500, Richard Ristow <[hidden email]> wrote: >At 10:05 AM 1/20/2011, David Marso wrote: > >>At any rate MATRIX=END MATRIX does *NOT* have a SORT function. > >As a matter of fact, it does; more precisely, it has a function, >GRADE, which will generate a sort order that can be used to sort the >matrix. Sorting using GRADE has been discussed on the list as the >Ristow-Peck algorithm. Here's an illustration, by Jon Peck(1): > >>* Example dataset (3 variables & 5 rows) *. >>INPUT PROGRAM. >>- VECTOR x(3). >>- LOOP #I = 1 TO 5. >>- LOOP #J = 1 TO 3. >>- compute x(#J) = 10 -#i-#j. >>- END LOOP. >>- END CASE. >>- END LOOP. >>- END FILE. >>END INPUT PROGRAM. >>EXEC. >>FORMAT ALL (F8.0). >> >>MATRIX. >>GET A/FILE=*. >>PRINT A. >>compute b = a. >>compute b(grade(a(:,2)),:) = a. >>print b. >>END MATRIX. > >Below, my original discussion(2); which, however, had to be corrected >by Jon Peck, because MATRIX's definition of GRADE is not the same as APL's: > >>Marta jogged my memory on this one: >>>COMPUTE order=GRADE(A(:,2)) will create a vector (order) with the >>>position of every data in the second column of matrix A. >> >>I think that GRADE is meant as the sorting command for MATRIX: don't >>return the sorted array; return the index vector that *will* sort the >>array. (This is one of the 'footprints' that make me think that >>MATRIX was influenced by the programming language APL.) It has its >>points; for example, you can sort the rows of an array by a key >>vector that's in a different array. >> >>It's somewhat buried in the documentation, but MATRIX (like APL) >>allows a vector as an array index, applying the elements of the >>vector individually to give a vector (or array) result. I think this >>is how the developers expected you'd sort a matrix > >====================================================== >(1) Date: Wed, 16 Mar 2005 08:31:27 -0600 > From: "Peck, Jon" <[hidden email]> > Subject: Re: Sorting matrices > To: [hidden email] > >(2) Date: Wed, 16 Mar 2005 00:44:39 -0500 > From: Richard Ristow <[hidden email]> > Subject: Re: Sorting matrices > To: [hidden email] >X-ELNK-AV: 0 > >===================== >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?" |
At 11:56 AM 1/21/2011, David Marso wrote:
>I Don't know how I missed ["GRADE"]. Wonder why they just didn't call it SORT? As I wrote, this and a few other indications suggest to me that the designers of MATRIX were influenced by the programming language APL, which was itself (among other things) partly matrix oriented. APL's function for sorting was *named* 'grade' (it was *written* in APL's own character set, as a triangle overstruck with a vertical bar <:-| ); and, I suppose, wasn't called 'sort' because it didn't sort its argument, but returned a vector of indices that *would* sort it. ===================== 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 |
I almost titled this "not an SPSS question" but we seem to be still in the
thread with that title. This isn't an SPSS question - at least I don't think so - but I know there are a bunch of statisticians on the list so I hope you'll forgive me. An friend and associate asked me about 'correlations' he was doing with Excel on some data from employee satisfaction surveys. When he told me it was from results reported at location level, I said "you can't do that". But then I looked at the spreadsheet and said maybe something could be done (I'm not academic as you can tell). There are about 400 observations, but 21 locations - ranging from 4 to 39 observations for each location. There are 44 questions, with an overall average and 3 indices (no idea how these were derived). Each location is reported as favorable, unfavorable (percentages I presume), and trend from previous waves. My friend ran the Excel Correlate function against the total data (aggregate of aggregates), for each question correlated to the overall average, and then each question against each other. So, my questions (so far) are: Can you draw any inferences from these aggregate data? With 21 locations, isn't this below the Central Limit Theory, or is that irrelevant because of the observations for each location? Are there appropriate techniques to analyze this type of aggregate data? I'm happy with correlations of the total of all locations, and with comparisons between the locations (bearing in mind small sample sizes). But are there other things I could look at? TIA! Mike ===================== 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 |
Multilevel modelling might be an option, though the # of locations is
on the lower end of the recommended range. Ryan On Sat, Apr 23, 2011 at 10:54 PM, Mike Pritchard <[hidden email]> wrote: > I almost titled this "not an SPSS question" but we seem to be still in the > thread with that title. > > This isn't an SPSS question - at least I don't think so - but I know there > are a bunch of statisticians on the list so I hope you'll forgive me. > > An friend and associate asked me about 'correlations' he was doing with > Excel on some data from employee satisfaction surveys. When he told me it > was from results reported at location level, I said "you can't do that". But > then I looked at the spreadsheet and said maybe something could be done (I'm > not academic as you can tell). There are about 400 observations, but 21 > locations - ranging from 4 to 39 observations for each location. There > are 44 questions, with an overall average and 3 indices (no idea how these > were derived). Each location is reported as favorable, unfavorable > (percentages I presume), and trend from previous waves. > > My friend ran the Excel Correlate function against the total data (aggregate > of aggregates), for each question correlated to the overall average, and > then each question against each other. > > So, my questions (so far) are: > > Can you draw any inferences from these aggregate data? With 21 locations, > isn't this below the Central Limit Theory, or is that irrelevant because of > the observations for each location? > > Are there appropriate techniques to analyze this type of aggregate data? > I'm happy with correlations of the total of all locations, and with > comparisons between the locations (bearing in mind small sample sizes). But > are there other things I could look at? > > TIA! > Mike > > ===================== > 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 |
Free forum by Nabble | Edit this page |