Importing Correlation Matrix for Factor Analysis

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

Importing Correlation Matrix for Factor Analysis

KEVIN MANNING
Dear list-mates,

   I am having some trouble importing a spearman correlation matrix for use with Factor Analysis.  I am quite the novice when it comes to this, so I have been trying to use a syntax from the archives:

CORRELATIONS
  /VARIABLES=x1 TO x10
  /MATRIX=OUT('c:\temp\corr1_.sav')
  /MISSING=PAIRWISE .
NONPAR CORR
  /VARIABLES=x1 TO x10
  /PRINT=SPEARMAN
  /MATRIX=OUT('c:\temp\corr2_.sav')
  /MISSING=PAIRWISE .

GET FILE='c:\temp\corr2_.sav'.
EXECUTE .
SELECT IF(rowtype_ ~= 'N').
EXECUTE .
RECODE  rowtype_  ('RHO'='CORR')  .
EXECUTE .
SAVE OUTFILE='c:\temp\corr2_.sav'.
GET FILE='c:\temp\corr1_.sav'.
EXECUTE .
SELECT IF($casenum<4).
EXECUTE .
ADD FILES /FILE=*
 /FILE='c:\temp\corr2_.sav'.
EXECUTE.

FACTOR
 /MATRIX=IN(cor='c:\temp\c_matrix.sav')
 /ANALYSIS x1 TO x10
  /PRINT KMO AIC EXTRACTION ROTATION
  /FORMAT SORT BLANK(0.4)
  /PLOT EIGEN
  /CRITERIA MINEIGEN(1) ITERATE(25)
  /EXTRACTION PC
  /CRITERIA ITERATE(25)
  /ROTATION VARIMAX
  /METHOD=CORRELATION .

****
     I am not sure I am doing this right - do I need the pearson correlation matrix here?  When I attempt to run the Factor Analysis without it, I reiceve an error message that the 'N' variables was not created (telling SPSS how large my sample is?).

And when I run the syntax as is, I receive an error message that the input variables are of the wrong type (?).

I really could use some help with this.  Thanks !!
Kevin
Reply | Threaded
Open this post in threaded view
|

Re: Importing Correlation Matrix for Factor Analysis

Marta Garcia-Granero
I Kevin

Since I wrote the code time ago, I'll try to help you

KEVIN MANNING escribió:

>    I am having some trouble importing a spearman correlation matrix for use with Factor Analysis.  I am quite the novice when it comes to this, so I have been trying to use a syntax from the archives:
>
> CORRELATIONS
>   /VARIABLES=x1 TO x10
>   /MATRIX=OUT('c:\temp\corr1_.sav')
>   /MISSING=PAIRWISE .
> NONPAR CORR
>   /VARIABLES=x1 TO x10
>   /PRINT=SPEARMAN
>   /MATRIX=OUT('c:\temp\corr2_.sav')
>   /MISSING=PAIRWISE .
>
> GET FILE='c:\temp\corr2_.sav'.
> EXECUTE .
> SELECT IF(rowtype_ ~= 'N').
> EXECUTE .
> RECODE  rowtype_  ('RHO'='CORR')  .
> EXECUTE .
> SAVE OUTFILE='c:\temp\corr2_.sav'.
> GET FILE='c:\temp\corr1_.sav'.
> EXECUTE .
> SELECT IF($casenum<4).
> EXECUTE .
> ADD FILES /FILE=*
>  /FILE='c:\temp\corr2_.sav'.
> EXECUTE.
>
> FACTOR
>  /MATRIX=IN(cor='c:\temp\c_matrix.sav')
>  /ANALYSIS x1 TO x10
>   /PRINT KMO AIC EXTRACTION ROTATION
>   /FORMAT SORT BLANK(0.4)
>   /PLOT EIGEN
>   /CRITERIA MINEIGEN(1) ITERATE(25)
>   /EXTRACTION PC
>   /CRITERIA ITERATE(25)
>   /ROTATION VARIMAX
>   /METHOD=CORRELATION .
>
> ****
>      I am not sure I am doing this right - do I need the pearson correlation matrix here?
The Pearson correlation matrix is used to extract meand & sd data
(necessary for some tests, I think it is the Bartlett sphericity test)
in factor analysis.
>   When I attempt to run the Factor Analysis without it, I reiceve an error message that the 'N' variables was not created (telling SPSS how large my sample is?).
>
> And when I run the syntax as is, I receive an error message that the input variables are of the wrong type (?).
>
You simply skipped one very important line of the code:

SAVE OUTFILE='c:\temp\c_matrix.sav'.


This line saves the "hybrid" file (Spearman's correlation coefficents,
plus N, means & SD) that will be used by the FACTOR procedura for input.

