SPSS Matrix program example

Arne Raeithel (raeithel@rzdspc1.informatik.uni-hamburg.de)
Sat, 26 Feb 1994 10:40:28 +0100 (MET)

Here is -- as promised -- a program, written in SPSS matrix language,
that performs PCA without any centering.
For the mathematical background see:
Jolliffe, I.T. (1986): Principal Components Analysis.
Berlin etc.: Springer.

The input file with name "rawdata" looks like this:
--------------start file-------------
8 8 6
1 1 1 2 -2 1 2 1
-2 -1 1 -2 2 -1 -2 -1
-1 1 -2 -2 1 -1 -2 1
-1 2 -1 2 -1 1 2 1
1 -2 -2 -2 -2 0 -2 1
-2 -1 -1 2 1 -1 2 -1
-2 1 1 2 -1 -1 2 -1
2 -2 1 -2 -2 0 -2 2
--------------end file---------------

Unipolar scores (e.g. 1 2 3 4 5 6 7) must be transformed by
subtracting the midpoint (giving -3 -2 -1 0 1 2 3).

-------------start program------------
* Principal Components Analysis of Repertory Grid raw data.
* Called "Eigen-Structure-Analysis of Grids" (ESA, Raeithel 1991).
* Program has been tested with SPSS for the Macintosh 4.0 only.

* SPSS on other platforms demands different pathnames here.

file handle GRID /name='PowerHD:examples:rawdata'.

* other alterations might be necessary...

set printback=no.

MATRIX.

* preparation, reading the matrix.

read parms /size={1,3} /field=1 to 20 /file=GRID.
compute n =parms(1).
compute p =parms(2).
compute rmx=parms(3).
compute enames={'E 1','E 2','E 3','E 4','E 5','E 6','E 7','E 8'}.
compute pnames={'K 1','K 2','K 3','K 4','K 5','K 6','K 7','K 8'}.
compute dnames={'Dim-1','Dim-2','Dim-3','Dim-4','Dim-5','Dim-6'}.
compute enames=enames(1:p).
compute pnames=pnames(1:n).
compute dnames=dnames(1:rmx).
read X /size={n,p} /field=1 to 120 /file=GRID.

* singular value decomposition.

call svd(X,U,L,A).

* rank, proportions of variance.

compute r = rank(X).
compute lam = T(diag(L*L)).
compute tr = rsum(lam).
compute rm = rmin({r,rmx}).
compute lam = lam(1:rm).
compute per = lam/tr.
compute cum = per.
loop j=2 to rm.
compute cum(j) = cum(j-1) + cum(j).
end loop.

* computation of image vector matrices C and E.

compute C = U(:,1:rm) * L(1:rm,1:rm).
compute E = A(:,1:rm) * L(1:rm,1:rm).

print /title 'Eigen-Structure-Analysis (ESA)'.
print r /title 'rank = number of principal axes' /format 'F4.0'.
print lam /title 'eigenvalues = variation on principal axes'
/format 'F8.3' /rnames={'---'} /cnames=dnames.
print per /title 'proportion of variation'
/format 'F8.3' /rnames={'---'} /cnames=dnames.
print cum /title 'cumulated proportions'
/format 'F8.3' /rnames={'---'} /cnames=dnames.
print C /title 'coordinates (loadings) of constructs'
/format 'F8.3' /rnames=pnames /cnames=dnames.
print E /title 'coordinates (loadings) of elements'
/format 'F8.3' /rnames=enames /cnames=dnames.

END MATRIX.
----------------end program--------------

Loading the program into the input window, and running it
produces the following output:
----------------start output-------------

Run MATRIX procedure:

Eigen-Structure-Analysis (ESA)

rank = number of principal axes
7

eigenvalues = variation on principal axes
Dim-1 Dim-2 Dim-3 Dim-4 Dim-5 Dim-6
--- 76.520 40.976 15.882 10.175 5.875 1.555

proportion of variation
Dim-1 Dim-2 Dim-3 Dim-4 Dim-5 Dim-6
--- .503 .270 .104 .067 .039 .010

cumulated proportions
Dim-1 Dim-2 Dim-3 Dim-4 Dim-5 Dim-6
--- .503 .773 .877 .944 .983 .993

coordinates (loadings) of constructs
Dim-1 Dim-2 Dim-3 Dim-4 Dim-5 Dim-6
K 1 2.657 3.086 -.319 -.335 .382 -.241
K 2 -2.263 -3.509 -1.178 -.235 .873 -.274
K 3 -2.377 -1.751 2.652 -.698 .719 -.191
K 4 3.259 1.175 2.049 -.270 .511 -.389
K 5 -3.710 1.605 1.287 1.906 .194 .483
K 6 2.669 -2.025 .188 2.275 -.429 -.590
K 7 3.520 -.609 -.575 .659 1.784 .496
K 8 -3.845 2.764 -1.068 .453 .886 -.638

coordinates (loadings) of elements
Dim-1 Dim-2 Dim-3 Dim-4 Dim-5 Dim-6
E 1 -1.998 3.606 -.687 -.612 -1.377 .226
E 2 2.861 -.020 1.608 -2.405 .536 .368
E 3 .722 .449 -3.326 -1.216 .832 -.208
E 4 5.556 .787 -.176 .566 -.351 -.166
E 5 -.139 -4.104 -.199 -1.044 -1.313 -.517
E 6 .499 1.899 .161 -.817 -.848 -.057
E 7 5.556 .787 -.176 .566 -.351 -.166
E 8 -1.348 2.466 1.280 -.373 .557 -1.000

------ END MATRIX -----
---------------end output----------------

The coordinates are for plotting constructs and elements
in the same space (a "mixed biplot" in Jolliffe's terms).
Adding tables for distances and congruence coefficients
would be fairly easy...

Arne Raeithel
Dept of Psychology
University of Hamburg.

P.S. continued, if there's any interest in this kind of information.