简体   繁体   中英

extract the correlation matrix for the factors in the psych package's fa.poly function

I'm working from caracal's great example conducting a factor analysis on dichotomous data and I'm now struggling to extract the factors from the object produced by the psych package's fa.poly function.

Can anyone help me extract the factors from the fa.poly object (and look at the correlation)?

Please see caracal's example for the working example.

In this example you create an object with:

faPCdirect <- fa.poly(XdiNum, nfactors=2, rotate="varimax")    # polychoric FA

so somewhere in faPCdirect there is what you want. I recommend using str() to inspect the structure of faPCdirect

> str(faPCdirect)

List of 5
 $ fa   :List of 34
  ..$ residual    : num [1:6, 1:6] 4.79e-01 7.78e-02 -2.97e-0...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:6] "X1" "X2" "X3" "X4" ...
  .. .. ..$ : chr [1:6] "X1" "X2" "X3" "X4" ...
  ..$ dof         : num 4
  ..$ fit      
      ...skip stuff....
  ..$ BIC         : num 4.11
  ..$ r.scores    : num [1:2, 1:2] 1 0.0508 0.0508 1
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "MR2" "MR1"
  .. .. ..$ : chr [1:2] "MR2" "MR1"
  ..$ R2          : Named num [1:2] 0.709 0.989
  .. ..- attr(*, "names")= chr [1:2] "MR2" "MR1"
  ..$ valid       : num [1:2] 0.819 0.987
  ..$ score.cor   : num [1:2, 1:2] 1 0.212 0.212 1

So this says that this object is a list of five, with the first element called fa and that contains an element called score.cor that is a 2x2 matrix. I think what you want is the off diagonal.

> faPCdirect$fa$score.cor
          [,1]      [,2]
[1,] 1.0000000 0.2117457
[2,] 0.2117457 1.0000000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM