4. Factor Analysis: Exploratory, Confirmatory

David Gerbing

Data

Access the lessR data set called datMach4 for the analysis of 351 people to the Mach IV scale. Read the optional variable labels. Including the item contents as variable labels means that the output of the confirmatory factor analysis contains the item content grouped by factor.

d <- Read("Mach4", quiet=TRUE)
l <- Read("Mach4_lbl", var_labels=TRUE)
## 
## >>> Suggestions
## Recommended binary format for data files: feather
##   Create with Write(d, "your_file", format="feather")
## More details about your data, Enter:  details()  for d, or  details(name)
## 
## Data Types
## ------------------------------------------------------------
## character: Non-numeric data values
## ------------------------------------------------------------
## 
##     Variable                  Missing  Unique 
##         Name     Type  Values  Values  Values   First and last values
## ------------------------------------------------------------------------------------------
##  1     label character     20       0      20   Never tell anyone the real reason you did something unless it is useful to do so ... Most people forget more easily the death of a parent than the loss of their property
## ------------------------------------------------------------------------------------------

Calculate the correlations and store in here in R, a data structure that contains the computed correlation matrix.

R <- cr(m01:m20)
## 
## >>> No missing data
## 
## 
## Note: To provide more color separation for off-diagonal
##       elements, the diagonal elements of the matrix for
##       computing the heat map are set to 0.

The correlation matrix for analysis is named R. The item (observed variable) correlation matrix is the numerical input into the confirmatory factor analysis.

View the correlation matrix.

corPrint(R, min_value=0.1)
##       m01 m02 m03 m04 m05 m06 m07 m08 m09 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20
##   m01 100      16      17 -11 -13  22 -14 -15      25  17      11     -12  19      17
##   m02     100     -15  12          14 -18 -22      18  13      25                    
##   m03  16     100          24  24      16  15  10          10      10                
##   m04     -15     100          14 -11  14  11  14 -18 -14  23      13  13            
##   m05  17  12         100 -11 -10  10         -13  23  22         -19      20      11
##   m06 -11      24     -11 100  52      25  41  29 -14 -16  11 -15  24     -21        
##   m07 -13      24  14 -10  52 100      32  40  22 -16 -11  15 -17  21  13 -16        
##   m08  22  14     -11  10         100 -10     -10  10     -12              12      15
##   m09 -14 -18  16  14      25  32 -10 100  25  16 -14 -13     -17  17  15         -17
##   m10 -15 -22  15  11      41  40      25 100  15 -18      15 -18  11  15 -16     -12
##   m11          10  14 -13  29  22 -10  16  15 100 -20 -11  26      28     -23     -17
##   m12  25  18     -18  23 -14 -16  10 -14 -18 -20 100  22 -11     -15 -22  10      20
##   m13  17  13     -14  22 -16 -11     -13     -11  22 100  12  16     -12  16      18
##   m14          10  23      11  15 -12      15  26 -11  12 100      22  10         -13
##   m15  11  25             -15 -17     -17 -18          16     100          22        
##   m16          10  13 -19  24  21      17  11  28 -15      22     100                
##   m17 -12          13          13      15  15     -22 -12  10         100         -25
##   m18  19              20 -21 -16  12     -16 -23  10  16      22         100        
##   m19                                                                         100    
##   m20  17              11          15 -17 -12 -17  20  18 -13         -25         100

Exploratory Factor Analysis

Here, do the default two-factor solution with "promax" rotation. The default correlation matrix is mycor. The abbreviation for corEFA() is efa().

efa(R, n_factors=4)
##   EXPLORATORY FACTOR ANALYSIS 
## 
## Loadings (except -0.2 to 0.2) 
## ------------------------------------- 
##       Factor1 Factor2 Factor3 Factor4 
##   m06   0.828                  -0.290 
##   m07   0.712                         
##   m10   0.539                         
##   m03   0.422   0.318                 
##   m09   0.323                         
##   m05           0.649                 
##   m18           0.555   0.253         
##   m13           0.543   0.226         
##   m01           0.490                 
##   m12           0.434  -0.230         
##   m08           0.236  -0.202         
##   m14           0.402   0.991  -0.401 
##   m04                   0.426         
##   m20           0.237  -0.282         
##   m17                   0.267         
##   m19                                 
##   m11          -0.299   0.309  -0.609 
##   m16                   0.274  -0.455 
##   m02                          -0.319 
##   m15  -0.207   0.203          -0.214 
## 
## Sum of Squares 
## ------------------------------------------------ 
##                  Factor1 Factor2 Factor3 Factor4 
##      SS loadings   1.933   2.038   1.825   1.099 
##   Proportion Var   0.097   0.102   0.091   0.055 
##   Cumulative Var   0.097   0.199   0.290   0.345 
## 
##   CONFIRMATORY FACTOR ANALYSIS CODE 
## 
## MeasModel <-  
## "  F1 =~ m01 + m02 + m03 + m04 + m05 
##    F2 =~ m06 + m07 + m08 + m09 + m10 + m11 
##    F3 =~ m12 + m13 + m14 + m15 
##    F4 =~ m17 + m18 + m19 + m20 
## " 
##  
## fit <- lessR::cfa(MeasModel)
##  
## library(lavaan) 
## fit <- lavaan::cfa(MeasModel, data=d) 
## summary(fit, fit.measures=TRUE, standardized=TRUE) 
## 
## Deletion threshold: min_loading = 0.2 
## Deleted items: m16

