# Factor Analysis with the Principal Factor Method and R

**R – Aaron Schlegel**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

As discussed in a previous post on the principal component method of factor analysis, the [latex]\hat{\Psi}[/latex] term in the estimated covariance matrix [latex]S[/latex], [latex]S = \hat{\Lambda} \hat{\Lambda}’ + \hat{\Psi}[/latex], was excluded and we proceeded directly to factoring [latex]S[/latex] and [latex]R[/latex]. The principal factor method of factor analysis (also called the principal axis method) finds an initial estimate of [latex]\hat{\Psi}[/latex] and factors [latex]S – \hat{\Psi}[/latex], or [latex]R – \hat{\Psi}[/latex] for the correlation matrix. Rearranging the estimated covariance and correlation matrices with the estimated [latex]p \times m[/latex] [latex]\hat{\Lambda}[/latex] matrix yields:

[latex display=”true”] S – \hat{\Psi} = \hat{\Lambda} \hat{\Lambda}^\prime [/latex]

[latex display=”true”] R – \hat{\Psi} = \hat{\Lambda} \hat{\Lambda}^\prime [/latex]

Therefore the principal factor method begins with eigenvalues and eigenvectors of [latex]S – \hat{\Psi}[/latex] or [latex]R – \hat{\Psi}[/latex]. [latex]\hat{\Psi}[/latex] is a diagonal matrix of the [latex]i[/latex]th communality. As in the principal component method, the [latex]i[/latex]th communality, [latex]\hat{h}^2_i[/latex], is equal to [latex]s_{ii} – \hat{\psi}_i[/latex] for [latex]S – \hat{\Psi}[/latex] and [latex]1 – \hat{\psi}_i[/latex] for [latex]R – \hat{\Psi}[/latex]. The diagonal of [latex]S[/latex] or [latex]R[/latex] is replaced by their respective communalities in [latex]\hat{\psi}_i[/latex] which gives us the following forms:

[latex display=”true”] S – \hat{\Psi} = \begin{bmatrix} \hat{h}^2_1 && s_{12} && \cdots && s_{1p} \\\ s_{21} && \hat{h}^2_2 && \cdots && s_{2p} \\\ \vdots && \vdots && && \vdots \\\ s_{p1} && s_{p2} && \cdots && \hat{h}^2_p \\\ \end{bmatrix}[/latex]

[latex display=”true”] R – \hat{\Psi} = \begin{bmatrix} \hat{h}^2_1 && r_{12} && \cdots && r_{1p} \\\ r_{21} && \hat{h}^2_2 && \cdots && r_{2p} \\\ \vdots && \vdots && && \vdots \\\ r_{p1} && r_{p2} && \cdots && \hat{h}^2_p \\\ \end{bmatrix}[/latex]

An initial estimate of the communalities is made using the squared multiple correlation between the observation vector [latex]y_i[/latex] and the other [latex]p – 1[/latex] variables. The squared multiple correlation in the case of [latex]R – \hat{\Psi}[/latex] is equivalent to the following:

[latex display=”true”] \hat{h}^2_i = 1 – \frac{1}{r^{ii}} [/latex]

Where [latex]r^{ii}[/latex] is the [latex]i[/latex]th diagonal element of [latex]R^{-1}[/latex]. In the case of [latex]S – \hat{\Psi}[/latex], the above is multiplied by the variance of the respective variable.

The factor loadings are then calculated by finding the eigenvalues and eigenvectors of the [latex]R – \hat{\Psi}[/latex] or [latex]S – \hat{\Psi}[/latex] matrix.

###### Factor Analysis with the Principal Factor Method in R

We will perform factor analysis using the principal factor method on the rootstock data as done previously with the principal component method to see if the approaches differ significantly. The data were obtained from the companion FTP site of the book Methods of Multivariate Analysis by Alvin Rencher. The data contains four dependent variables as follows:

