


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



#################### Factor Analysis ############################### ##Example 9.
X=read.table("Sta135jiming/Wichern_data/T8-4.dat") names(X)=c("JPMorgan","Citibank","WellsFargo","RoyalDutchShell","ExxonMobil") #### Principal component solution of factor model ############
S=var(X) R=cor(X) R JPMorgan Citibank WellsFargo RoyalDutchShell ExxonMobil JPMorgan 1.0000000 0.6322878 0.5104973 0.1146019 0. Citibank 0.6322878 1.00000 00 0.5741424 0.3222921 0. WellsFargo 0.5104973 0.5741424 1.0000000 0.1824992 0. RoyalDutchShell 0.1146019 0.3222921 0.1824992 1.0000000 0. ExxonMobil 0.1544628 0.2126747 0.1462067 0.6833777 1.0 000000 eig=eigen(R) eig$val [1] 2.4372731 1.4070127 0.5005127 0.4000316 0. eig$vec [,1] [,2] [,3] [,4] [,5] [1,] - 0.4690832 0.3680070 0.60431522 0.3630228 0. [2,] - 0.5324055 0.2364624 0.13610 618 - 0.6292079 - 0. [3,] - 0.4651633 0.3151795 - 0.77182810 0.2889658 0. [4,] - 0.3873459 - 0.5850373 - 0.09336192 - 0.3812515 0. [5,] - 0.3606821 - 0.6058463 0.10882629 0.4934145 - 0. m= L=(eig$vec %*% diag(sqrt(eig$val)))[,1:m] ###Estimated factor loadings
~
Psi = diag(R - L%*%t(L)) ### Estimated specific variances
~ i
Psi JPMorgan Citibank WellsFargo RoyalDutchShell ExxonMobil 0.2731542 0.2304689 0.3328604 0.1527429 0. hi2 = apply(L^2, 1, sum) ### Estimated communalities
~ i 2
hi [1] 0.72 68458 0.7695311 0.6671396 0.8472571 0. 1 - hi2 ###alternative calculation of the estimated specific variances [1] 0.2731542 0.2304689 0.3328604 0.1527429 0.
R function factanal() provides maximum likelihood estimates method, based on R matrix (SAS provides principal component estimates method) ########################################################################################## #### MLE without rotation #################
factanal(X,factor=2,rotation="none") Call: factanal(x = X, factors = 2, rotation = "none") Uniquenesses: [1] 0.417 0.275 0.542 0.005 0. Loadings: Factor1 Factor [1,] 0.121 0. [2,] 0.328 0. [3,] 0.188 0. [4,] 0. [5,] 0. Factor1 Factor SS loadings 1.622 1. Proportion Var 0.324 0.
Cumulative Var 0.324 0. Test of the hypothesis that 2 factors are sufficient. The chi square statistic is 1.97 on 1 degree of freedom. The p-value is 0. ######### MLE with rotation = varimax ########
factanal(X,factor=2,rotation="varimax") Call: factanal(x = X, factors = 2, rotation = "varimax") Uniquenesses: [1] 0.417 0.275 0.542 0.005 0. Loadings: Factor1 Factor [1,] 0.
[2,] 0.819 0. [3,] 0.668 0. [4,] 0.113 0. [5,] 0.108 0. Factor1 Factor SS loadings 1.725 1. Proportion Var 0.345 0. Cumulative Var 0. 345 0. Test of the hypothesis that 2 factors are sufficient. The chi square statistic is 1.97 on 1 degree of freedom. The p-value is 0. ###Store results###
fit=factanal(X,factor=2,rotation="none") names(fit) [1] "converged" "loadings" " uniquenesses " "correlation" "criteria" "factors" "dof" [8] "method" "STATISTIC" "PVAL" "n.obs" "call" ###To access the estimated specific variances
~ i ###
fit$uniq JPMorgan Citibank WellsFargo RoyalDutchShell ExxonMobil 0.4165374 0.2746902 0.5420233 0.0050000 0.
###Predict factors (factor scores) using regression method###
fit3=factanal(X,factor=2,rotation="none",scores="regression") fit3$scores Factor1 Factor [1,] - 1.8011656 0. [2,] 0.2977760 0. [3,] - 0.1545820 - 0. [4,] - 1.2035382 0. : :
plot(fit3$scores,pch=20,xlab="Factor1",ylab="Factor2",main="Factor scores by regression") abline(h=0) abline(v=0)