matrix data unscrambling problem

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

matrix data unscrambling problem

Maguin, Eugene

I have variance-covariance matrix (lower triangle) written to a text file in serial format, five values per line. I need to restructure the data to a lower triangle form so that it can eventually be read into spss via Matrix Data. As I understand what spss can do, there is no way to use spss to read the matrix directly in such way that it is correctly structured. I haven’t been able to think of a way to use spss read the file and restructure the data values into lower triangular form.  However, I do figure that it could be done using the Matrix command set, which I’m not familiar with and would prefer to avoid getting familiar. I’m also quite sure it could be done in Python but I’m not familiar with that either.

 

So any ideas about how to do this using the spss command set?

 

Thanks, Gene Maguin

Reply | Threaded
Open this post in threaded view
|

Re: matrix data unscrambling problem

Bruce Weaver
Administrator
Gene, maybe it's just a "too late on Friday afternoon" problem, but I'm struggling a bit to understand what the original text file looks like.  Can you show us (i.e., paste it into a message)?  Thanks.



Maguin, Eugene wrote
I have variance-covariance matrix (lower triangle) written to a text file in serial format, five values per line. I need to restructure the data to a lower triangle form so that it can eventually be read into spss via Matrix Data. As I understand what spss can do, there is no way to use spss to read the matrix directly in such way that it is correctly structured. I haven't been able to think of a way to use spss read the file and restructure the data values into lower triangular form.  However, I do figure that it could be done using the Matrix command set, which I'm not familiar with and would prefer to avoid getting familiar. I'm also quite sure it could be done in Python but I'm not familiar with that either.

So any ideas about how to do this using the spss command set?

Thanks, Gene Maguin
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

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

Re: matrix data unscrambling problem

Maguin, Eugene
Sure.
Suppose you have a 6x6 variance-covariance matrix. Written out in lower triangle (LT) form, you have

11
21 22
31 32 33
41 42 43 44
51 52 53 54 55
61 62 63 64 65 66

Where the numbers are the row,col coordinates. In the real matrix, there would be decimal numbers.
Anyway, the matrix comes out of mplus like this

11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66

Five elements per row, six rows total.

So, how to get it back to LT form.



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Friday, November 15, 2013 4:50 PM
To: [hidden email]
Subject: Re: matrix data unscrambling problem

Gene, maybe it's just a "too late on Friday afternoon" problem, but I'm struggling a bit to understand what the original text file looks like.  Can you /show/ us (i.e., paste it into a message)?  Thanks.




Maguin, Eugene wrote

> I have variance-covariance matrix (lower triangle) written to a text
> file in serial format, five values per line. I need to restructure the
> data to a lower triangle form so that it can eventually be read into
> spss via Matrix Data. As I understand what spss can do, there is no
> way to use spss to read the matrix directly in such way that it is
> correctly structured. I haven't been able to think of a way to use
> spss read the file and restructure the data values into lower
> triangular form.  However, I do figure that it could be done using the
> Matrix command set, which I'm not familiar with and would prefer to
> avoid getting familiar. I'm also quite sure it could be done in Python but I'm not familiar with that either.
>
> So any ideas about how to do this using the spss command set?
>
> Thanks, Gene Maguin





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

"When all else fails, RTFM."

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

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723094.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

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

Re: matrix data unscrambling problem

Maguin, Eugene
In reply to this post by Bruce Weaver
I understand how to do it now. Pretty easily actually. Just a little trick. Here's the whole setup.  Gene Maguin

*  RESTRUCTURE MPLUS SAVEDATA FILE.
* DATA LIST FILE='U:\HILLSIDE\MPLUS2\RESTRUCTURETEST.TXT' FREE / V1 TO V36.
DATA LIST FREE / V1 TO V36.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66 71 72 73 74
75 76 77 81 82
83 84 85 86 87
88
END DATA.
EXECUTE.
FORMAT V1 TO V36(F2.0).

FLIP.  /*  right here!.

FORMAT VAR001(F2.0).
COMPUTE ROW=1.
COMPUTE COL=1.
FORMAT ROW COL(F1.0).
DO IF ($CASENUM GE 2).
+  DO IF (LAG(ROW) EQ LAG(COL)).
+     COMPUTE ROW=LAG(ROW)+1.
+     COMPUTE COL=1.
+  ELSE.
+  COMPUTE ROW=LAG(ROW).
+  COMPUTE COL=LAG(COL)+1.
+  END IF.
END IF.
EXECUTE.


DELETE VARIABLES CASE_LBL.

CASESTOVARS ID=ROW/INDEX=COL.



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Friday, November 15, 2013 4:50 PM
To: [hidden email]
Subject: Re: matrix data unscrambling problem

Gene, maybe it's just a "too late on Friday afternoon" problem, but I'm struggling a bit to understand what the original text file looks like.  Can you /show/ us (i.e., paste it into a message)?  Thanks.




Maguin, Eugene wrote

> I have variance-covariance matrix (lower triangle) written to a text
> file in serial format, five values per line. I need to restructure the
> data to a lower triangle form so that it can eventually be read into
> spss via Matrix Data. As I understand what spss can do, there is no
> way to use spss to read the matrix directly in such way that it is
> correctly structured. I haven't been able to think of a way to use
> spss read the file and restructure the data values into lower
> triangular form.  However, I do figure that it could be done using the
> Matrix command set, which I'm not familiar with and would prefer to
> avoid getting familiar. I'm also quite sure it could be done in Python but I'm not familiar with that either.
>
> So any ideas about how to do this using the spss command set?
>
> Thanks, Gene Maguin





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

"When all else fails, RTFM."

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

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723094.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

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

Re: matrix data unscrambling problem

Bruce Weaver
Administrator
How about this after the FLIP?  ;-)

COMPUTE ROW = TRUNC(VAR001/10).
COMPUTE COL = VAR001 - ROW*10.
FORMATS VAR001 (F2.0) ROW COL (F1).
EXECUTE. /* Needed before DELETE VARIABLES.
DELETE VARIABLES CASE_LBL.
CASESTOVARS ID=ROW/INDEX=COL.



Maguin, Eugene wrote
I understand how to do it now. Pretty easily actually. Just a little trick. Here's the whole setup.  Gene Maguin

*  RESTRUCTURE MPLUS SAVEDATA FILE.
* DATA LIST FILE='U:\HILLSIDE\MPLUS2\RESTRUCTURETEST.TXT' FREE / V1 TO V36.
DATA LIST FREE / V1 TO V36.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66 71 72 73 74
75 76 77 81 82
83 84 85 86 87
88
END DATA.
EXECUTE.
FORMAT V1 TO V36(F2.0).

FLIP.  /*  right here!.

FORMAT VAR001(F2.0).
COMPUTE ROW=1.
COMPUTE COL=1.
FORMAT ROW COL(F1.0).
DO IF ($CASENUM GE 2).
+  DO IF (LAG(ROW) EQ LAG(COL)).
+     COMPUTE ROW=LAG(ROW)+1.
+     COMPUTE COL=1.
+  ELSE.
+  COMPUTE ROW=LAG(ROW).
+  COMPUTE COL=LAG(COL)+1.
+  END IF.
END IF.
EXECUTE.


DELETE VARIABLES CASE_LBL.

CASESTOVARS ID=ROW/INDEX=COL.



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Friday, November 15, 2013 4:50 PM
To: [hidden email]
Subject: Re: matrix data unscrambling problem

Gene, maybe it's just a "too late on Friday afternoon" problem, but I'm struggling a bit to understand what the original text file looks like.  Can you /show/ us (i.e., paste it into a message)?  Thanks.




Maguin, Eugene wrote
> I have variance-covariance matrix (lower triangle) written to a text
> file in serial format, five values per line. I need to restructure the
> data to a lower triangle form so that it can eventually be read into
> spss via Matrix Data. As I understand what spss can do, there is no
> way to use spss to read the matrix directly in such way that it is
> correctly structured. I haven't been able to think of a way to use
> spss read the file and restructure the data values into lower
> triangular form.  However, I do figure that it could be done using the
> Matrix command set, which I'm not familiar with and would prefer to
> avoid getting familiar. I'm also quite sure it could be done in Python but I'm not familiar with that either.
>
> So any ideas about how to do this using the spss command set?
>
> Thanks, Gene Maguin





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

"When all else fails, RTFM."

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

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723094.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

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

Re: matrix data unscrambling problem

David Marso
Administrator
I don't see the reluctance to learn MATRIX.
It is quite powerful and pretty simple once you get a taste.

DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----



DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11   0   0   0   0   0
  21  22   0   0   0   0
  31  32  33   0   0   0
  41  42  43  44   0   0
  51  52  53  54  55   0
  61  62  63  64  65  66
 
------ END MATRIX -----
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: matrix data unscrambling problem

David Marso
Administrator
Thinking it might be awkward to hard code the size, here is a QAD way to dynamically determine the required size.
DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.

GET V / FILE * / VARIABLES V.
COMPUTE #=1.
COMPUTE Nelem=NROW(V).
LOOP.
+  COMPUTE Nelem=Nelem-#.
+  COMPUTE #=#+1.
END LOOP IF Nelem LE 0.
COMPUTE Nrc=#-1.

+  COMPUTE COV=MAKE(Nrc,Nrc,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO Nrc.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----

David Marso wrote
I don't see the reluctance to learn MATRIX.
It is quite powerful and pretty simple once you get a taste.

DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----



DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11   0   0   0   0   0
  21  22   0   0   0   0
  31  32  33   0   0   0
  41  42  43  44   0   0
  51  52  53  54  55   0
  61  62  63  64  65  66
 
------ END MATRIX -----
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: matrix data unscrambling problem

David Marso
Administrator
Of course all 3 of us missed the obvious ;-(
BTW: SPSS doesn't really have any use for a lower triangular matrix that I can think of.
I assume you are dumping this into the CANCORR macro (per recent posts).
Follow this with MCONVERT and then stick it into CanCorr after clobbering the lines which create the CORRELATION matrix .

MATRIX DATA VAR v1 to v6 /FORMAT FREE  /CONTENTS COV.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
LIST.
 
ROWTYPE_ VARNAME_         v1         v2         v3         v4         v5         v6
 
COV      v1          11.0000    21.0000    31.0000    41.0000    51.0000    61.0000
COV      v2          21.0000    22.0000    32.0000    42.0000    52.0000    62.0000
COV      v3          31.0000    32.0000    33.0000    43.0000    53.0000    63.0000
COV      v4          41.0000    42.0000    43.0000    44.0000    54.0000    64.0000
COV      v5          51.0000    52.0000    53.0000    54.0000    55.0000    65.0000
COV      v6          61.0000    62.0000    63.0000    64.0000    65.0000    66.0000
 
 
Number of cases read:  6    Number of cases listed:  6

David Marso wrote
Thinking it might be awkward to hard code the size, here is a QAD way to dynamically determine the required size.
DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.

GET V / FILE * / VARIABLES V.
COMPUTE #=1.
COMPUTE Nelem=NROW(V).
LOOP.
+  COMPUTE Nelem=Nelem-#.
+  COMPUTE #=#+1.
END LOOP IF Nelem LE 0.
COMPUTE Nrc=#-1.

+  COMPUTE COV=MAKE(Nrc,Nrc,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO Nrc.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----

David Marso wrote
I don't see the reluctance to learn MATRIX.
It is quite powerful and pretty simple once you get a taste.

DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----



DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11   0   0   0   0   0
  21  22   0   0   0   0
  31  32  33   0   0   0
  41  42  43  44   0   0
  51  52  53  54  55   0
  61  62  63  64  65  66
 
------ END MATRIX -----
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: matrix data unscrambling problem

Art Kendall
In reply to this post by Maguin, Eugene
does mplus have another way of outputting the matrix?
Art Kendall
Social Research Consultants
On 11/15/2013 5:07 PM, Maguin, Eugene [via SPSSX Discussion] wrote:
Sure.
Suppose you have a 6x6 variance-covariance matrix. Written out in lower triangle (LT) form, you have

11
21 22
31 32 33
41 42 43 44
51 52 53 54 55
61 62 63 64 65 66

Where the numbers are the row,col coordinates. In the real matrix, there would be decimal numbers.
Anyway, the matrix comes out of mplus like this

11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66

Five elements per row, six rows total.

So, how to get it back to LT form.



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Friday, November 15, 2013 4:50 PM
To: [hidden email]
Subject: Re: matrix data unscrambling problem

Gene, maybe it's just a "too late on Friday afternoon" problem, but I'm struggling a bit to understand what the original text file looks like.  Can you /show/ us (i.e., paste it into a message)?  Thanks.




Maguin, Eugene wrote

> I have variance-covariance matrix (lower triangle) written to a text
> file in serial format, five values per line. I need to restructure the
> data to a lower triangle form so that it can eventually be read into
> spss via Matrix Data. As I understand what spss can do, there is no
> way to use spss to read the matrix directly in such way that it is
> correctly structured. I haven't been able to think of a way to use
> spss read the file and restructure the data values into lower
> triangular form.  However, I do figure that it could be done using the
> Matrix command set, which I'm not familiar with and would prefer to
> avoid getting familiar. I'm also quite sure it could be done in Python but I'm not familiar with that either.
>
> So any ideas about how to do this using the spss command set?
>
> Thanks, Gene Maguin





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

"When all else fails, RTFM."

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

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723094.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

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



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723095.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

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

Re: matrix data unscrambling problem

Bruce Weaver
Administrator
In reply to this post by David Marso
Ah yes...I like that one!  


David Marso wrote
Of course all 3 of us missed the obvious ;-(
BTW: SPSS doesn't really have any use for a lower triangular matrix that I can think of.
I assume you are dumping this into the CANCORR macro (per recent posts).
Follow this with MCONVERT and then stick it into CanCorr after clobbering the lines which create the CORRELATION matrix .

MATRIX DATA VAR v1 to v6 /FORMAT FREE  /CONTENTS COV.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
LIST.
 
ROWTYPE_ VARNAME_         v1         v2         v3         v4         v5         v6
 
COV      v1          11.0000    21.0000    31.0000    41.0000    51.0000    61.0000
COV      v2          21.0000    22.0000    32.0000    42.0000    52.0000    62.0000
COV      v3          31.0000    32.0000    33.0000    43.0000    53.0000    63.0000
COV      v4          41.0000    42.0000    43.0000    44.0000    54.0000    64.0000
COV      v5          51.0000    52.0000    53.0000    54.0000    55.0000    65.0000
COV      v6          61.0000    62.0000    63.0000    64.0000    65.0000    66.0000
 
 
Number of cases read:  6    Number of cases listed:  6

David Marso wrote
Thinking it might be awkward to hard code the size, here is a QAD way to dynamically determine the required size.
DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.

GET V / FILE * / VARIABLES V.
COMPUTE #=1.
COMPUTE Nelem=NROW(V).
LOOP.
+  COMPUTE Nelem=Nelem-#.
+  COMPUTE #=#+1.
END LOOP IF Nelem LE 0.
COMPUTE Nrc=#-1.

+  COMPUTE COV=MAKE(Nrc,Nrc,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO Nrc.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----

David Marso wrote
I don't see the reluctance to learn MATRIX.
It is quite powerful and pretty simple once you get a taste.

DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----



DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11   0   0   0   0   0
  21  22   0   0   0   0
  31  32  33   0   0   0
  41  42  43  44   0   0
  51  52  53  54  55   0
  61  62  63  64  65  66
 
------ END MATRIX -----
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

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

Re: matrix data unscrambling problem

David Marso
Administrator
In reply to this post by David Marso
Oops, I meant Ridge Reg

David Marso wrote
Of course all 3 of us missed the obvious ;-(
BTW: SPSS doesn't really have any use for a lower triangular matrix that I can think of.
I assume you are dumping this into the CANCORR macro (per recent posts).
Follow this with MCONVERT and then stick it into CanCorr after clobbering the lines which create the CORRELATION matrix .

MATRIX DATA VAR v1 to v6 /FORMAT FREE  /CONTENTS COV.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
LIST.
 
ROWTYPE_ VARNAME_         v1         v2         v3         v4         v5         v6
 
COV      v1          11.0000    21.0000    31.0000    41.0000    51.0000    61.0000
COV      v2          21.0000    22.0000    32.0000    42.0000    52.0000    62.0000
COV      v3          31.0000    32.0000    33.0000    43.0000    53.0000    63.0000
COV      v4          41.0000    42.0000    43.0000    44.0000    54.0000    64.0000
COV      v5          51.0000    52.0000    53.0000    54.0000    55.0000    65.0000
COV      v6          61.0000    62.0000    63.0000    64.0000    65.0000    66.0000
 
 
Number of cases read:  6    Number of cases listed:  6

David Marso wrote
Thinking it might be awkward to hard code the size, here is a QAD way to dynamically determine the required size.
DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.

GET V / FILE * / VARIABLES V.
COMPUTE #=1.
COMPUTE Nelem=NROW(V).
LOOP.
+  COMPUTE Nelem=Nelem-#.
+  COMPUTE #=#+1.
END LOOP IF Nelem LE 0.
COMPUTE Nrc=#-1.

+  COMPUTE COV=MAKE(Nrc,Nrc,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO Nrc.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----

David Marso wrote
I don't see the reluctance to learn MATRIX.
It is quite powerful and pretty simple once you get a taste.

DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66
 
------ END MATRIX -----



DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:
 
COV
  11   0   0   0   0   0
  21  22   0   0   0   0
  31  32  33   0   0   0
  41  42  43  44   0   0
  51  52  53  54  55   0
  61  62  63  64  65  66
 
------ END MATRIX -----
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: matrix data unscrambling problem

Maguin, Eugene
In reply to this post by David Marso
Thanks for all your replies.
Bruce: In my example, I used the (I,j) values as x(I,j) values to keep track of operation. The real matrices are just covariance matrices.

David: It's more easily thought of as a matrix problem, I agree.

Art: I think the answer is No. Matrices are written to the output (listing) file in lower triangular but only with three decimal values.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, November 15, 2013 6:02 PM
To: [hidden email]
Subject: Re: matrix data unscrambling problem

I don't see the reluctance to learn MATRIX.
It is quite powerful and pretty simple once you get a taste.

DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:

COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66

------ END MATRIX -----



DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:

COV
  11   0   0   0   0   0
  21  22   0   0   0   0
  31  32  33   0   0   0
  41  42  43  44   0   0
  51  52  53  54  55   0
  61  62  63  64  65  66

------ END MATRIX -----




-----
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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723099.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

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

Re: matrix data unscrambling problem

David Marso
Administrator
Gene,
In a post later in this thread I demonstrated that this can be read directly using MATRIX DATA
Only qualifiers are to use FORMAT=FREE and CONTENTS=COV (since default is LIST and CORR).
To push this into RidgeReg you will need to convert it to a correlation matrix and do some data manipulations to put the N's and Means into appropriate rows (alternatively modify the macro).
Here I demonstrate the issues.
DATA LIST FREE / x1 TO X4 .
BEGIN DATA
5 2 5 1 2 5 6 1 5 6 5 1 6 3 5 1 2 3 5 6 2 5
3 6 2 1 5 6 1 2 5 3 5 1 3 5 5 3 5 1 3 6 1 5
3 5 1 2 5 3 6 1 5 3 1 5 3 7 5 1 7 3 1 5 3 1
END DATA.
CORR VAR x1 to x4 /MISSING = LISTWISE/ MATRIX OUT (*).
LIST.
 
MATRIX FILE FORMAT ASSUMED BY RIDGEREG.
ROWTYPE_ VARNAME_         x1         x2         x3         x4
 
MEAN               3.8125000  3.6250000  3.8750000  3.1250000
STDDEV             1.7594980  1.8211718  1.8929694  2.1870833
N                 16.0000000 16.0000000 16.0000000 16.0000000
CORR     x1        1.0000000  -.1690411  -.2076655  -.2533673
CORR     x2        -.1690411  1.0000000  -.1305323  -.2887231
CORR     x3        -.2076655  -.1305323  1.0000000  -.5112620
CORR     x4        -.2533673  -.2887231  -.5112620  1.0000000
 
 
Number of cases read:  7    Number of cases listed:  7

MCONVERT.
LIST.

ROWTYPE_ VARNAME_         x1         x2         x3         x4
 
MEAN               3.8125000  3.6250000  3.8750000  3.1250000
STDDEV             1.7594980  1.8211718  1.8929694  2.1870833
N                 16.0000000 16.0000000 16.0000000 16.0000000
COV      x1        3.0958333  -.5416667  -.6916667  -.9750000
COV      x2        -.5416667  3.3166667  -.4500000 -1.1500000
COV      x3        -.6916667  -.4500000  3.5833333 -2.1166667
COV      x4        -.9750000 -1.1500000 -2.1166667  4.7833333


WHAT YOU WOULD BE PROVIDING AS INPUT
MATRIX DATA VAR x1  TO x4
   / FORMAT FREE
   / CONTENTS Mean  N_VECTOR COV .
BEGIN DATA
 3.8125000  3.6250000  3.8750000  3.1250000
 16.0000000 16.0000000 16.0000000 16.0000000
 3.0958333  -.5416667   3.3166667  -.6916667  -.4500000  3.5833333 -.9750000 -1.1500000 -2.1166667  4.7833333
END DATA.
LIST.
 
 OOPS! This does NOT agree with what RidgeReg assumes !
ROWTYPE_ VARNAME_         x1         x2         x3         x4
 
N                    16.0000    16.0000    16.0000    16.0000
MEAN                  3.8125     3.6250     3.8750     3.1250
COV      x1           3.0958     -.5417     -.6917     -.9750
COV      x2           -.5417     3.3167     -.4500    -1.1500
COV      x3           -.6917     -.4500     3.5833    -2.1167
COV      x4           -.9750    -1.1500    -2.1167     4.7833
 
 
Number of cases read:  6    Number of cases listed:  6

MCONVERT.
LIST.

NEITHER DOES THIS
ROWTYPE_ VARNAME_         x1         x2         x3         x4
 
N                 16.0000000 16.0000000 16.0000000 16.0000000
MEAN               3.8125000  3.6250000  3.8750000  3.1250000
STDDEV             1.7594980  1.8211718  1.8929694  2.1870833
CORR     x1        1.0000000  -.1690411  -.2076656  -.2533673
CORR     x2        -.1690411  1.0000000  -.1305323  -.2887231
CORR     x3        -.2076656  -.1305323  1.0000000  -.5112620
CORR     x4        -.2533673  -.2887231  -.5112620  1.0000000
 
 
Number of cases read:  7    Number of cases listed:  7

Notice that this produces a matrix file which is NOT identical to that created by CORRELATIONS ;-(((
the RidgeReg Macro (RR) references the N from row 3 (where here they occur in row 1)
compute n=x(3,1).
needs to be changed to
compute n=x(1,1).

RR assumes the Mean vector is in row 1, where here they are in row 2.
RR assumes the SDs are row 2 where here the end up in Row 3.
compute xmean=x(1,2:(nv+1)).
compute ybar=x(1,1).
compute std=t(x(2,2:(nv+1))).
compute sy=x(2,1).

NEEDS TO BE CHANGED TO
compute xmean=x(2,2:(nv+1)).
compute ybar=x(3,1).
compute std=t(x(3,2:(nv+1))).
compute sy=x(3,1).

You will also need to comment out the raw data read in the beginning.

correlations variables=!dep !enter
            /missing=listwise
            /matrix out(corr).

HTH, David

Maguin, Eugene wrote
Thanks for all your replies.
Bruce: In my example, I used the (I,j) values as x(I,j) values to keep track of operation. The real matrices are just covariance matrices.

David: It's more easily thought of as a matrix problem, I agree.

Art: I think the answer is No. Matrices are written to the output (listing) file in lower triangular but only with three decimal values.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, November 15, 2013 6:02 PM
To: [hidden email]
Subject: Re: matrix data unscrambling problem

I don't see the reluctance to learn MATRIX.
It is quite powerful and pretty simple once you get a taste.

DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE COV(#C,#R)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:

COV
  11  21  31  41  51  61
  21  22  32  42  52  62
  31  32  33  43  53  63
  41  42  43  44  54  64
  51  52  53  54  55  65
  61  62  63  64  65  66

------ END MATRIX -----



DATA LIST FREE / V.
BEGIN DATA
11 21 22 31 32
33 41 42 43 44
51 52 53 54 55
61 62 63 64 65
66
END DATA.
MATRIX.
GET V / FILE * / VARIABLES V.
+  COMPUTE COV=MAKE(6,6,0).
+  COMPUTE #=1.
+  LOOP #R=1 TO 6.
+    LOOP #C=1 TO #R.
+      COMPUTE COV(#R,#C)=V(#).
+      COMPUTE #=#+1.
+    END LOOP.
+  END LOOP.
PRINT COV.
END MATRIX.

Run MATRIX procedure:

COV
  11   0   0   0   0   0
  21  22   0   0   0   0
  31  32  33   0   0   0
  41  42  43  44   0   0
  51  52  53  54  55   0
  61  62  63  64  65  66

------ END MATRIX -----




-----
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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723099.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

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

Re: matrix data unscrambling problem

Maguin, Eugene
Thanks. Yes, that is what I'm going do. I've tested that part out. Turns out that RidgeReg has more flexibility than I originally thought because it will run through a range of k values or will execute for a specific k value. The output depends on the choice of range or specific. Also turns out that the input requirements differ for the choice. If the computation is for a specific value, means are required. If a range of values, then means aren't required. Turns out that mplus writes the EM covariance matrix in E format but the means and N are not included in the save file.  They are, however, are printed, albeit in a different format. Although I think only the range of k's option will be picked; flexibility is better.

RidgeReg is set up to save the data file in a temp file and compute the correlations within the macro. Instead, my idea is, as you said,
to use matrix data to read the cov matrix and mconvert to convert it to corrs but outside of the macro , which means I'll comment out some lines in the macro. Originally, I thought of putting matrix data in the macro but I'd need to alter the macro call a bit to pass the N value. Easier, I think, to do so outside the macro as this is a one-time project. However, the drawback to this plan is the need to insert the rowtype variable and assign it values. Your point is that the get command in matrix would avoid this drawback, and it would, I think. It'd interesting to do this because I'd certainly learn something. The tradeoff is time to get minimal proficiency.

Gene Maguin






-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Monday, November 18, 2013 10:47 AM
To: [hidden email]
Subject: Re: matrix data unscrambling problem

Gene,
In a post later in this thread I demonstrated that this can be read directly using MATRIX DATA Only qualifiers are to use FORMAT=FREE and CONTENTS=COV (since default is LIST and CORR).
To push this into RidgeReg you will need to convert it to a correlation matrix and do some data manipulations to put the N's and Means into appropriate rows (alternatively modify the macro).
Here I demonstrate the issues.
DATA LIST FREE / x1 TO X4 .
BEGIN DATA
5 2 5 1 2 5 6 1 5 6 5 1 6 3 5 1 2 3 5 6 2 5
3 6 2 1 5 6 1 2 5 3 5 1 3 5 5 3 5 1 3 6 1 5
3 5 1 2 5 3 6 1 5 3 1 5 3 7 5 1 7 3 1 5 3 1 END DATA.
CORR VAR x1 to x4 /MISSING = LISTWISE/ MATRIX OUT (*).
LIST.

*MATRIX FILE FORMAT ASSUMED BY RIDGEREG. *
ROWTYPE_ VARNAME_         x1         x2         x3         x4

MEAN               3.8125000  3.6250000  3.8750000  3.1250000
STDDEV             1.7594980  1.8211718  1.8929694  2.1870833
N                 16.0000000 16.0000000 16.0000000 16.0000000
CORR     x1        1.0000000  -.1690411  -.2076655  -.2533673
CORR     x2        -.1690411  1.0000000  -.1305323  -.2887231
CORR     x3        -.2076655  -.1305323  1.0000000  -.5112620
CORR     x4        -.2533673  -.2887231  -.5112620  1.0000000


Number of cases read:  7    Number of cases listed:  7

MCONVERT.
LIST.

ROWTYPE_ VARNAME_         x1         x2         x3         x4

MEAN               3.8125000  3.6250000  3.8750000  3.1250000
STDDEV             1.7594980  1.8211718  1.8929694  2.1870833
N                 16.0000000 16.0000000 16.0000000 16.0000000
COV      x1        3.0958333  -.5416667  -.6916667  -.9750000
COV      x2        -.5416667  3.3166667  -.4500000 -1.1500000
COV      x3        -.6916667  -.4500000  3.5833333 -2.1166667
COV      x4        -.9750000 -1.1500000 -2.1166667  4.7833333


*WHAT YOU WOULD BE PROVIDING AS INPUT*
MATRIX DATA VAR x1  TO x4
   / FORMAT FREE
   / CONTENTS Mean  N_VECTOR COV .
BEGIN DATA
 3.8125000  3.6250000  3.8750000  3.1250000
 16.0000000 16.0000000 16.0000000 16.0000000
 3.0958333  -.5416667   3.3166667  -.6916667  -.4500000  3.5833333 -.9750000
-1.1500000 -2.1166667  4.7833333
END DATA.
LIST.

 *OOPS! This does NOT agree with what RidgeReg assumes !
*ROWTYPE_ VARNAME_         x1         x2         x3         x4

N                    16.0000    16.0000    16.0000    16.0000
MEAN                  3.8125     3.6250     3.8750     3.1250
COV      x1           3.0958     -.5417     -.6917     -.9750
COV      x2           -.5417     3.3167     -.4500    -1.1500
COV      x3           -.6917     -.4500     3.5833    -2.1167
COV      x4           -.9750    -1.1500    -2.1167     4.7833


Number of cases read:  6    Number of cases listed:  6

*MCONVERT.*
LIST.

*NEITHER DOES THIS*
ROWTYPE_ VARNAME_         x1         x2         x3         x4

N                 16.0000000 16.0000000 16.0000000 16.0000000
MEAN               3.8125000  3.6250000  3.8750000  3.1250000
STDDEV             1.7594980  1.8211718  1.8929694  2.1870833
CORR     x1        1.0000000  -.1690411  -.2076656  -.2533673
CORR     x2        -.1690411  1.0000000  -.1305323  -.2887231
CORR     x3        -.2076656  -.1305323  1.0000000  -.5112620
CORR     x4        -.2533673  -.2887231  -.5112620  1.0000000


Number of cases read:  7    Number of cases listed:  7

Notice that this produces a matrix file which is NOT identical to that created by CORRELATIONS ;-((( the RidgeReg Macro (RR) references the N from row 3 (where here they occur in row 1) compute n=x(3,1).
needs to be changed to
compute n=x(*1*,1).

RR assumes the Mean vector is in row 1, where here they are in row 2.
RR assumes the SDs are row 2 where here the end up in Row 3.
compute xmean=x(1,2:(nv+1)).
compute ybar=x(1,1).
compute std=t(x(2,2:(nv+1))).
compute sy=x(2,1).

NEEDS TO BE CHANGED TO
compute xmean=x(*2*,2:(nv+1)).
compute ybar=x(*3*,1).
compute std=t(x(*3*,2:(nv+1))).
compute sy=x(*3*,1).

You will also need to comment out the raw data read in the beginning.

correlations variables=!dep !enter
            /missing=listwise
            /matrix out(corr).

HTH, David


Maguin, Eugene wrote

> Thanks for all your replies.
> Bruce: In my example, I used the (I,j) values as x(I,j) values to keep
> track of operation. The real matrices are just covariance matrices.
>
> David: It's more easily thought of as a matrix problem, I agree.
>
> Art: I think the answer is No. Matrices are written to the output
> (listing) file in lower triangular but only with three decimal values.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of David Marso
> Sent: Friday, November 15, 2013 6:02 PM
> To:

> SPSSX-L@.UGA

> Subject: Re: matrix data unscrambling problem
>
> I don't see the reluctance to learn MATRIX.
> It is quite powerful and pretty simple once you get a taste.
>
> DATA LIST FREE / V.
> BEGIN DATA
> 11 21 22 31 32
> 33 41 42 43 44
> 51 52 53 54 55
> 61 62 63 64 65
> 66
> END DATA.
> MATRIX.
> GET V / FILE * / VARIABLES V.
> +  COMPUTE COV=MAKE(6,6,0).
> +  COMPUTE #=1.
> +  LOOP #R=1 TO 6.
> +    LOOP #C=1 TO #R.
> +      COMPUTE COV(#R,#C)=V(#).
> +      COMPUTE COV(#C,#R)=V(#).
> +      COMPUTE #=#+1.
> +    END LOOP.
> +  END LOOP.
> PRINT COV.
> END MATRIX.
>
> Run MATRIX procedure:
>
> COV
>   11  21  31  41  51  61
>   21  22  32  42  52  62
>   31  32  33  43  53  63
>   41  42  43  44  54  64
>   51  52  53  54  55  65
>   61  62  63  64  65  66
>
> ------ END MATRIX -----
>
>
>
> DATA LIST FREE / V.
> BEGIN DATA
> 11 21 22 31 32
> 33 41 42 43 44
> 51 52 53 54 55
> 61 62 63 64 65
> 66
> END DATA.
> MATRIX.
> GET V / FILE * / VARIABLES V.
> +  COMPUTE COV=MAKE(6,6,0).
> +  COMPUTE #=1.
> +  LOOP #R=1 TO 6.
> +    LOOP #C=1 TO #R.
> +      COMPUTE COV(#R,#C)=V(#).
> +      COMPUTE #=#+1.
> +    END LOOP.
> +  END LOOP.
> PRINT COV.
> END MATRIX.
>
> Run MATRIX procedure:
>
> COV
>   11   0   0   0   0   0
>   21  22   0   0   0   0
>   31  32  33   0   0   0
>   41  42  43  44   0   0
>   51  52  53  54  55   0
>   61  62  63  64  65  66
>
> ------ END MATRIX -----
>
>
>
>
> -----
> 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?"
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling
> -problem-tp5723092p5723099.html Sent from the SPSSX Discussion mailing
> list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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

> LISTSERV@.UGA

>  (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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/matrix-data-unscrambling-problem-tp5723092p5723129.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

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