- trunk girth at four years (mm [latex]\times[/latex] 100)
- extension growth at four years (m)
- trunk girth at 15 years (mm [latex]\times[/latex] 100)
- weight of tree above ground at 15 years (lb [latex]\times[/latex] 1000)

Load the data and name the columns

root <- read.table('ROOT.DAT', col.names = c('Tree.Number', 'Trunk.Girth.4.Years', 'Ext.Growth.4.Years', 'Trunk.Girth.15.Years', 'Weight.Above.Ground.15.Years'))

Since the variables of the rootstock data were measured on different scales, we will proceed with using the correlation matrix [latex]R[/latex] to perform factor analysis.

Find the correlation matrix.

R <- cor(root[,2:5]) round(R, 2) ## Trunk.Girth.4.Years Ext.Growth.4.Years ## Trunk.Girth.4.Years 1.00 0.88 ## Ext.Growth.4.Years 0.88 1.00 ## Trunk.Girth.15.Years 0.44 0.52 ## Weight.Above.Ground.15.Years 0.33 0.45 ## Trunk.Girth.15.Years ## Trunk.Girth.4.Years 0.44 ## Ext.Growth.4.Years 0.52 ## Trunk.Girth.15.Years 1.00 ## Weight.Above.Ground.15.Years 0.95 ## Weight.Above.Ground.15.Years ## Trunk.Girth.4.Years 0.33 ## Ext.Growth.4.Years 0.45 ## Trunk.Girth.15.Years 0.95 ## Weight.Above.Ground.15.Years 1.00

Calculate and replace the diagonal of [latex]R[/latex] with the estimated communalities.

R.smc <- (1 - 1 / diag(solve(R))) diag(R) <- R.smc round(R, 2) ## Trunk.Girth.4.Years Ext.Growth.4.Years ## Trunk.Girth.4.Years 0.80 0.88 ## Ext.Growth.4.Years 0.88 0.81 ## Trunk.Girth.15.Years 0.44 0.52 ## Weight.Above.Ground.15.Years 0.33 0.45 ## Trunk.Girth.15.Years ## Trunk.Girth.4.Years 0.44 ## Ext.Growth.4.Years 0.52 ## Trunk.Girth.15.Years 0.91 ## Weight.Above.Ground.15.Years 0.95 ## Weight.Above.Ground.15.Years ## Trunk.Girth.4.Years 0.33 ## Ext.Growth.4.Years 0.45 ## Trunk.Girth.15.Years 0.95 ## Weight.Above.Ground.15.Years 0.91

Now that we have an initial estimate of the communalities, we can find the eigenvalues and eigenvectors of the [latex]R - \hat{\Psi}[/latex] matrix.

r.eigen <- eigen(R) r.eigen$values ## [1] 2.64598796 0.90756969 -0.03306996 -0.09008523

The [latex]R[/latex] matrix is no longer positive semidefinite due to replacing the diagonal with the communalities. Thus there are a few small negative eigenvalues. Since negative eigenvalues cannot be used to estimate [latex]\hat{\Lambda}[/latex] (due to taking the square root of the [latex]D[/latex] matrix), we can proceed with [latex]m = 2[/latex].

An interesting note is when negative eigenvalues exist, the cumulative proportion of variance calculated from the eigenvalues will exceed [latex]1[/latex] and then decline back to [latex]1[/latex] after considering the negative eigenvalues. The following loop demonstrates this phenomenon:

tot.prop <- 0 for (i in r.eigen$values) { tot.prop <- tot.prop + i / sum(r.eigen$values) print(tot.prop) } ## [1] 0.7713346 ## [1] 1.035901 ## [1] 1.026261 ## [1] 1

Obtain the factor loadings as before by multiplying the square root of the first two eigenvalues by their respective eigenvectors.

r.lambda <- as.matrix(r.eigen$vectors[,1:2]) %*% diag(sqrt(r.eigen$values[1:2])) r.lambda ## [,1] [,2] ## [1,] -0.7402973 0.5421762 ## [2,] -0.8034091 0.4520610 ## [3,] -0.8770380 -0.4050851 ## [4,] -0.8266112 -0.4951379

