Date: Mon, 26 Sep 2005 21:17:35 +0200
Reply-To: Dirk Enzmann <dirk.enzmann@jura.uni-hamburg.de>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Dirk Enzmann <dirk.enzmann@jura.uni-hamburg.de>
Subject: Re: importing PRELIS correlations
Content-Type: text/plain; charset=us-ascii; format=flowed
I did not see an answer to Kylie's question (below), thus here is a
quick (not perfect but workable) solution:
/* ------------------------------------------------------ */
/* SPSS syntax to convert PRELIS output to correlation */
/* matrix (quick and dirty): */
/* Example: Prelis output of a single line of correlation */
/* coefficients: */
/* 0.10000D+01 -0.25278D-02 0.10000D+01 0.23427D+00 -0.58275D-01
0.10000D+01 0.48736D-01 0.54267D-01 -0.21431D+00 0.10000D+01 */
/* Firstly: Edit the Prelis output using a text-editor. */
/* Use the find/replace (all) option to: */
/* (a) replace all double spaces by one space (if */
/* necessary, repeatedly), */
/* (b) replace each space character by a return (line */
/* break such as ^p or similar, depending on your */
/* editor), */
/* (c) replace each D by E. */
/* */
/* Save the file as an ASCII or TXT file, for example */
/* as 'prelis.dat'. */
/* */
/* The result should look similar to the lines between */
/* "begin data" and "end data": */
data list list
/var1.
begin data
0.10000E+01
-0.25278E-02
0.10000E+01
0.23427E+00
-0.58275E-01
0.10000E+01
0.48736E-01
0.54267E-01
-0.21431E+00
0.10000E+01
end data.
/* Secondly run the following SPSS syntax (adapt the path */
/* to 'prelis.dat' accordingly): */
/* (to test the example without having 'prelis dat' */
/* available, make comments of the following four syntax */
/* lines: */
GET TRANSLATE FILE='prelis.dat'
/TYPE=TAB
/MAP .
EXECUTE .
matrix.
get rvec
/file=*
/variables=var1.
compute d = nrow(rvec).
/* Determine number of variables from length of rvec: */
compute rest = d.
LOOP np=1 TO d.
compute rest = rest - np.
END LOOP IF (rest = 0).
/* Create matrix containing 0: */
compute mat = make(NP,NP,0).
/* Write elements of rvec to matrix: */
compute r = 1.
compute c = 1.
LOOP i=1 TO d.
compute mat(r,c) = rvec(i).
compute mat(c,r) = rvec(i).
DO IF (r = c).
compute c = 1.
compute r = r+1.
ELSE.
compute c = c+1.
END IF.
END LOOP.
PRINT mat.
/* Write matrix as matrix system file to active data file: */
MSAVE mat
/TYPE = CORR
/OUTFILE=*.
end matrix.
/* Thirdly: */
/* RENAME VARIABLE NAMES (3 : np) AND VALUES OF */
/* VARIABLE varname_ MANUALLY. */.
/* ------------------------------------------------------ */
Dirk
------------------------------------------------
Thu, 8 Sep 2005 11:30:36 +0930,
Kylie Lange <kylie.lange@flinders.edu.au> wrote:
> I have a user who has is calculating polychoric correlations is PRELIS
> (part of LISREL) and then using those as a correlation matrix input to
> SPSS' factor analysis procedure. At the moment he takes the text
> output
> from PRELIS and uses Excel to get it into SPSS' matrix format. This is
> fiddly for large correlation matrices so he would ideally like a way
> to directly import the text output into SPSS via syntax.
>
> The PRELIS output comes as a single line (no line breaks). For
> example:
>
> 0.10000D+01 -0.25278D-02 0.10000D+01 0.23427D+00 -0.58275D-01
> 0.10000D+01 0.48736D-01 0.54267D-01 -0.21431D+00 0.10000D+01
>
> It also uses PRELIS' own version of scientific notation, with
> 0.10000D+01 = 1.0000. The PRELIS output represents the lower half of
> the correlation matrix, reading each row from left to right. So
> -0.25278D-02 is the correlation between x2 and x1. The ideal end
> result would be a SPSS data file with the same structure that the
> below syntax gives:
>
> matrix data variables = rowtype_ x1 x2 x3 x4.
> begin data
> mean 0.0 0.0 0.0 0.0 0.0 0.0
> stddev 1.0 1.0 1.0 1.0 1.0 1.0
> n 100 100 100 100 100 100
> corr 1 -0.0025278 0.23427 0.048736
> corr -0.0025278 1 -0.058275 0.054267
> corr 0.23427 -0.058275 1 -0.21432
> corr 0.048736 0.054267 -0.21432 1
> end data.
>
> Does anyone have any suggestions of where to start with this?
*************************************************
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg
Germany
phone: +49-040-42838.7498 (office)
+49-040-42838.4591 (Billon)
fax: +49-040-42838.2344
email: dirk.enzmann@jura.uni-hamburg.de
www:
http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
*************************************************