Docsity

Notes on Factor Analysis - Multivariable Data Analysis | STA 135, Study notes of Descriptive statistics

Toggle sidebar
bg1
############## ###### Factor Analysis ##### ############# #############
##Example 9.10
> X=read.table ("Sta135jiming /Wichern_data/ T8-4.dat")
> names(X)=c(" JPMorgan","Cit ibank","WellsF argo","RoyalD utchShell","Ex xonMobil")
#### Principal component sol ution of factor model ####### #####
#### of m=2 fa ctors
> S=var(X)
> R=cor(X)
> R
JPMorgan C itibank WellsF argo RoyalDut chShell ExxonM obil
JPMorgan 1.0000000 0.6322878 0 .5104973 0.1146019 0.1544628
Citibank 0.6322878 1. 0000000 0.5741424 0. 3222921 0.212 6747
WellsFargo 0.5104973 0. 5741424 1.000 0000 0. 1824992 0.146 2067
RoyalDutchShel l 0.1146019 0. 3222921 0.182 4992 1. 0000000 0 .6833777
ExxonMobil 0.1544628 0. 2126747 0.146 2067 0. 6833777 1.0000000
> eig=eigen(R)
> eig$val
[1] 2.4372731 1.4070127 0.50 05127 0.400031 6 0.2551699
> eig$vec
[,1 ] [,2] [,3] [,4] [,5]
[1,] -0.469083 2 0.3680070 0.60431522 0. 3630228 0.38 412160
[2,] -0.532405 5 0.2364624 0.13610618 -0.629 2079 -0.496187 94
[3,] -0.465163 3 0.3151795 -0. 77182810 0.28 89658 0.0711 6948
[4,] -0.387345 9 -0.5850373 -0. 09336192 -0.381 2515 0.594664 08
[5,] -0.360682 1 -0.6058463 0. 10882629 0.49 34145 -0.497551 67
> m=2
> L=(eig$vec % *% diag(sqrt(e ig$val)))[,1:m] # ##Estimated factor loadings
!
{l
~
ij}
> L
[,1 ] [,2]
[1,] -0.732321 8 0.4365209
[2,] -0.831179 1 0.2804859
[3,] -0.726202 2 0.3738582
[4,] -0.604715 5 -0.6939569
[5,] -0.563088 5 -0.7186401
> Psi = diag(R - L%*%t(L)) ### Estimated spe cific variances
!
"
~
i
> Psi
JPMorga n Citib ank Wells Fargo RoyalDu tchShell ExxonMobil
0.273154 2 0.2304 689 0.33 28604 0 .1527429 0.1664878
> hi2 = apply( L^2, 1, sum) ### Estimate d communaliti es
!
h
~
i
2
> hi2
[1] 0.7268458 0.7695311 0.66 71396 0.847257 1 0.8335122
> 1-hi2 ###al ternative calc ulation of the estimated sp ecific varianc es
[1] 0.2731542 0.2304689 0.33 28604 0.152742 9 0.1664878
pf3
pf4

Partial preview of the text

Download Notes on Factor Analysis - Multivariable Data Analysis | STA 135 and more Study notes Descriptive statistics in PDF only on Docsity!

#################### 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 ############

of m=2 factors

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

{ l

~

ij }

> L

[,1] [,2]

[1,] - 0.7323218 0.

[2,] - 0.8311791 0.

[3,] - 0.7262022 0.

[4,] - 0.6047155 - 0.

[5,] - 0.5630885 - 0.

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

h

~ 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 the predicted factor scores

plot(fit3$scores,pch=20,xlab="Factor1",ylab="Factor2",main="Factor scores by regression") abline(h=0) abline(v=0)