Confirmatory Factor Analysis

The confirmatory factor analysis is of multiple-indicator measurement scales, that is, each item (observed variable) is assigned to only one factor. Solution method is centroid factor analysis.

Specify the measurement model for the analysis in Lavaan notation. Define four factors: Deceit, Trust, Cynicism, and Flattery.

MeasModel <- 
" 
   Deceit =~ m07 + m06 + m10 + m09 
   Trust =~ m12 + m05 + m13 + m01 
   Cynicism =~ m11 + m16 + m04 
   Flattery =~ m15 + m02 
"

Do the confirmatory factor analysis of 4-factor solution of Mach IV scale, Hunter, Gerbing and Boster (1982). By default output goes to the console, or, can store the output into an object, here cfa_out, which can then be displayed as a whole, or piecemeal.

The abbreviation for corCFA() is cfa().

cfa_out <- cfa(MeasModel, R)

cfa_out
##   FACTOR / SCALE COMPOSITION 
## 
## F1 
## ------------------------------ 
## m07: There is no excuse for lying to someone else 
## m06: Honesty is the best policy in all cases 
## m10: When you ask someone to do something for you, it is best to give the real reasons for wanting 
##      it rather than giving reasons which carry more weight 
## m09: All in all, it is better to be humble and honest than to be important and dishonest 
##  
## F2 
## ------------------------------ 
## m12: Anyone who completely trusts anyone else is asking for trouble 
## m05: It is safest to assume that all people have a vicious streak and it will come out when they 
##      are given a chance 
## m13: The biggest difference between most criminals and other people is that the criminals are 
##      stupid enough to get caught 
## m01: Never tell anyone the real reason you did something unless it is useful to do so 
##  
## F3 
## ------------------------------ 
## m11: Most people who get ahead in the world lead clean, moral lives 
## m16: It is possible to be good in all respects 
## m04: Most people are basically good and kind 
##  
## F4 
## ------------------------------ 
## m15: It is wise to flatter important people 
## m02: The best way to handle people is to tell them what they want to hear 
## 
##   RELIABILITY ANALYSIS 
## 
##  Scale   Alpha    Omega 
## ----------------------- 
##    F1    0.691    0.701 
##    F2    0.515    0.517 
##    F3    0.402    0.421 
##    F4    0.400    0.400 
## 
##   SOLUTION 
## 
## Fac  Indi   Pat    Unique  Factors with which an indicator correlates too 
## tor  cator  tern   ness    highly, and other indicator diagnostics. 
## --------------------------------------------------------------------------- 
##  
##  F1  m07   0.743   0.448     
##  F1  m06   0.682   0.535     
##  F1  m10   0.578   0.666     
##  F1  m09   0.409   0.832     
##  
##  F2  m12   0.540   0.708     
##  F2  m05   0.446   0.801     
##  F2  m13   0.435   0.810     
##  F2  m01   0.415   0.828     
##  
##  F3  m11   0.549   0.698     
##  F3  m16   0.510   0.740     
##  F3  m04   0.255   0.935     F2  
##  
##  F4  m15   0.500   0.750     
##  F4  m02   0.500   0.750     
## 
##                                                                            Cyn Fla 
##                                                                    Dec Tru ici tte 
##            m07 m06 m10 m09| m12 m05 m13 m01| m11 m16 m04| m15 m02| eit  st  sm  ry 
##                                                                                    
##        m07  55  52  40  32| -16 -10 -11 -13|  22  21  14| -17    |  74 -27  43 -26 
##        m06  52  47  41  25| -14 -11 -16 -11|  29  24    | -15    |  68 -28  47 -19 
##        m10  40  41  33  25| -18         -15|  15  11  11| -18 -22|  58 -23  28 -40 
##        m09  32  25  25  17| -14     -13 -14|  16  17  14| -17 -18|  41 -27  36 -35 
## ---------------------------------------------------------------------------------- 
##        m12 -16 -14 -18 -14|  29  23  22  25| -20 -15 -18|      18| -26  54 -40  26 
##        m05 -10 -11        |  23  20  22  17| -13 -19    |      12| -13  45 -31  21 
##        m13 -11 -16     -13|  22  22  19  17| -11     -14|  16  13| -20  44 -21  29 
##        m01 -13 -11 -15 -14|  25  17  17  17|            |  11    | -22  42 -19  18 
## ---------------------------------------------------------------------------------- 
##        m11  22  29  15  16| -20 -13 -11    |  30  28  14|        |  34 -29  55     
##        m16  21  24  11  17| -15 -19        |  28  26  13|        |  30 -25  51     
##        m04  14      11  14| -18     -14    |  14  13    |     -15|  20 -27  25 -16 
## ---------------------------------------------------------------------------------- 
##        m15 -17 -15 -18 -17|          16  11|            |  25  25| -28  24      50 
##        m02         -22 -18|  18  12  13    |         -15|  25  25| -22  27 -13  50 
## ---------------------------------------------------------------------------------- 
##     Deceit  74  68  58  41| -26 -13 -20 -22|  34  30  20| -28 -22| 100 -44  64 -50 
##      Trust -27 -28 -23 -27|  54  45  44  42| -29 -25 -27|  24  27| -44 100 -61  51 
##   Cynicism  43  47  28  36| -40 -31 -21 -19|  55  51  25|     -13|  64 -61 100 -16 
##   Flattery -26 -19 -40 -35|  26  21  29  18|         -16|  50  50| -50  51 -16 100 
## 
##   RESIDUALS 
## 
##       m07 m06 m10 m09| m12 m05 m13 m01| m11 m16 m04| m15 m02| 
##                                                               
##   m07                |                |            |      09| 
##   m06                |                |  05        |      13| 
##   m10                |      09        | -05 -08    |     -08| 
##   m09                |         -05 -07|          07| -07 -08| 
## ------------------------------------------------------------- 
##   m12                |                |         -10| -06    | 
##   m05          09    |                |     -05    |        | 
##   m13             -05|                |      11 -07|        | 
##   m01             -07|                |            |        | 
## ------------------------------------------------------------- 
##   m11      05 -05    |                |            |      05| 
##   m16         -08    |     -05  11    |            |        | 
##   m04              07| -10     -07    |            |     -13| 
## ------------------------------------------------------------- 
##   m15             -07| -06            |            |        | 
##   m02  09  13 -08 -08|                |  05     -13|        | 
## ------------------------------------------------------------- 
## 
##       Sum of    Average
##       Squares   Abs Value
##       -------   --------- 
##  m07    0.017    0.030 
##  m06    0.024    0.032 
##  m10    0.031    0.044 
##  m09    0.028    0.042 
##  m12    0.020    0.034 
##  m05    0.017    0.029 
##  m13    0.027    0.040 
##  m01    0.014    0.028 
##  m11    0.015    0.030 
##  m16    0.026    0.036 
##  m04    0.038    0.039 
##  m15    0.015    0.028 
##  m02    0.061    0.056 
##  
## Total sum of squares for all items: 0.333 
##  
## Root mean square residual for all items: 0.577 
##  
## Average absolute residual w/o the diagonal: 0.036 
## 
##  
## 
##   LAVAAN SPECIFICATION 
## 
## MeasModel  <- 
## " 
##    Deceit =~ m07 + m06 + m10 + m09 
##    Trust =~ m12 + m05 + m13 + m01 
##    Cynicism =~ m11 + m16 + m04 
##    Flattery =~ m15 + m02 
## "
##  
## library(lavaan) 
## fit <- lavaan::cfa(MeasModel, data=d, std.ov=TRUE, std.lv=TRUE) 
## summary(fit, fit.measures=TRUE) 
##  
## -------- 
## The preceding code fits the model from data frame:  d 
## To access the correlation matrix directly without the data 
##   replace the parameter  data  with the parameters 
##         sample.cov  and  sample.nobs 
##   These names refer to the name of the input correlation matrix and sample size
## 