BTW, you can avoid all the redundant "EXECUTE." scattered along the
syntax (I wrote it time ago, when I hadn't read Richard Ristow's
postings about the use and abuse of "EXE".

This is a shortened (but fully functional) version of that code:

* First, some dummy data to work with (replace by your own).
INPUT PROGRAM.
- VECTOR X(10).
- LOOP #I = 1 TO 100.
- LOOP #J = 1 TO 10.
- COMPUTE X(#J) = UNIFORM(5).
- END LOOP.
- END CASE.
- END LOOP.
- END FILE.
END INPUT PROGRAM.
execute.

* Here, replace "x1 TO x10" by the names of your variables *.
CORRELATIONS
  /VARIABLES=x1 TO x10
  /MATRIX=OUT('c:\temp\corr1_.sav')
  /MISSING=PAIRWISE .
NONPAR CORR
  /VARIABLES=x1 TO x10
  /PRINT=SPEARMAN
  /MATRIX=OUT('c:\temp\corr2_.sav')
  /MISSING=PAIRWISE .

* Now, the task is authomatic, don't modify anything *.
GET FILE='c:\temp\corr2_.sav'.
SELECT IF(rowtype_ ~= 'N').
RECODE  rowtype_  ('RHO'='CORR')  .
SAVE OUTFILE='c:\temp\corr2_.sav'.
GET FILE='c:\temp\corr1_.sav'.
SELECT IF($casenum<4).
ADD FILES /FILE=*
 /FILE='c:\temp\corr2_.sav'.
SAVE OUTFILE='c:\temp\c_matrix.sav'.

* Factor analysis (you can modify some options to suit your needs) *.
FACTOR
 /MATRIX=IN(cor='c:\temp\c_matrix.sav')
 /ANALYSIS x1 TO x10
  /PRINT KMO AIC EXTRACTION ROTATION
  /FORMAT SORT BLANK(0.4)
  /PLOT EIGEN
  /CRITERIA MINEIGEN(1) ITERATE(25)
  /EXTRACTION PC
  /CRITERIA ITERATE(25)
  /ROTATION VARIMAX
  /METHOD=CORRELATION .

Regards,
Marta Garcia-Granero
Reply | Threaded
Open this post in threaded view
|

Re: Importing Correlation Matrix for Factor Analysis

Marta Garcia-Granero
Questions should be addressed TO THE LIST, please  :-)

KEVIN MANNING escribió:
> Thanks Marta, I am still having some trouble with this (?).  Perhaps you could take a look.  Below is the error message from SPSS ; I don't see in the syntax where the variable "rowtype_" is created, and that seems to be tripping me up.

It should be created authomatically by the NONPAR CORR procedure.
> GET FILE='C:\KEVINM~1\LOCALS~1\Temp\corr2_.sav'.
>

OK, stop here before running the next command, and take a look at the
dataset you've just loaded. List the contents and email them to me (to
the list, of course).
Reply | Threaded
Open this post in threaded view
|

Re: Importing Correlation Matrix for Factor Analysis

KEVIN MANNING
Thank you.  Ahh - I see where I was making an error (why rowtype_ was not created).  Ok, but here is my new error message(?).  It seems the variable varname is a string variable in one file and a numeric variable in the other (?).

Thank you all for your help.

***
GET FILE='C:\KEVINM~1\LOCALS~1\corr2_.sav'.
SELECT IF(rowtype_ ~= 'N').
RECODE  rowtype_  ('RHO'='CORR')  .
SAVE OUTFILE='C:\KEVINM~1\LOCALS~1\corr2_.sav'.
GET FILE='C:\KEVINM~1\LOCALS~1\Temp\corr1_.sav'.
SELECT IF($casenum<4).
ADD FILES /FILE=*
 /FILE='C:\KEVINM~1\LOCALS~1\corr2_.sav'.

Variable(s) with conflicting type:

                       ------Input1------          ------Input2------
Result                 Type Variable name          Type Variable name

VARNAME_               s36  VARNAME_               s13  VARNAME_

Codes:  num = numeric;  sn = string of length n

>Error # 5127
>Mismatched variable types on the input files.
>This command not executed.


>Note # 5145
>The working file has been restored, and subsequent commands may access the
>working file.

SAVE OUTFILE='c:\C:\KEVINM~1\LOCALS~1\Temp\c_matrix.sav'.

>Error # 61 in column 14.  Text: c:\C:\KEVINM~1\LOCALS~1\Temp\c_matrix.sav
>The filename is not valid.
>This command not executed.

****



----- Original Message -----
From: Marta Garcia-Granero <[hidden email]>
Date: Tuesday, June 19, 2007 9:59 am
Subject: Re: Importing Correlation Matrix for Factor Analysis
To: [hidden email]


> Questions should be addressed TO THE LIST, please  :-)
>
> KEVIN MANNING escribió:
> > Thanks Marta, I am still having some trouble with this (?).  Perhaps
> you could take a look.  Below is the error message from SPSS ; I don't
> see in the syntax where the variable "rowtype_" is created, and that
> seems to be tripping me up.
>
> It should be created authomatically by the NONPAR CORR procedure.
> > GET FILE='C:\KEVINM~1\LOCALS~1\Temp\corr2_.sav'.
> >
>
> OK, stop here before running the next command, and take a look at the
> dataset you've just loaded. List the contents and email them to me (to
> the list, of course).
Reply | Threaded
Open this post in threaded view
|

