library(readr)
Darlington <- read_csv("~/SA projects 2019/Christopher Darlington/Darlington.csv")
## Parsed with column specification:
## cols(
## .default = col_double()
## )
## See spec(...) for full column specifications.
View(Darlington)
attach(Darlington)
library(factoextra)
## Loading required package: ggplot2
## Welcome! Related Books: `Practical Guide To Cluster Analysis in R` at https://goo.gl/13EFCZ
library(FactoMineR)
library(ggplot2)
library(nFactors)
## Loading required package: MASS
## Loading required package: psych
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
## Loading required package: boot
##
## Attaching package: 'boot'
## The following object is masked from 'package:psych':
##
## logit
## Loading required package: lattice
##
## Attaching package: 'lattice'
## The following object is masked from 'package:boot':
##
## melanoma
##
## Attaching package: 'nFactors'
## The following object is masked from 'package:lattice':
##
## parallel
library(psych)
##screen plot , determining the number of factors or components in form of dimensions to be considered
res.pca <- prcomp(Darlington, scale = TRUE)
fviz_eig(res.pca)
fviz_pca_var(res.pca,
col.var = "contrib", # Color by contributions to the PC
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)
fviz_pca_ind(res.pca,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)
eig.val <- get_eigenvalue(res.pca)
eig.val
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 12.4846760 41.6155868 41.61559
## Dim.2 2.2782194 7.5940646 49.20965
## Dim.3 1.6924597 5.6415322 54.85118
## Dim.4 1.4085301 4.6951003 59.54628
## Dim.5 1.0788981 3.5963270 63.14261
## Dim.6 1.0175697 3.3918991 66.53451
## Dim.7 0.9158606 3.0528686 69.58738
## Dim.8 0.8839461 2.9464871 72.53387
## Dim.9 0.7257424 2.4191412 74.95301
## Dim.10 0.7119263 2.3730876 77.32609
## Dim.11 0.5930774 1.9769247 79.30302
## Dim.12 0.5663349 1.8877831 81.19080
## Dim.13 0.5352396 1.7841321 82.97493
## Dim.14 0.5094441 1.6981471 84.67308
## Dim.15 0.4828362 1.6094540 86.28254
## Dim.16 0.4212901 1.4043004 87.68684
## Dim.17 0.4185037 1.3950122 89.08185
## Dim.18 0.3643340 1.2144467 90.29629
## Dim.19 0.3520885 1.1736283 91.46992
## Dim.20 0.3344316 1.1147721 92.58470
## Dim.21 0.3128334 1.0427781 93.62747
## Dim.22 0.2990096 0.9966987 94.62417
## Dim.23 0.2702602 0.9008674 95.52504
## Dim.24 0.2463364 0.8211214 96.34616
## Dim.25 0.2242207 0.7474024 97.09356
## Dim.26 0.2166219 0.7220729 97.81564
## Dim.27 0.1874375 0.6247916 98.44043
## Dim.28 0.1714858 0.5716194 99.01205
## Dim.29 0.1592605 0.5308683 99.54292
## Dim.30 0.1371253 0.4570845 100.00000
Non graphical solution to screen test
ev<-eigen(cor(Darlington))
ap<-parallel(subject=nrow(Darlington),var=ncol(Darlington),rep=100,cent=.05)
nS<-nScree(x=ev$values,parallel=ap$eigen$qevpea)
plotnScree(nS)
fac<-factanal(Darlington,3,rotation="promax")
print(fac,digits = 2,cutoff=.3,sort=TRUE)
##
## Call:
## factanal(x = Darlington, factors = 3, rotation = "promax")
##
## Uniquenesses:
## EOCA1 EOCA2 EOCA3 EOPR1 EOPR2 EOPR3 EOPR4 EORT1 EORT2 EORT3
## 0.81 0.87 0.71 0.61 0.54 0.52 0.38 0.22 0.34 0.59
## EOAU1 EOAU2 EOAU3 EOAU4 EOIN1 EOIN2 EOIN3 EOIN4 EOIN5 TOITC1
## 0.70 0.61 0.74 0.65 0.45 0.43 0.37 0.46 0.31 0.37
## TOITC2 TOITC3 TOITC4 TOITC5 TOITC6 BPGR1 BPGR2 BPGR3 BPGR4 BPGR5
## 0.52 0.51 0.45 0.41 0.75 0.26 0.21 0.26 0.32 0.50
##
## Loadings:
## Factor1 Factor2 Factor3
## EOCA3 0.58
## EOPR1 0.58
## EOPR3 0.78
## EOPR4 0.89
## EOAU1 0.54
## EOIN1 0.56
## EOIN2 0.68
## EOIN3 0.81
## EOIN4 0.85
## EOIN5 1.00
## TOITC1 0.97
## TOITC2 0.70
## TOITC3 0.52
## TOITC4 0.69
## TOITC5 0.55
## BPGR1 0.99
## BPGR2 1.07
## BPGR3 0.79
## BPGR4 0.75
## EORT1 1.08
## EORT2 0.95
## EOCA1 0.37
## EOCA2 0.45
## EOPR2 0.48
## EORT3 0.35 0.34
## EOAU2 0.47
## EOAU3 0.42
## EOAU4 0.46
## TOITC6
## BPGR5 0.42
##
## Factor1 Factor2 Factor3
## SS loadings 9.06 3.76 3.27
## Proportion Var 0.30 0.13 0.11
## Cumulative Var 0.30 0.43 0.54
##
## Factor Correlations:
## Factor1 Factor2 Factor3
## Factor1 1.00 -0.66 0.70
## Factor2 -0.66 1.00 -0.65
## Factor3 0.70 -0.65 1.00
##
## Test of the hypothesis that 3 factors are sufficient.
## The chi square statistic is 1043.71 on 348 degrees of freedom.
## The p-value is 1.27e-70