The communalities, specific variances and complexity of the factor loadings can then be calculated.

r.h2 <- rowSums(r.lambda^2) r.u2 <- 1 - r.h2 com <- rowSums(r.lambda^2)^2 / rowSums(r.lambda^4)

Collect the results into a `data.frame`

.

cor.pa <- data.frame(cbind(round(r.lambda, 2), round(r.h2, 2), round(r.u2, 3), round(com, 1))) colnames(cor.pa) <- c('PA1', 'PA2', 'h2', 'u2', 'com') cor.pa ## PA1 PA2 h2 u2 com ## 1 -0.74 0.54 0.84 0.158 1.8 ## 2 -0.80 0.45 0.85 0.150 1.6 ## 3 -0.88 -0.41 0.93 0.067 1.4 ## 4 -0.83 -0.50 0.93 0.072 1.6

###### Principal Factor Method with the `psych`

Package

The psych package also performs factor analysis using the principal method with the `fa()`

function.

library(psych)

The `fa()`

function performs the iterated principal factor method by default, which, as the name implies, iterates the initial communality estimates with those of the resulting [latex]\hat{\Lambda}[/latex] matrix until they converge. This approach to factor analysis will be demonstrated in a future post. Setting the `max.iter`

argument to 1 will output the non-iterated principal factor method results.

root.cor.fa <- fa(root[,2:5], nfactors = 2, rotate = 'none', fm = 'pa', max.iter = 1) root.cor.fa ## Factor Analysis using method = pa ## Call: fa(r = root[, 2:5], nfactors = 2, rotate = "none", max.iter = 1, ## fm = "pa") ## Standardized loadings (pattern matrix) based upon correlation matrix ## PA1 PA2 h2 u2 com ## Trunk.Girth.4.Years 0.74 0.54 0.84 0.158 1.8 ## Ext.Growth.4.Years 0.80 0.45 0.85 0.150 1.6 ## Trunk.Girth.15.Years 0.88 -0.41 0.93 0.067 1.4 ## Weight.Above.Ground.15.Years 0.83 -0.50 0.93 0.072 1.6 ## ## PA1 PA2 ## SS loadings 2.65 0.91 ## Proportion Var 0.66 0.23 ## Cumulative Var 0.66 0.89 ## Proportion Explained 0.74 0.26 ## Cumulative Proportion 0.74 1.00 ## ## Mean item complexity = 1.6 ## Test of the hypothesis that 2 factors are sufficient. ## ## The degrees of freedom for the null model are 6 and the objective function was 4.19 with Chi Square of 187.92 ## The degrees of freedom for the model are -1 and the objective function was 0.17 ## ## The root mean square of the residuals (RMSR) is 0.02 ## The df corrected root mean square of the residuals is NA ## ## The harmonic number of observations is 48 with the empirical chi square 0.24 with prob < NA ## The total number of observations was 48 with MLE Chi Square = 7.26 with prob < NA ## ## Tucker Lewis Index of factoring reliability = 1.281 ## Fit based upon off diagonal values = 1 ## Measures of factor score adequacy ## PA1 PA2 ## Correlation of scores with factors 0.98 0.93 ## Multiple R square of scores with factors 0.95 0.86 ## Minimum correlation of possible factor scores 0.90 0.72

The results of the `fa()`

function align to our own other than an arbitrary scaling of the first factor by [latex]-1[/latex].

###### Rotation of Factor Loadings

Rotate the factors using varimax rotation to improve interpretation. Varimax rotation of the loadings can be done with the `varimax()`

function, or in the `fa()`

function by setting the `rotate`

argument to `varimax`

.

