Display a correlation matrix showing only the lower half triangular portion in spss

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

Display a correlation matrix showing only the lower half triangular portion in spss

zhanggonwoo
I want to display only one triangle of a correlation matrix
how can I enter the syntax?

Reply | Threaded
Open this post in threaded view
|

Re: Display a correlation matrix showing only the lower half triangular portion in spss

Bruce Weaver
Administrator
This does what you ask for in an an example I generated.  

VECTOR x = x1 to x3.
LOOP # = 1 to 2.
 DO IF Rowtype_ EQ "CORR".
  IF x(#) EQ 1 OR MISSING(x(#)) x(#+1) = $SYSMIS.
 END IF.
END LOOP.
LIST.

Why do you want to do this though?  In the full example I tried (see below), the matrix data set no longer works as input to the REGRESSION command after changing values above the diagonal to SYSMIS.  

Here's the full example.  

NEW FILE.
DATASET CLOSE ALL.
MATRIX DATA
    VARIABLES=ROWTYPE_ x1 x2 x3.
BEGIN DATA
MEAN 9.6710 35.0896 2.2930
STDDEV 4.4804 9.1517 1.2907
N 50 50 50
CORR 1
CORR -.4555 1
CORR .3165 -.9085 1
END DATA.

REGRESSION MATRIX IN(*)
 /VARIABLES=x1 x2 x3
 /DEPENDENT=x1
 /METHOD=ENTER x2 x3.

* Change values above diagonal to SYSMIS.
VECTOR x = x1 to x3.
LOOP # = 1 to 2.
 DO IF Rowtype_ EQ "CORR".
  IF x(#) EQ 1 OR MISSING(x(#)) x(#+1) = $SYSMIS.
 END IF.
END LOOP.
LIST.

REGRESSION MATRIX IN(*)
 /VARIABLES=x1 x2 x3
 /DEPENDENT=x1
 /METHOD=ENTER x2 x3.



zhanggonwoo wrote
I want to display only one triangle of a correlation matrix
how can I enter the syntax?

--
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: Display a correlation matrix showing only the lower half triangular portion in spss

PRogman
In reply to this post by zhanggonwoo
Just for info, if you want to format the correlation table in the Output Window there is an extension command FormatCorrelations available. It depends on SPSSINC MODIFY TABLES extension command. It has a bug that removes the Cell Count Row independent of the option setting. The row with p-values can be removed with a 2nd SPSSINC MODIFY TABLES command.

/PR

* Generated by extension command Format Correlation Matrix *.
SPSSINC MODIFY TABLES
  SUBTYPE='Correlations' SELECT=0 DIMENSION=ROWS PROCESS=PRECEDING
  /STYLES customfunction="formatcorrmat.cleancorr(hidecounts=True, hidel=False, lowertri=True, hideinsig=1, emphlarge=1, boldsig=1)".

* Remove rows with p-values *.
SPSSINC MODIFY TABLES
  SUBTYPE = "Correlations" SELECT = 1 DIMENSION = ROWS LEVEL = -1  PROCESS = PRECEDING HIDE=TRUE
  /STYLES     APPLYTO = BOTH.


<quote author="zhanggonwoo">
I want to display only one triangle of a correlation matrix
how can I enter the syntax?
---
Reply | Threaded
Open this post in threaded view
|

Re: Display a correlation matrix showing only the lower half triangular portion in spss

Bruce Weaver
Administrator
I was just about to moan about why this is not included as an option for the CORRELATIONS command, but then decided to check the latest documentation.  I am pleased to report that in v27, the following options were added to the PRINT subcommand for CORRELATIONS:

  FULL** <-- the default
  LOWER
  NODIAG
  NOMATRIX

It's about time!  I'm currently on v26, but expect to get v27 in a couple months.  


https://www.ibm.com/docs/en/spss-statistics/26.0.0?topic=reference-correlations
https://www.ibm.com/docs/en/spss-statistics/27.0.0?topic=reference-correlations
https://www.ibm.com/docs/en/spss-statistics/28.0.0?topic=reference-correlations


<quote author="PRogman">
Just for info, if you want to format the correlation table in the Output Window there is an extension command FormatCorrelations available. It depends on SPSSINC MODIFY TABLES extension command. It has a bug that removes the Cell Count Row independent of the option setting. The row with p-values can be removed with a 2nd SPSSINC MODIFY TABLES command.

/PR

* Generated by extension command Format Correlation Matrix *.
SPSSINC MODIFY TABLES
  SUBTYPE='Correlations' SELECT=0 DIMENSION=ROWS PROCESS=PRECEDING
  /STYLES customfunction="formatcorrmat.cleancorr(hidecounts=True, hidel=False, lowertri=True, hideinsig=1, emphlarge=1, boldsig=1)".

* Remove rows with p-values *.
SPSSINC MODIFY TABLES
  SUBTYPE = "Correlations" SELECT = 1 DIMENSION = ROWS LEVEL = -1  PROCESS = PRECEDING HIDE=TRUE
  /STYLES     APPLYTO = BOTH.


zhanggonwoo wrote
I want to display only one triangle of a correlation matrix
how can I enter the syntax?
---
--
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: Display a correlation matrix showing only the lower half triangular portion in spss

PRogman
Speaking of CORRELATION command...
My mind is not synchronized with the /PRINT options.

SIG .     Do not flag significant values. SIG is the default.
NOSIG . Flag significant values. Values significant at the 0.05 level are flagged with a single asterisk; those that are significant at the 0.01 level are flagged with two asterisks.

To me the NOSIG alternative would not flag significant values...  :-)

/PR
Reply | Threaded
Open this post in threaded view
|

Re: Display a correlation matrix showing only the lower half triangular portion in spss

Bruce Weaver
Administrator
Right!  The FM says:

SIG . Do not flag significant values. SIG is the default.

NOSIG . Flag significant values. Values significant at the 0.05 level are flagged with a single asterisk; those that are significant at the 0.01 level are flagged with two asterisks.


In ~my~ mind, SIG should tell SPSS to include p-values in the output, and NOSIG should tell it to exclude p-values.  But of course, p-values are shown in either case.  





PRogman wrote
Speaking of CORRELATION command...
My mind is not synchronized with the /PRINT options.

SIG .     Do not flag significant values. SIG is the default.
NOSIG . Flag significant values. Values significant at the 0.05 level are flagged with a single asterisk; those that are significant at the 0.01 level are flagged with two asterisks.

To me the NOSIG alternative would not flag significant values...  :-)

