SPSS Statistics

 View Only
  • 1.  Polychoric EFA

    Posted Fri September 23, 2022 10:22 AM
    Does anyone know how to run EFA using a polychoric correlation matrix?

    I have downloaded the HETCOR extension

    ------------------------------
    Emily Bell
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Polychoric EFA

    Posted Fri September 23, 2022 12:32 PM
    Hi. 

    As I see it, you would use OMS to save out the HETCOR matrix, read that back in using MATRIX DATA, and finally submit that to FACTOR using its MATRIX subcommand.

    If that's not clear enough - and it may well not be - I think I could put together an example.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 3.  RE: Polychoric EFA

    Posted Fri September 23, 2022 02:29 PM
    Something like this will work:

    oms select tables /if subtypes='HeterogeneousCorrelations'
      /destination format=text outfile="/temp/matrix.txt"
      /tag="_x_".
    SPSSINC HETCOR gender educ salary salbegin minority
     /OPTIONS ESTIMATOR=TWOSTEP STDERR=TRUE MISSING=PAIRWISE N=TRUE TYPE=TRUE
     /SAVE.
    omsend tag="_x_".
    begin program Python3.
    varlist="gender educ salary salbegin minority"
    my_corrline=[]
    my_ns=[]
    IN="/temp/matrix.txt"
    OUT="/temp/matrix_data.sps"
    with open(IN) as file:
        lines = file.readlines()
        lines = [line.rstrip() for line in lines]
    for l in lines:
      corr=l.find("Correlation ")
      n=l.find("N ")
      if corr > 0: my_corrline.append(l[corr:].replace("Correlation",'').strip())
      if n > 0:    my_ns.append(l[n:].replace("N",'').strip())
     
    F=open(OUT, 'w')
    print("MATRIX DATA VARIABLES=ROWTYPE_ " + varlist + "\n /FORMAT=FULL.\nBEGIN DATA.",file=F)
    print("N " + str(my_ns[0].replace("'",'')),file=F)
    for c in my_corrline:
      print("CORR " + str(c),file=F)
    print("END DATA.\n",file=F)
    F.close()
    end program.
    insert file="temp/matrix_data.sps".
    FACTOR MATRIX IN(COR=*) /MISSING=LISTWISE.

    Where I have bolded, you change to suit what you want. Just make sure that the strings for the list of variables and the 2 temp files are the same where they need to be, since they are referenced more than once.

    Obviously, you may want some different settings for the factor analysis. See the manual for details, since order of subcommands matters for FA.

    Hope this helps.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------