[R] nearest correlation to polychoric

William Revelle lists at revelle.net
Sat Jul 14 00:31:10 CEST 2007


Jens,
   An alternative solution to the improper matrix 
problem is to do a principal factor solution 
rather than a maximum likelihood  factor analysis 
solution.   In the following discussion, I am 
using the factor.pa  (principal factor) function 
from my psych package.


Using your test set
  pr <- structure(c(1, 0.477, 0.644, 0.478, 0.651, 0.826, 0.477, 1, 0.516,
    0.233, 0.682, 0.75, 0.644, 0.516, 1, 0.599, 0.581, 0.742, 0.478,
   0.233, 0.599, 1, 0.741, 0.8, 0.651, 0.682, 0.581, 0.741, 1, 0.798,
   0.826, 0.75, 0.742, 0.8, 0.798, 1), .Dim = c(6, 6))

I did a factor.pa(pr,2) and got

Loadings:
      PA1  PA2
[1,] 0.52 0.54
[2,] 0.13 0.92
[3,] 0.56 0.49
[4,] 0.97 0.11
[5,] 0.63 0.58
[6,] 0.73 0.70

                  PA1   PA2
SS loadings    2.472 2.217
Proportion Var 0.412 0.369
Cumulative Var 0.412 0.781

This compares to a factanal solution on the nearcor solution
  nr <- nearcor(pr)$cor
f2 <- factanal(cov=nr, factors=2)

Loadings:
      Factor1 Factor2
[1,] 0.735   0.388 
[2,] 0.868   0.123 
[3,] 0.534   0.523 
[4,] 0.151   0.986 
[5,] 0.508   0.660 
[6,] 0.740   0.669 

                Factor1 Factor2
SS loadings      2.407   2.295
Proportion Var   0.401   0.382
Cumulative Var   0.401   0.784


The factor congruence of the two solutions is

  round(factor.congruence(f2,p2),2)
          PA1  PA2
Factor1 0.74 0.99
Factor2 1.00 0.68

However, when I do the same analysis on your 
second demo set, in one run I got a Haywood case 
for the principal factors.
f2 <- factor.pa(hcor,2,n.obs=400)

Loadings:
    PA1   PA2 
x1        0.87
x2        0.65
x3 -0.10  0.64
x4        0.56
y1  0.51     
y2  0.63     
y3  0.78     
y4  1.13     

                 PA1   PA2
SS loadings    2.56 1.917
Proportion Var 0.32 0.240
Cumulative Var 0.32 0.560


but not for the factanal of the nearcor solution for the hcor problem:
ncor <- nearcor(hcor)$cor
m2 <- factanal(covmat=ncor,factors=2,n.obs=400)

Loadings:
      Factor1 Factor2
[1,]          0.899
[2,] -0.168   0.569
[3,]          0.647
[4,]          0.583
[5,]  0.468        
[6,]  0.683        
[7,]  0.877  -0.100
[8,]  0.997        

                Factor1 Factor2
SS loadings      2.486   1.907
Proportion Var   0.311   0.238
Cumulative Var   0.311   0.549

However, once again, the factor congruence coefficients are very good:

round(factor.congruence(m2,f2),2)
           PA1   PA2
Factor1  0.99 -0.09
Factor2 -0.09  1.00


Then, I did a number of runs comparing principal 
axes to the hetcor data (what you call hcor), 
factanal  to the original data ( what you call 
xcor, and factanal solutions to the nearcor 
solution (ncor).  The general pattern is that 
principal axes of the polychoric (hcor) matrix 
tends to match the factanal solutions to the 
original data better than factanal of the nearcor 
matrix does the original matrix.

   round(factor.congruence(f2,n2),2)   #compare 
principal axes to mle of nearcor solution
     Factor1 Factor2
PA1    0.98    0.17
PA2    0.18    0.99
>        round(factor.congruence(f2,x2),2) 
>#compare principal axes to mle of original data
     Factor1 Factor2
PA1    0.92    0.07
PA2    0.10    0.95
>        round(factor.congruence(n2,x2),2) 
>#compare mle of original to mle of nearcor
         Factor1 Factor2
Factor1    0.92    0.02
Factor2    0.03    0.94

Thanks for posting the nearcor algorithm and function.








At 8:42 PM +0200 7/13/07, Jens Oehlschlägel wrote:
>Dimitris,
>
>Thanks a lot for the quick response with the 
>pointer to posdefify. Using its logic as an 
>afterburner to the algorithm of Higham seems to 
>work.
>
>Martin,
>
>>  Jens, could you make your code (mentioned 
>>below) available to the community, or even 
>>donate to be included as a new method of 
>>posdefify() ?
>
>Nice opportunity to give-back. Below is the R 
>code for nearcor and .Rd help file. A quite 
>natural place for nearcor would be John Fox' 
>package polycor, what do you think?
>
>John?
>
>Best regards
>
>Jens Oehlschlägel




{nearcor function and help file deleted --- see original posting}


Bill

-- 
William Revelle		http://personality-project.org/revelle.html
Professor			http://personality-project.org/personality.html
Department of Psychology             http://www.wcas.northwestern.edu/psych/
Northwestern University	http://www.northwestern.edu/
Use R for statistics:                          http://personality-project.org/r



More information about the R-help mailing list