Re: Importing Correlation Matrix for Factor Analysis

Marta Garcia-Granero
Hi Kevin

KEVIN MANNING escribió:
> Thank you.  Ahh - I see where I was making an error (why rowtype_ was not created).  Ok, but here is my new error message(?).  It seems the variable varname is a string variable in one file and a numeric variable in the other (?).
>

Both are String variables, but one of them is longer than the other! 35
characters against 13). Which SPSS version are you using? The code
worked absolutely OK in my computer using SPSS 13, as it did when I
wrote it for SPSS 11 or 12 (I don't remember right now). I can't check
it in SPSS 15, because the computer with SPSS 15 intalled is not
conected to Internet (long story, I want to skin alive my ADSL provider,
I'm still sneaking into my neighbour's wireless connection using the lap
top after 7 days with my "legal" connection out of order and still
unrepaired...).

> Variable(s) with conflicting type:
>
>                        ------Input1------          ------Input2------
> Result                 Type Variable name          Type Variable name
>
> VARNAME_               s36  VARNAME_               s13  VARNAME_
>
> Codes:  num = numeric;  sn = string of length n
>
>

The only solution I can think of right now involves manual processing of
the datasets. After loading  "corr2_.sav", go to the Data Editor,
Variable View and change manually the lenght of the string variable
VARNAME_ from 13 to 36. Then go back to the syntax window and proceed
with the rest of the manipulation steps as before.

GET FILE='c:\Temp\Corr2_.sav'.

Go to Variable View and modify the lenght of the string variable...
Go back to Syntax window and run next commands.

SELECT IF......
RECODE....
SAVE....


Keep me informed.

Regards,
Marta
Reply | Threaded
Open this post in threaded view
|

Re: Importing Correlation Matrix for Factor Analysis

Maguin, Eugene
In reply to this post by KEVIN MANNING
Kevin,

I think you misunderstood the error message you received. This is the
relevant part.

                       ------Input1------          ------Input2------
Result                 Type Variable name          Type Variable name
VARNAME_               s36  VARNAME_               s13  VARNAME_

In file 1 VARNAME_ is a 36 character string variable and in file 2 it is a
13 character string. To fix it, you'll need to convert VARNAME_ in file 2 to
a36 format. (You can go that other way and convert the file 1 variable name
to a13.)

Gene Maguin
Reply | Threaded
Open this post in threaded view
|

Re: Importing Correlation Matrix for Factor Analysis

KEVIN MANNING
In reply to this post by Marta Garcia-Granero
Thanks Marta.  That worked fine (I am not sure why that occurred; I use version 12).  Anyway, thanks for all your help.
Kevin


Research Study Coordinator
Division of Medical Psychology
The Johns Hopkins Hospital
600 N. Wolfe Street / Meyer 218
Baltimore, MD 21287-7218
phone: (410)955-1647
fax: (410)955-0504
e-mail: [hidden email]

----- Original Message -----
From: Marta Garcia-Granero <[hidden email]>
Date: Tuesday, June 19, 2007 10:51 am
Subject: Re: Importing Correlation Matrix for Factor Analysis
To: [hidden email]


> Hi Kevin
>
> KEVIN MANNING escribió:
> > Thank you.  Ahh - I see where I was making an error (why rowtype_
> was not created).  Ok, but here is my new error message(?).  It seems
> the variable varname is a string variable in one file and a numeric
> variable in the other (?).
> >
>
> Both are String variables, but one of them is longer than the other! 35
> characters against 13). Which SPSS version are you using? The code
> worked absolutely OK in my computer using SPSS 13, as it did when I
> wrote it for SPSS 11 or 12 (I don't remember right now). I can't check
> it in SPSS 15, because the computer with SPSS 15 intalled is not
> conected to Internet (long story, I want to skin alive my ADSL provider,
> I'm still sneaking into my neighbour's wireless connection using the lap
> top after 7 days with my "legal" connection out of order and still
> unrepaired...).
>
> > Variable(s) with conflicting type:
> >
> >                        ------Input1------          ------Input2------
> > Result                 Type Variable name          Type Variable name
> >
> > VARNAME_               s36  VARNAME_               s13  VARNAME_
> >
> > Codes:  num = numeric;  sn = string of length n
> >
> >
>
> The only solution I can think of right now involves manual processing
> of
> the datasets. After loading  "corr2_.sav", go to the Data Editor,
> Variable View and change manually the lenght of the string variable
> VARNAME_ from 13 to 36. Then go back to the syntax window and proceed
> with the rest of the manipulation steps as before.
>
> GET FILE='c:\Temp\Corr2_.sav'.
>
> Go to Variable View and modify the lenght of the string variable...
> Go back to Syntax window and run next commands.
>
> SELECT IF......
> RECODE....
> SAVE....
>
>
> Keep me informed.
>
> Regards,
> Marta