root.cor.fa.v <- fa(root[,2:5], nfactors = 2, rotate = 'varimax', fm = 'pa', max.iter = 1) root.cor.fa.v ## Factor Analysis using method = pa ## Call: fa(r = root[, 2:5], nfactors = 2, rotate = "varimax", max.iter = 1, ## fm = "pa") ## Standardized loadings (pattern matrix) based upon correlation matrix ## PA1 PA2 h2 u2 com ## Trunk.Girth.4.Years 0.19 0.90 0.84 0.158 1.1 ## Ext.Growth.4.Years 0.30 0.87 0.85 0.150 1.2 ## Trunk.Girth.15.Years 0.92 0.29 0.93 0.067 1.2 ## Weight.Above.Ground.15.Years 0.95 0.18 0.93 0.072 1.1 ## ## PA1 PA2 ## SS loadings 1.87 1.68 ## Proportion Var 0.47 0.42 ## Cumulative Var 0.47 0.89 ## Proportion Explained 0.53 0.47 ## Cumulative Proportion 0.53 1.00 ## ## Mean item complexity = 1.1 ## Test of the hypothesis that 2 factors are sufficient. ## ## The degrees of freedom for the null model are 6 and the objective function was 4.19 with Chi Square of 187.92 ## The degrees of freedom for the model are -1 and the objective function was 0.17 ## ## The root mean square of the residuals (RMSR) is 0.02 ## The df corrected root mean square of the residuals is NA ## ## The harmonic number of observations is 48 with the empirical chi square 0.24 with prob < NA ## The total number of observations was 48 with MLE Chi Square = 7.26 with prob < NA ## ## Tucker Lewis Index of factoring reliability = 1.281 ## Fit based upon off diagonal values = 1 ## Measures of factor score adequacy ## PA1 PA2 ## Correlation of scores with factors 0.97 0.94 ## Multiple R square of scores with factors 0.94 0.87 ## Minimum correlation of possible factor scores 0.88 0.75

###### Principal Component and Principal Factor Methods Comparison

The principal factor method (and iterated principal factor method) will usually yield results close to the principal component method if either the correlations or the number of variables is large (Rencher, 2002, pp. 424).

Perform the principal component method of factor analysis and compare with the principal factor method.

root.cor.pa <- principal(root[,2:5], nfactors = 2, rotate = 'varimax') root.cor.pa ## Principal Components Analysis ## Call: principal(r = root[, 2:5], nfactors = 2, rotate = "varimax") ## Standardized loadings (pattern matrix) based upon correlation matrix ## RC1 RC2 h2 u2 com ## Trunk.Girth.4.Years 0.16 0.96 0.95 0.051 1.1 ## Ext.Growth.4.Years 0.28 0.93 0.94 0.061 1.2 ## Trunk.Girth.15.Years 0.94 0.29 0.97 0.027 1.2 ## Weight.Above.Ground.15.Years 0.97 0.19 0.98 0.022 1.1 ## ## RC1 RC2 ## SS loadings 1.94 1.90 ## Proportion Var 0.48 0.48 ## Cumulative Var 0.48 0.96 ## Proportion Explained 0.50 0.50 ## Cumulative Proportion 0.50 1.00 ## ## Mean item complexity = 1.1 ## Test of the hypothesis that 2 components are sufficient. ## ## The root mean square of the residuals (RMSR) is 0.03 ## with the empirical chi square 0.39 with prob < NA ## ## Fit based upon off diagonal values = 1

Both methods achieved a simple structure of the loadings following rotation. The loadings from each method are rather similar and don’t differ significantly, though the principal component method yielded factors that load more heavily on the variables which the factors hypothetically represent. However, the factors resulting from the principal component method explain 96% of the cumulative variance compared to 89% from the principal factor method. Though not a drastic difference, one is inclined to proceed with the principal component method in this case as the factors account for almost all of the variance in the variables.

###### References

Rencher, A. (2002). Methods of Multivariate Analysis (2nd ed.). Brigham Young University: John Wiley & Sons, Inc.

The post Factor Analysis with the Principal Factor Method and R appeared first on Aaron Schlegel.

**leave a comment**for the author, please follow the link and comment on their blog:

**R – Aaron Schlegel**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.