TIP: Using Matrix with SPLIT FILE Correlation Matrices

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

TIP: Using Matrix with SPLIT FILE Correlation Matrices

David Marso
Administrator
This post was updated on .
This might come in handy for some of you.
-----------------------------------------------------------------------
Notices AS IS:  
Reposting is strictly forbidden without my (David Marso) written permission.
No warranties and all that legal verbosity etc. etc. etc.
Incidental Craniogasms (TM) or cases of computer induced Tourette's
are not the responsibility of the author.
Internals are intentionally left blank/uncommented to
promote the use of the FM.
-----------------------------------------------------------------------
EDITED 3-18-2013: ~ 10:00 AM:
*Added Debug logic as further exploration of sanity and hair preservation technique.


*Using Matrix with SPLIT FILE Correlation Matrices *.

DEFINE MATFUNC (!POS !TOKENS(1)/!POS  !TOKENS(1)).
+  DO IF (DEBUG =0).
+    PRINT SPLIT(##-1) / TITLE "Split level category" .
+  ELSE IF (DEBUG GT 2).
+    PRINT /TITLE "Macro:MATFUNC".
+  END IF.

+  COMPUTE !2=GINV(!1).
+  PRINT !2 /TITLE !QUOTE(!CONCAT("Inverse of ",!1, " Matrix.")).
!ENDDEFINE.

DEFINE EXTRACT ( !POS !TOKENS(1)/!POS !TOKENS(1) !DEFAULT(1)).
+  DO IF (DEBUG GT 2).
+    PRINT /TITLE !QUOTE(!CONCAT("Macro: Extract: ", !1) ).
+  END IF.
+  DO IF (!2=1).
+    COMPUTE !1=DATA(##,:).
+  ELSE.
+    COMPUTE !1=DATA(##:(##+!2-1),:).
+  END IF.
+  COMPUTE ##=##+!2.
+  DO IF (DEBUG GT 1).
+    PRINT !1  / FORMAT "F8.5".
+  END IF.
!ENDDEFINE.

DEFINE PreProc (SPLITVar !Charend ("/") / CORRVars !CMDEND).
+  SORT CASES BY !SPLITVar.
+  SPLIT FILE BY !SPLITVar.
+  CORRELATIONS  /MATRIX OUT (*)/MISSING LISTWISE /VARIABLES=!CORRVars.
+  SPLIT FILE OFF.
+  AUTORECODE ROWTYPE_ /INTO @RT@.
+  MATCH FILES / FILE * / DROP ROWTYPE_ VARNAME_ .
!ENDDEFINE.

DEFINE MatProc (debug !TOKENS(1) !DEFAULT (0)).
MATRIX.
+  COMPUTE debug=!debug.
+  DO IF (DEBUG GT 2).
+    PRINT /TITLE "Macro: MatProc".
+  END IF.

+  GET DATA / FILE * / VAR ALL.
+  COMPUTE SPLIT=DATA(:,1).
+  COMPUTE RT=DATA(:,NCOL(DATA)).
+  COMPUTE DATA=DATA(:,2:(NCOL(DATA)-1)).
+  COMPUTE N_SPLITS=1.

+  LOOP #=2 TO NROW(DATA).
+    DO IF SPLIT(#) NE SPLIT(#-1).
+      COMPUTE  N_SPLITS= N_SPLITS+1.
+    END IF.
+  END LOOP.

+  DO IF (debug GT 1).
+    PRINT N_SPLITS.
+  END IF.

+  COMPUTE ##=1.
+  COMPUTE NC=NCOL(DATA).

+  LOOP #=1 TO N_SPLITS.
+    DO IF (debug GT 0).
+      PRINT SPLIT(##) / TITLE 'Current split value'.
+    END IF.
+    EXTRACT MEAN      .
+    EXTRACT SD        .
+    EXTRACT N         .
+    EXTRACT CORR  NC  .
+    MATFUNC CORR INVCORR.
+  END LOOP.
END MATRIX.
!ENDDEFINE .

*EXAMPLES*.
GET
  FILE='C:\Program Files\SPSS\Employee data.sav'.
Preproc SplitVar JobCat / CorrVars salary salbegin jobtime prevexp .
MatProc .

GET
  FILE='C:\Program Files\SPSS\Employee data.sav'.
Preproc SplitVar JobCat / CorrVars salary salbegin jobtime prevexp .
MatProc debug=3 .



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?"