los datos del ejemplo se pueden descargar en ATGC_expfa.xlsx
#Exploratory factor analysis in R
################packages to install
#install.packages("psych") ######PCA/EFA amongst many other things!
#install.packages("REdaS") ######produces KMO and Bartletts test
#install.packages("readxl") ######reads excel
library(psych)
library(readxl)
library(REdaS)
## Loading required package: grid
##############read in the data set
ATGC <- read_excel("E:/ATGC_expFA.xlsx")
View(ATGC)
attach(ATGC)
#############
bart_spher(ATGC) ###### produces Bartletts test of spherecity (you want this to be significant)
## Bartlett's Test of Sphericity
##
## Call: bart_spher(x = ATGC)
##
## X2 = 1165.567
## df = 36
## p-value < 2.22e-16
KMO(ATGC) ###### Kaiser-Meyer-Olkin measure, you want to be above .7
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = ATGC)
## Overall MSA = 0.78
## MSA for each item =
## ATGC_1 ATGC_2 ATGC_3 ATGC_4 ATGC_5 ATGC_6 ATGC_7 ATGC_8 ATGC_9
## 0.79 0.79 0.82 0.87 0.66 0.73 0.77 0.86 0.78
#############FA, if you are doing a PCA switch fa to say principal
##########using Kaisers rule, Eigenvalues>1 represent valid factors
###set nfactors to n items, in this case there is 12 items so we state nfactors=12
#####oblimin is selected as the rotation although this is default for factor
# analysis (variamx is default for pca)
##orthagonal roatations availible ="none", "varimax", "quartimax", "bentlerT",
#"equamax", "varimin", "geominT" "bifactor"
##oblique roatations availible "Promax", "promax", "oblimin", "simplimax", "bentlerQ, "geominQ" "biquartimin" "cluster"
fa(ATGC, nfactors = 3, rotate = "oblimin" )
## Loading required namespace: GPArotation
## Factor Analysis using method = minres
## Call: fa(r = ATGC, nfactors = 3, rotate = "oblimin")
## Standardized loadings (pattern matrix) based upon correlation matrix
## MR2 MR1 MR3 h2 u2 com
## ATGC_1 -0.07 0.07 0.73 0.57 0.43 1.0
## ATGC_2 0.04 -0.02 0.79 0.62 0.38 1.0
## ATGC_3 0.04 -0.04 0.69 0.46 0.54 1.0
## ATGC_4 0.52 -0.02 0.16 0.32 0.68 1.2
## ATGC_5 0.88 -0.04 -0.04 0.74 0.26 1.0
## ATGC_6 0.79 0.09 0.03 0.70 0.30 1.0
## ATGC_7 -0.07 0.80 0.04 0.63 0.37 1.0
## ATGC_8 0.16 0.61 0.00 0.47 0.53 1.1
## ATGC_9 0.02 0.81 -0.03 0.65 0.35 1.0
##
## MR2 MR1 MR3
## SS loadings 1.75 1.72 1.69
## Proportion Var 0.19 0.19 0.19
## Cumulative Var 0.19 0.39 0.57
## Proportion Explained 0.34 0.33 0.33
## Cumulative Proportion 0.34 0.67 1.00
##
## With factor correlations of
## MR2 MR1 MR3
## MR2 1.00 0.34 0.25
## MR1 0.34 1.00 0.50
## MR3 0.25 0.50 1.00
##
## Mean item complexity = 1
## Test of the hypothesis that 3 factors are sufficient.
##
## The degrees of freedom for the null model are 36 and the objective function was 3.23 with Chi Square of 1165.57
## The degrees of freedom for the model are 12 and the objective function was 0.03
##
## The root mean square of the residuals (RMSR) is 0.01
## The df corrected root mean square of the residuals is 0.02
##
## The harmonic number of observations is 366 with the empirical chi square 4.22 with prob < 0.98
## The total number of observations was 366 with Likelihood Chi Square = 11.85 with prob < 0.46
##
## Tucker Lewis Index of factoring reliability = 1
## RMSEA index = 0 and the 90 % confidence intervals are 0 0.053
## BIC = -58.98
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy
## MR2 MR1 MR3
## Correlation of (regression) scores with factors 0.92 0.91 0.90
## Multiple R square of scores with factors 0.85 0.82 0.80
## Minimum correlation of possible factor scores 0.70 0.65 0.61
###################you can produce a figure
M1<-fa(ATGC, nfactors = 3, rotate = "oblimin" ) ##save the analysis as the object m1
fa.diagram(M1,main="ATGC") ## produce a figure with the title ""
#note fa.diagram still works for PCA