Or, view pieces. See the names of all the output components. The output includes:

names(cfa_out)
##  [1] "call"                "out_title_scales"    "out_labels"         
##  [4] "out_title_rel"       "out_reliability"     "out_title_solution" 
##  [7] "out_indicators"      "out_solution"        "out_title_residuals"
## [10] "out_residuals"       "out_res_stats"       "out_title_lavaan"   
## [13] "out_lavaan"          "out_Rmd"             "ff.cor"             
## [16] "if.cor"              "diag.cor"            "alpha"              
## [19] "omega"               "pred"                "resid"

Here just view just the scale reliabilities.

cfa_out$out_reliability
##  Scale   Alpha    Omega
## -----------------------
##    F1    0.691    0.701
##    F2    0.515    0.517
##    F3    0.402    0.421
##    F4    0.400    0.400

Can also just analysis item content, without the factor analysis.

cfa(MeasModel, labels="only")
##  
## F1 
## ------------------------------ 
## m07: There is no excuse for lying to someone else 
## m06: Honesty is the best policy in all cases 
## m10: When you ask someone to do something for you, it is best to give the real reasons for wanting it rather than giving reasons which carry more weight 
## m09: All in all, it is better to be humble and honest than to be important and dishonest 
##  
## F2 
## ------------------------------ 
## m12: Anyone who completely trusts anyone else is asking for trouble 
## m05: It is safest to assume that all people have a vicious streak and it will come out when they are given a chance 
## m13: The biggest difference between most criminals and other people is that the criminals are stupid enough to get caught 
## m01: Never tell anyone the real reason you did something unless it is useful to do so 
##  
## F3 
## ------------------------------ 
## m11: Most people who get ahead in the world lead clean, moral lives 
## m16: It is possible to be good in all respects 
## m04: Most people are basically good and kind 
##  
## F4 
## ------------------------------ 
## m15: It is wise to flatter important people 
## m02: The best way to handle people is to tell them what they want to hear 
## 