/PR
--
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: Display a correlation matrix showing only the lower half triangular portion in spss

zhanggonwoo
In reply to this post by Bruce Weaver
Thank you very much.
The correlation matrix is done, if I want to try to use covariance matrix, what do I put in?
Any help would be appreciated!!!

syntax like this:

matrix data variables=rowtype_ x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12.

begin data
cov 2.056
cov 0.727 1.055
cov 0.592 0.477 0.962
cov 0.441 0.393 0.376 1.839
cov 0.368 0.332 0.312 0.705 1.057
cov 0.733 0.569 0.536 1.232 1.004 3.557
cov  0.581 0.484 0.420 0.202 0.221 0.345 1.988
cov 1.106 1.068 0.831 0.666 0.533 0.591 2.350 9.719
cov 0.373 0.308 0.301 0.186 0.196 0.174 0.663 1.679 1.015
cov 0.245 0.247 0.217 0.180 0.074 0.356 0.065 0.365 -0.011 3.359
cov 0.711 0.643 0.511 0.229 0.331 0.730 0.405 1.238 0.111 2.376 11.487
cov 0.188 0.117 0.021 0.133 0.183 0.250 -0.012 -0.061 -0.075 0.811 1.756 3.385
n 500 500 500 500 500 500 500 500 500 500 500 500
end data.
Reply | Threaded
Open this post in threaded view
|

Re: Display a correlation matrix showing only the lower half triangular portion in spss

Bruce Weaver
Administrator
Thanks for providing code to read in the matrix dataset.  Try this.

* Store the original sort order.
COMPUTE order1 = $CASENUM.
FORMATS order1 (F2.0).
 
SORT CASES by rowtype_ order1.
COMPUTE row = $CASENUM.
FORMATS row (F2.0).
VECTOR x = x1 to x12.
LOOP # = 1 to 11.
 DO IF Rowtype_ EQ "COV".
  IF # GE row x(#+1) = $SYSMIS.
 END IF.
END LOOP.
SORT CASES by order1.
FORMATS x1 to x12 (F8.3).
LIST varname_ x1 to x12.





zhanggonwoo wrote
Thank you very much.
The correlation matrix is done, if I want to try to use covariance matrix, what do I put in?
Any help would be appreciated!!!

syntax like this:

matrix data variables=rowtype_ x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12.

begin data
cov 2.056
cov 0.727 1.055
cov 0.592 0.477 0.962
cov 0.441 0.393 0.376 1.839
cov 0.368 0.332 0.312 0.705 1.057
cov 0.733 0.569 0.536 1.232 1.004 3.557
cov  0.581 0.484 0.420 0.202 0.221 0.345 1.988
cov 1.106 1.068 0.831 0.666 0.533 0.591 2.350 9.719
cov 0.373 0.308 0.301 0.186 0.196 0.174 0.663 1.679 1.015
cov 0.245 0.247 0.217 0.180 0.074 0.356 0.065 0.365 -0.011 3.359
cov 0.711 0.643 0.511 0.229 0.331 0.730 0.405 1.238 0.111 2.376 11.487
cov 0.188 0.117 0.021 0.133 0.183 0.250 -0.012 -0.061 -0.075 0.811 1.756 3.385
n 500 500 500 500 500 500 500 500 500 500 500 500
end data.
--
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/).