Generate R Markdown instructions of the confirmation factor analysis with the option: Rmd. Output file in this example will be m4.Rmd, a simple text file that can be edited with any text editor including RStudio, from which it can be knit to generate dynamic output such as to a Word document.

c <- cfa(MeasModel, R, Rmd="m4")

Re-order the Correlation Matrix

Hierarchical Cluster Analysis

Re-order the correlation matrix and display its heat map according to a hierarchical cluster analysis, indicated by the default parameter of the order parameter, hclust. Default input correlation matrix is the mycor structure, from which R will be extracted automatically.

The optional n_clusters parameter indicates to display corresponding cluster membership according to the specified number of clusters from the hierarchical tree. Although a four-factor solution, choose five clusters to allow for a “garbage” cluster.

corReorder(R, n_clusters=5)
## 
##  5 Cluster Solution 
## -------------------
## m01 m05 m08 m12 m13 m18 m20 m02 m15 m03 m06 m07 m09 m10 m04 m11 m14 m16 m17 m19 
##   1   1   1   1   1   1   1   2   2   3   3   3   3   3   4   4   4   4   5   5

##       m02   m15   m08   m20   m18   m01   m12   m05   m13   m17   m19   m03
## m02  1.00  0.25  0.14  0.08  0.08  0.07  0.18  0.12  0.13 -0.05 -0.03  0.00
## m15  0.25  1.00  0.06  0.04  0.22  0.11  0.08  0.09  0.16 -0.02 -0.01 -0.01
## m08  0.14  0.06  1.00  0.15  0.12  0.22  0.10  0.10  0.09 -0.06  0.04  0.06
## m20  0.08  0.04  0.15  1.00  0.09  0.17  0.20  0.11  0.18 -0.25 -0.03 -0.05
## m18  0.08  0.22  0.12  0.09  1.00  0.19  0.10  0.20  0.16 -0.08  0.00  0.09
## m01  0.07  0.11  0.22  0.17  0.19  1.00  0.25  0.17  0.17 -0.12  0.08  0.16
## m12  0.18  0.08  0.10  0.20  0.10  0.25  1.00  0.23  0.22 -0.22 -0.06  0.04
## m05  0.12  0.09  0.10  0.11  0.20  0.17  0.23  1.00  0.22 -0.06 -0.08  0.06
## m13  0.13  0.16  0.09  0.18  0.16  0.17  0.22  0.22  1.00 -0.12 -0.01 -0.06
## m17 -0.05 -0.02 -0.06 -0.25 -0.08 -0.12 -0.22 -0.06 -0.12  1.00  0.09  0.07
## m19 -0.03 -0.01  0.04 -0.03  0.00  0.08 -0.06 -0.08 -0.01  0.09  1.00  0.02
## m03  0.00 -0.01  0.06 -0.05  0.09  0.16  0.04  0.06 -0.06  0.07  0.02  1.00
## m09 -0.18 -0.17 -0.10 -0.17 -0.09 -0.14 -0.14 -0.09 -0.13  0.15  0.02  0.16
## m10 -0.22 -0.18 -0.07 -0.12 -0.16 -0.15 -0.18 -0.02 -0.08  0.15 -0.01  0.15
## m06 -0.04 -0.15 -0.05 -0.07 -0.21 -0.11 -0.14 -0.11 -0.16  0.05  0.02  0.24
## m07 -0.09 -0.17 -0.09 -0.07 -0.16 -0.13 -0.16 -0.10 -0.11  0.13  0.02  0.24
## m11  0.01 -0.02 -0.10 -0.17 -0.23 -0.09 -0.20 -0.13 -0.11  0.03  0.01  0.10
## m16 -0.03 -0.01 -0.06 -0.01 -0.07 -0.08 -0.15 -0.19 -0.03  0.06  0.00  0.10
## m04 -0.15 -0.01 -0.11 -0.09 -0.05 -0.08 -0.18 -0.09 -0.14  0.13  0.02  0.07
## m14 -0.02  0.01 -0.12 -0.13  0.06 -0.03 -0.11  0.06  0.12  0.10  0.08  0.10
##       m09   m10   m06   m07   m11   m16   m04   m14
## m02 -0.18 -0.22 -0.04 -0.09  0.01 -0.03 -0.15 -0.02
## m15 -0.17 -0.18 -0.15 -0.17 -0.02 -0.01 -0.01  0.01
## m08 -0.10 -0.07 -0.05 -0.09 -0.10 -0.06 -0.11 -0.12
## m20 -0.17 -0.12 -0.07 -0.07 -0.17 -0.01 -0.09 -0.13
## m18 -0.09 -0.16 -0.21 -0.16 -0.23 -0.07 -0.05  0.06
## m01 -0.14 -0.15 -0.11 -0.13 -0.09 -0.08 -0.08 -0.03
## m12 -0.14 -0.18 -0.14 -0.16 -0.20 -0.15 -0.18 -0.11
## m05 -0.09 -0.02 -0.11 -0.10 -0.13 -0.19 -0.09  0.06
## m13 -0.13 -0.08 -0.16 -0.11 -0.11 -0.03 -0.14  0.12
## m17  0.15  0.15  0.05  0.13  0.03  0.06  0.13  0.10
## m19  0.02 -0.01  0.02  0.02  0.01  0.00  0.02  0.08
## m03  0.16  0.15  0.24  0.24  0.10  0.10  0.07  0.10
## m09  1.00  0.25  0.25  0.32  0.16  0.17  0.14  0.06
## m10  0.25  1.00  0.41  0.40  0.15  0.11  0.11  0.15
## m06  0.25  0.41  1.00  0.52  0.29  0.24  0.09  0.11
## m07  0.32  0.40  0.52  1.00  0.22  0.21  0.14  0.15
## m11  0.16  0.15  0.29  0.22  1.00  0.28  0.14  0.26
## m16  0.17  0.11  0.24  0.21  0.28  1.00  0.13  0.22
## m04  0.14  0.11  0.09  0.14  0.14  0.13  1.00  0.23
## m14  0.06  0.15  0.11  0.15  0.26  0.22  0.23  1.00

Use the hclust_type parameter to specify the type of cluster analysis provided by base R beyond the default of "complete". Other possibilities include "ward.D", "ward.D2", "single", "average".

Manual Reorder

The variables in the correlation matrix can be re-ordered manually, including sub-setting the matrix. Do so with the vars parameter, specifying the index (ordinal positioning) of each variable in the re-ordered matrix.

Here, subset six variables from the original correlation matrix. Specifying the vars parameter automatically sets order to manual, so no need to separately specify.

R2 <- corReorder(R, vars=c(6,7,9,10,15,2))

R2
##       m06   m07   m09   m10   m15   m02
## m06  1.00  0.52  0.25  0.41 -0.15 -0.04
## m07  0.52  1.00  0.32  0.40 -0.17 -0.09
## m09  0.25  0.32  1.00  0.25 -0.17 -0.18
## m10  0.41  0.40  0.25  1.00 -0.18 -0.22
## m15 -0.15 -0.17 -0.17 -0.18  1.00  0.25
## m02 -0.04 -0.09 -0.18 -0.22  0.25  1.00

Full Manual

Use the base R help() function to view the full manual for the factor analysis and correlation matrix functions. Simply enter a question mark followed by the name of the function.

?corCFA
?corEFA
?corScree
?corProp
?corRead
?corReflect
?corReorder
?Correlation