needed_packages <- c("psych",  "REdaS", "Hmisc", "corrplot", "ggcorrplot", "factoextra",  "nFactors", "HDclassif","")                      
# Extract not installed packages
not_installed <- needed_packages[!(needed_packages %in% installed.packages()[ , "Package"])]    
# Install not installed packages
if(length(not_installed)) install.packages(not_installed, repos = "http://cran.us.r-project.org") 
## Installing package into 'C:/Users/dorot/OneDrive/Documents/R/win-library/4.0'
## (as 'lib' is unspecified)
## Warning: package '' is not available (for R version 4.0.2)
library(psych)
## Warning: package 'psych' was built under R version 4.0.3
library(REdaS)
## Warning: package 'REdaS' was built under R version 4.0.3
## Loading required package: grid
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.0.3
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
## 
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
## 
##     describe
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.0.3
## corrplot 0.84 loaded
library(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.0.3
library(factoextra)#Used for principal component analysis to get a different view of eigenvalues
## Warning: package 'factoextra' was built under R version 4.0.3
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(nFactors)
## Warning: package 'nFactors' was built under R version 4.0.3
## 
## Attaching package: 'nFactors'
## The following object is masked from 'package:lattice':
## 
##     parallel
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
## 
##     src, summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#load data
studentpIusepersonality <- read.csv('studentpIusepersonality.csv')
#### filtering some fields#####
sData <-select(studentpIusepersonality,E1,E2,E4,E5,E7,E8,E10,A1,A2,A3,A5,A6,A10,C1,C3,C4,C6,C8,C9,N1,N2,N4,N5,N6,N7,O3,O4,O7,O8,O9,O10)

##Step 1: Screen the correlation matrix

#create a correlation matrix (these are just some methods)
sMatrix<-cor(sData)
round(sMatrix, 2)
##        E1    E2    E4    E5    E7    E8   E10    A1    A2    A3    A5    A6
## E1   1.00  0.57  0.52  0.40 -0.10 -0.39 -0.10  0.22  0.36  0.16  0.38  0.29
## E2   0.57  1.00  0.65  0.28 -0.02 -0.53 -0.20  0.12  0.37  0.04  0.21  0.20
## E4   0.52  0.65  1.00  0.20 -0.11 -0.55 -0.22  0.13  0.35  0.09  0.24  0.22
## E5   0.40  0.28  0.20  1.00 -0.26 -0.07 -0.01  0.39  0.43  0.28  0.41  0.43
## E7  -0.10 -0.02 -0.11 -0.26  1.00  0.15  0.06 -0.08 -0.13 -0.10 -0.21 -0.08
## E8  -0.39 -0.53 -0.55 -0.07  0.15  1.00  0.26 -0.03 -0.13  0.05 -0.25 -0.05
## E10 -0.10 -0.20 -0.22 -0.01  0.06  0.26  1.00  0.02  0.01  0.05 -0.10  0.10
## A1   0.22  0.12  0.13  0.39 -0.08 -0.03  0.02  1.00  0.39  0.56  0.42  0.45
## A2   0.36  0.37  0.35  0.43 -0.13 -0.13  0.01  0.39  1.00  0.43  0.44  0.51
## A3   0.16  0.04  0.09  0.28 -0.10  0.05  0.05  0.56  0.43  1.00  0.30  0.44
## A5   0.38  0.21  0.24  0.41 -0.21 -0.25 -0.10  0.42  0.44  0.30  1.00  0.46
## A6   0.29  0.20  0.22  0.43 -0.08 -0.05  0.10  0.45  0.51  0.44  0.46  1.00
## A10 -0.03  0.09  0.12 -0.05  0.17  0.07 -0.01 -0.16 -0.08 -0.16 -0.15 -0.07
## C1   0.17  0.06  0.03  0.06 -0.01 -0.11  0.09 -0.02  0.00 -0.06  0.15  0.15
## C3   0.34  0.22  0.18  0.24  0.01 -0.12  0.06  0.24  0.20  0.13  0.17  0.36
## C4   0.14  0.17  0.11  0.18 -0.04 -0.07  0.08  0.04  0.18  0.03  0.14  0.29
## C6  -0.06 -0.06 -0.05  0.04  0.10  0.25 -0.04  0.13  0.12  0.10 -0.10 -0.10
## C8  -0.30 -0.13 -0.12 -0.07  0.00  0.17 -0.13 -0.04 -0.05  0.08 -0.13 -0.18
## C9  -0.07  0.00 -0.01  0.03  0.08  0.15  0.01 -0.01  0.02  0.07 -0.09 -0.15
## N1  -0.34 -0.30 -0.27 -0.07  0.13  0.37  0.00 -0.12 -0.21 -0.05 -0.25 -0.22
## N2  -0.16 -0.16 -0.20 -0.01  0.13  0.28  0.12  0.02 -0.05  0.08 -0.11 -0.03
## N4  -0.32 -0.33 -0.33 -0.05  0.13  0.43  0.17 -0.03 -0.08  0.01 -0.17  0.00
## N5  -0.21 -0.29 -0.28 -0.03  0.11  0.34  0.16  0.03 -0.08  0.02 -0.09  0.04
## N6  -0.20 -0.19 -0.23 -0.02  0.15  0.35  0.12  0.03 -0.04  0.11 -0.16  0.02
## N7  -0.29 -0.23 -0.23 -0.16  0.11  0.23  0.12 -0.12 -0.21 -0.06 -0.21 -0.18
## O3   0.08  0.11  0.09  0.25  0.03  0.07  0.06  0.20  0.21  0.14  0.11  0.24
## O4   0.11  0.11  0.07  0.09  0.17  0.10  0.06  0.12  0.14  0.13  0.09  0.14
## O7  -0.04 -0.01  0.02  0.08 -0.02  0.08  0.01  0.04  0.08  0.07  0.01  0.05
## O8  -0.11 -0.07 -0.03  0.11  0.00  0.13  0.02 -0.11  0.04 -0.01 -0.07 -0.06
## O9  -0.06 -0.02  0.02  0.08 -0.07  0.08  0.07  0.00  0.06  0.09 -0.04  0.01
## O10 -0.13 -0.09 -0.04  0.12 -0.03  0.19  0.04 -0.01 -0.03  0.01 -0.09  0.01
##       A10    C1    C3    C4    C6    C8    C9    N1    N2    N4    N5    N6
## E1  -0.03  0.17  0.34  0.14 -0.06 -0.30 -0.07 -0.34 -0.16 -0.32 -0.21 -0.20
## E2   0.09  0.06  0.22  0.17 -0.06 -0.13  0.00 -0.30 -0.16 -0.33 -0.29 -0.19
## E4   0.12  0.03  0.18  0.11 -0.05 -0.12 -0.01 -0.27 -0.20 -0.33 -0.28 -0.23
## E5  -0.05  0.06  0.24  0.18  0.04 -0.07  0.03 -0.07 -0.01 -0.05 -0.03 -0.02
## E7   0.17 -0.01  0.01 -0.04  0.10  0.00  0.08  0.13  0.13  0.13  0.11  0.15
## E8   0.07 -0.11 -0.12 -0.07  0.25  0.17  0.15  0.37  0.28  0.43  0.34  0.35
## E10 -0.01  0.09  0.06  0.08 -0.04 -0.13  0.01  0.00  0.12  0.17  0.16  0.12
## A1  -0.16 -0.02  0.24  0.04  0.13 -0.04 -0.01 -0.12  0.02 -0.03  0.03  0.03
## A2  -0.08  0.00  0.20  0.18  0.12 -0.05  0.02 -0.21 -0.05 -0.08 -0.08 -0.04
## A3  -0.16 -0.06  0.13  0.03  0.10  0.08  0.07 -0.05  0.08  0.01  0.02  0.11
## A5  -0.15  0.15  0.17  0.14 -0.10 -0.13 -0.09 -0.25 -0.11 -0.17 -0.09 -0.16
## A6  -0.07  0.15  0.36  0.29 -0.10 -0.18 -0.15 -0.22 -0.03  0.00  0.04  0.02
## A10  1.00 -0.01 -0.02  0.05  0.05  0.06  0.14  0.11  0.09  0.07  0.08  0.01
## C1  -0.01  1.00  0.22  0.24 -0.33 -0.30 -0.28 -0.15 -0.09 -0.10  0.02 -0.04
## C3  -0.02  0.22  1.00  0.34 -0.14 -0.44 -0.30 -0.18  0.05  0.04  0.04  0.10
## C4   0.05  0.24  0.34  1.00 -0.30 -0.38 -0.34 -0.12  0.02  0.04  0.10  0.17
## C6   0.05 -0.33 -0.14 -0.30  1.00  0.37  0.48  0.29  0.23  0.20  0.09  0.08
## C8   0.06 -0.30 -0.44 -0.38  0.37  1.00  0.51  0.27  0.12  0.08  0.04  0.01
## C9   0.14 -0.28 -0.30 -0.34  0.48  0.51  1.00  0.26  0.18  0.09  0.11 -0.04
## N1   0.11 -0.15 -0.18 -0.12  0.29  0.27  0.26  1.00  0.41  0.53  0.35  0.40
## N2   0.09 -0.09  0.05  0.02  0.23  0.12  0.18  0.41  1.00  0.39  0.36  0.42
## N4   0.07 -0.10  0.04  0.04  0.20  0.08  0.09  0.53  0.39  1.00  0.36  0.57
## N5   0.08  0.02  0.04  0.10  0.09  0.04  0.11  0.35  0.36  0.36  1.00  0.40
## N6   0.01 -0.04  0.10  0.17  0.08  0.01 -0.04  0.40  0.42  0.57  0.40  1.00
## N7   0.06 -0.08 -0.09 -0.07  0.08  0.09  0.06  0.43  0.39  0.35  0.27  0.37
## O3  -0.03  0.11  0.17  0.07  0.03 -0.13 -0.05  0.07  0.11  0.14  0.07  0.14
## O4   0.07  0.02  0.15  0.00  0.04 -0.05  0.05  0.09  0.29  0.16  0.12  0.26
## O7   0.10  0.00  0.07  0.21  0.07  0.09  0.08 -0.01  0.06  0.02  0.13  0.05
## O8   0.15 -0.10 -0.08  0.08  0.18  0.13  0.22  0.16  0.10  0.10  0.11  0.03
## O9   0.12 -0.12 -0.06  0.08  0.20  0.10  0.19  0.08  0.03  0.07  0.06  0.00
## O10  0.20 -0.05 -0.15 -0.01  0.13  0.14  0.17  0.14  0.07  0.13  0.09  0.05
##        N7    O3    O4    O7    O8    O9   O10
## E1  -0.29  0.08  0.11 -0.04 -0.11 -0.06 -0.13
## E2  -0.23  0.11  0.11 -0.01 -0.07 -0.02 -0.09
## E4  -0.23  0.09  0.07  0.02 -0.03  0.02 -0.04
## E5  -0.16  0.25  0.09  0.08  0.11  0.08  0.12
## E7   0.11  0.03  0.17 -0.02  0.00 -0.07 -0.03
## E8   0.23  0.07  0.10  0.08  0.13  0.08  0.19
## E10  0.12  0.06  0.06  0.01  0.02  0.07  0.04
## A1  -0.12  0.20  0.12  0.04 -0.11  0.00 -0.01
## A2  -0.21  0.21  0.14  0.08  0.04  0.06 -0.03
## A3  -0.06  0.14  0.13  0.07 -0.01  0.09  0.01
## A5  -0.21  0.11  0.09  0.01 -0.07 -0.04 -0.09
## A6  -0.18  0.24  0.14  0.05 -0.06  0.01  0.01
## A10  0.06 -0.03  0.07  0.10  0.15  0.12  0.20
## C1  -0.08  0.11  0.02  0.00 -0.10 -0.12 -0.05
## C3  -0.09  0.17  0.15  0.07 -0.08 -0.06 -0.15
## C4  -0.07  0.07  0.00  0.21  0.08  0.08 -0.01
## C6   0.08  0.03  0.04  0.07  0.18  0.20  0.13
## C8   0.09 -0.13 -0.05  0.09  0.13  0.10  0.14
## C9   0.06 -0.05  0.05  0.08  0.22  0.19  0.17
## N1   0.43  0.07  0.09 -0.01  0.16  0.08  0.14
## N2   0.39  0.11  0.29  0.06  0.10  0.03  0.07
## N4   0.35  0.14  0.16  0.02  0.10  0.07  0.13
## N5   0.27  0.07  0.12  0.13  0.11  0.06  0.09
## N6   0.37  0.14  0.26  0.05  0.03  0.00  0.05
## N7   1.00  0.13  0.10 -0.07  0.03 -0.01  0.01
## O3   0.13  1.00  0.34 -0.35 -0.24 -0.20 -0.06
## O4   0.10  0.34  1.00 -0.22 -0.21 -0.22 -0.13
## O7  -0.07 -0.35 -0.22  1.00  0.47  0.40  0.29
## O8   0.03 -0.24 -0.21  0.47  1.00  0.60  0.47
## O9  -0.01 -0.20 -0.22  0.40  0.60  1.00  0.42
## O10  0.01 -0.06 -0.13  0.29  0.47  0.42  1.00
Hmisc::rcorr(as.matrix(sData)) 
##        E1    E2    E4    E5    E7    E8   E10    A1    A2    A3    A5    A6
## E1   1.00  0.57  0.52  0.40 -0.10 -0.39 -0.10  0.22  0.36  0.16  0.38  0.29
## E2   0.57  1.00  0.65  0.28 -0.02 -0.53 -0.20  0.12  0.37  0.04  0.21  0.20
## E4   0.52  0.65  1.00  0.20 -0.11 -0.55 -0.22  0.13  0.35  0.09  0.24  0.22
## E5   0.40  0.28  0.20  1.00 -0.26 -0.07 -0.01  0.39  0.43  0.28  0.41  0.43
## E7  -0.10 -0.02 -0.11 -0.26  1.00  0.15  0.06 -0.08 -0.13 -0.10 -0.21 -0.08
## E8  -0.39 -0.53 -0.55 -0.07  0.15  1.00  0.26 -0.03 -0.13  0.05 -0.25 -0.05
## E10 -0.10 -0.20 -0.22 -0.01  0.06  0.26  1.00  0.02  0.01  0.05 -0.10  0.10
## A1   0.22  0.12  0.13  0.39 -0.08 -0.03  0.02  1.00  0.39  0.56  0.42  0.45
## A2   0.36  0.37  0.35  0.43 -0.13 -0.13  0.01  0.39  1.00  0.43  0.44  0.51
## A3   0.16  0.04  0.09  0.28 -0.10  0.05  0.05  0.56  0.43  1.00  0.30  0.44
## A5   0.38  0.21  0.24  0.41 -0.21 -0.25 -0.10  0.42  0.44  0.30  1.00  0.46
## A6   0.29  0.20  0.22  0.43 -0.08 -0.05  0.10  0.45  0.51  0.44  0.46  1.00
## A10 -0.03  0.09  0.12 -0.05  0.17  0.07 -0.01 -0.16 -0.08 -0.16 -0.15 -0.07
## C1   0.17  0.06  0.03  0.06 -0.01 -0.11  0.09 -0.02  0.00 -0.06  0.15  0.15
## C3   0.34  0.22  0.18  0.24  0.01 -0.12  0.06  0.24  0.20  0.13  0.17  0.36
## C4   0.14  0.17  0.11  0.18 -0.04 -0.07  0.08  0.04  0.18  0.03  0.14  0.29
## C6  -0.06 -0.06 -0.05  0.04  0.10  0.25 -0.04  0.13  0.12  0.10 -0.10 -0.10
## C8  -0.30 -0.13 -0.12 -0.07  0.00  0.17 -0.13 -0.04 -0.05  0.08 -0.13 -0.18
## C9  -0.07  0.00 -0.01  0.03  0.08  0.15  0.01 -0.01  0.02  0.07 -0.09 -0.15
## N1  -0.34 -0.30 -0.27 -0.07  0.13  0.37  0.00 -0.12 -0.21 -0.05 -0.25 -0.22
## N2  -0.16 -0.16 -0.20 -0.01  0.13  0.28  0.12  0.02 -0.05  0.08 -0.11 -0.03
## N4  -0.32 -0.33 -0.33 -0.05  0.13  0.43  0.17 -0.03 -0.08  0.01 -0.17  0.00
## N5  -0.21 -0.29 -0.28 -0.03  0.11  0.34  0.16  0.03 -0.08  0.02 -0.09  0.04
## N6  -0.20 -0.19 -0.23 -0.02  0.15  0.35  0.12  0.03 -0.04  0.11 -0.16  0.02
## N7  -0.29 -0.23 -0.23 -0.16  0.11  0.23  0.12 -0.12 -0.21 -0.06 -0.21 -0.18
## O3   0.08  0.11  0.09  0.25  0.03  0.07  0.06  0.20  0.21  0.14  0.11  0.24
## O4   0.11  0.11  0.07  0.09  0.17  0.10  0.06  0.12  0.14  0.13  0.09  0.14
## O7  -0.04 -0.01  0.02  0.08 -0.02  0.08  0.01  0.04  0.08  0.07  0.01  0.05
## O8  -0.11 -0.07 -0.03  0.11  0.00  0.13  0.02 -0.11  0.04 -0.01 -0.07 -0.06
## O9  -0.06 -0.02  0.02  0.08 -0.07  0.08  0.07  0.00  0.06  0.09 -0.04  0.01
## O10 -0.13 -0.09 -0.04  0.12 -0.03  0.19  0.04 -0.01 -0.03  0.01 -0.09  0.01
##       A10    C1    C3    C4    C6    C8    C9    N1    N2    N4    N5    N6
## E1  -0.03  0.17  0.34  0.14 -0.06 -0.30 -0.07 -0.34 -0.16 -0.32 -0.21 -0.20
## E2   0.09  0.06  0.22  0.17 -0.06 -0.13  0.00 -0.30 -0.16 -0.33 -0.29 -0.19
## E4   0.12  0.03  0.18  0.11 -0.05 -0.12 -0.01 -0.27 -0.20 -0.33 -0.28 -0.23
## E5  -0.05  0.06  0.24  0.18  0.04 -0.07  0.03 -0.07 -0.01 -0.05 -0.03 -0.02
## E7   0.17 -0.01  0.01 -0.04  0.10  0.00  0.08  0.13  0.13  0.13  0.11  0.15
## E8   0.07 -0.11 -0.12 -0.07  0.25  0.17  0.15  0.37  0.28  0.43  0.34  0.35
## E10 -0.01  0.09  0.06  0.08 -0.04 -0.13  0.01  0.00  0.12  0.17  0.16  0.12
## A1  -0.16 -0.02  0.24  0.04  0.13 -0.04 -0.01 -0.12  0.02 -0.03  0.03  0.03
## A2  -0.08  0.00  0.20  0.18  0.12 -0.05  0.02 -0.21 -0.05 -0.08 -0.08 -0.04
## A3  -0.16 -0.06  0.13  0.03  0.10  0.08  0.07 -0.05  0.08  0.01  0.02  0.11
## A5  -0.15  0.15  0.17  0.14 -0.10 -0.13 -0.09 -0.25 -0.11 -0.17 -0.09 -0.16
## A6  -0.07  0.15  0.36  0.29 -0.10 -0.18 -0.15 -0.22 -0.03  0.00  0.04  0.02
## A10  1.00 -0.01 -0.02  0.05  0.05  0.06  0.14  0.11  0.09  0.07  0.08  0.01
## C1  -0.01  1.00  0.22  0.24 -0.33 -0.30 -0.28 -0.15 -0.09 -0.10  0.02 -0.04
## C3  -0.02  0.22  1.00  0.34 -0.14 -0.44 -0.30 -0.18  0.05  0.04  0.04  0.10
## C4   0.05  0.24  0.34  1.00 -0.30 -0.38 -0.34 -0.12  0.02  0.04  0.10  0.17
## C6   0.05 -0.33 -0.14 -0.30  1.00  0.37  0.48  0.29  0.23  0.20  0.09  0.08
## C8   0.06 -0.30 -0.44 -0.38  0.37  1.00  0.51  0.27  0.12  0.08  0.04  0.01
## C9   0.14 -0.28 -0.30 -0.34  0.48  0.51  1.00  0.26  0.18  0.09  0.11 -0.04
## N1   0.11 -0.15 -0.18 -0.12  0.29  0.27  0.26  1.00  0.41  0.53  0.35  0.40
## N2   0.09 -0.09  0.05  0.02  0.23  0.12  0.18  0.41  1.00  0.39  0.36  0.42
## N4   0.07 -0.10  0.04  0.04  0.20  0.08  0.09  0.53  0.39  1.00  0.36  0.57
## N5   0.08  0.02  0.04  0.10  0.09  0.04  0.11  0.35  0.36  0.36  1.00  0.40
## N6   0.01 -0.04  0.10  0.17  0.08  0.01 -0.04  0.40  0.42  0.57  0.40  1.00
## N7   0.06 -0.08 -0.09 -0.07  0.08  0.09  0.06  0.43  0.39  0.35  0.27  0.37
## O3  -0.03  0.11  0.17  0.07  0.03 -0.13 -0.05  0.07  0.11  0.14  0.07  0.14
## O4   0.07  0.02  0.15  0.00  0.04 -0.05  0.05  0.09  0.29  0.16  0.12  0.26
## O7   0.10  0.00  0.07  0.21  0.07  0.09  0.08 -0.01  0.06  0.02  0.13  0.05
## O8   0.15 -0.10 -0.08  0.08  0.18  0.13  0.22  0.16  0.10  0.10  0.11  0.03
## O9   0.12 -0.12 -0.06  0.08  0.20  0.10  0.19  0.08  0.03  0.07  0.06  0.00
## O10  0.20 -0.05 -0.15 -0.01  0.13  0.14  0.17  0.14  0.07  0.13  0.09  0.05
##        N7    O3    O4    O7    O8    O9   O10
## E1  -0.29  0.08  0.11 -0.04 -0.11 -0.06 -0.13
## E2  -0.23  0.11  0.11 -0.01 -0.07 -0.02 -0.09
## E4  -0.23  0.09  0.07  0.02 -0.03  0.02 -0.04
## E5  -0.16  0.25  0.09  0.08  0.11  0.08  0.12
## E7   0.11  0.03  0.17 -0.02  0.00 -0.07 -0.03
## E8   0.23  0.07  0.10  0.08  0.13  0.08  0.19
## E10  0.12  0.06  0.06  0.01  0.02  0.07  0.04
## A1  -0.12  0.20  0.12  0.04 -0.11  0.00 -0.01
## A2  -0.21  0.21  0.14  0.08  0.04  0.06 -0.03
## A3  -0.06  0.14  0.13  0.07 -0.01  0.09  0.01
## A5  -0.21  0.11  0.09  0.01 -0.07 -0.04 -0.09
## A6  -0.18  0.24  0.14  0.05 -0.06  0.01  0.01
## A10  0.06 -0.03  0.07  0.10  0.15  0.12  0.20
## C1  -0.08  0.11  0.02  0.00 -0.10 -0.12 -0.05
## C3  -0.09  0.17  0.15  0.07 -0.08 -0.06 -0.15
## C4  -0.07  0.07  0.00  0.21  0.08  0.08 -0.01
## C6   0.08  0.03  0.04  0.07  0.18  0.20  0.13
## C8   0.09 -0.13 -0.05  0.09  0.13  0.10  0.14
## C9   0.06 -0.05  0.05  0.08  0.22  0.19  0.17
## N1   0.43  0.07  0.09 -0.01  0.16  0.08  0.14
## N2   0.39  0.11  0.29  0.06  0.10  0.03  0.07
## N4   0.35  0.14  0.16  0.02  0.10  0.07  0.13
## N5   0.27  0.07  0.12  0.13  0.11  0.06  0.09
## N6   0.37  0.14  0.26  0.05  0.03  0.00  0.05
## N7   1.00  0.13  0.10 -0.07  0.03 -0.01  0.01
## O3   0.13  1.00  0.34 -0.35 -0.24 -0.20 -0.06
## O4   0.10  0.34  1.00 -0.22 -0.21 -0.22 -0.13
## O7  -0.07 -0.35 -0.22  1.00  0.47  0.40  0.29
## O8   0.03 -0.24 -0.21  0.47  1.00  0.60  0.47
## O9  -0.01 -0.20 -0.22  0.40  0.60  1.00  0.42
## O10  0.01 -0.06 -0.13  0.29  0.47  0.42  1.00
## 
## n= 382 
## 
## 
## P
##     E1     E2     E4     E5     E7     E8     E10    A1     A2     A3    
## E1         0.0000 0.0000 0.0000 0.0624 0.0000 0.0606 0.0000 0.0000 0.0023
## E2  0.0000        0.0000 0.0000 0.6479 0.0000 0.0000 0.0231 0.0000 0.4290
## E4  0.0000 0.0000        0.0001 0.0274 0.0000 0.0000 0.0136 0.0000 0.0959
## E5  0.0000 0.0000 0.0001        0.0000 0.1619 0.8689 0.0000 0.0000 0.0000
## E7  0.0624 0.6479 0.0274 0.0000        0.0028 0.2656 0.1106 0.0102 0.0429
## E8  0.0000 0.0000 0.0000 0.1619 0.0028        0.0000 0.5017 0.0127 0.3520
## E10 0.0606 0.0000 0.0000 0.8689 0.2656 0.0000        0.6691 0.8495 0.3647
## A1  0.0000 0.0231 0.0136 0.0000 0.1106 0.5017 0.6691        0.0000 0.0000
## A2  0.0000 0.0000 0.0000 0.0000 0.0102 0.0127 0.8495 0.0000        0.0000
## A3  0.0023 0.4290 0.0959 0.0000 0.0429 0.3520 0.3647 0.0000 0.0000       
## A5  0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0541 0.0000 0.0000 0.0000
## A6  0.0000 0.0000 0.0000 0.0000 0.1330 0.2889 0.0491 0.0000 0.0000 0.0000
## A10 0.5838 0.0916 0.0222 0.2862 0.0006 0.1577 0.8995 0.0023 0.1215 0.0014
## C1  0.0009 0.2490 0.5325 0.2186 0.8055 0.0290 0.0810 0.6336 0.9646 0.2327
## C3  0.0000 0.0000 0.0005 0.0000 0.8623 0.0218 0.2242 0.0000 0.0000 0.0099
## C4  0.0062 0.0008 0.0352 0.0003 0.4516 0.1518 0.1207 0.4567 0.0004 0.6205
## C6  0.2594 0.2446 0.3766 0.3898 0.0451 0.0000 0.4607 0.0137 0.0212 0.0433
## C8  0.0000 0.0084 0.0173 0.1955 0.9365 0.0006 0.0116 0.4398 0.3207 0.1009
## C9  0.1596 0.9555 0.7914 0.5228 0.1337 0.0024 0.8642 0.9177 0.6967 0.1729
## N1  0.0000 0.0000 0.0000 0.1799 0.0099 0.0000 0.9301 0.0226 0.0000 0.3761
## N2  0.0013 0.0023 0.0000 0.8214 0.0084 0.0000 0.0226 0.7687 0.3225 0.1077
## N4  0.0000 0.0000 0.0000 0.3343 0.0094 0.0000 0.0009 0.5109 0.1032 0.8253
## N5  0.0000 0.0000 0.0000 0.5209 0.0304 0.0000 0.0021 0.5169 0.1039 0.7176
## N6  0.0001 0.0002 0.0000 0.6739 0.0034 0.0000 0.0169 0.6108 0.4078 0.0264
## N7  0.0000 0.0000 0.0000 0.0018 0.0321 0.0000 0.0147 0.0160 0.0000 0.2296
## O3  0.1023 0.0259 0.0794 0.0000 0.6129 0.1853 0.2632 0.0000 0.0000 0.0050
## O4  0.0271 0.0293 0.2045 0.0770 0.0010 0.0581 0.2124 0.0159 0.0064 0.0134
## O7  0.4783 0.7911 0.7669 0.1138 0.7446 0.1170 0.8659 0.4925 0.1228 0.1835
## O8  0.0293 0.1947 0.5721 0.0294 0.9588 0.0136 0.6887 0.0338 0.3911 0.8716
## O9  0.2474 0.7180 0.7038 0.1173 0.1452 0.1159 0.1546 0.9410 0.2090 0.0770
## O10 0.0110 0.0954 0.4578 0.0213 0.5176 0.0001 0.4204 0.9156 0.5071 0.8137
##     A5     A6     A10    C1     C3     C4     C6     C8     C9     N1    
## E1  0.0000 0.0000 0.5838 0.0009 0.0000 0.0062 0.2594 0.0000 0.1596 0.0000
## E2  0.0000 0.0000 0.0916 0.2490 0.0000 0.0008 0.2446 0.0084 0.9555 0.0000
## E4  0.0000 0.0000 0.0222 0.5325 0.0005 0.0352 0.3766 0.0173 0.7914 0.0000
## E5  0.0000 0.0000 0.2862 0.2186 0.0000 0.0003 0.3898 0.1955 0.5228 0.1799
## E7  0.0000 0.1330 0.0006 0.8055 0.8623 0.4516 0.0451 0.9365 0.1337 0.0099
## E8  0.0000 0.2889 0.1577 0.0290 0.0218 0.1518 0.0000 0.0006 0.0024 0.0000
## E10 0.0541 0.0491 0.8995 0.0810 0.2242 0.1207 0.4607 0.0116 0.8642 0.9301
## A1  0.0000 0.0000 0.0023 0.6336 0.0000 0.4567 0.0137 0.4398 0.9177 0.0226
## A2  0.0000 0.0000 0.1215 0.9646 0.0000 0.0004 0.0212 0.3207 0.6967 0.0000
## A3  0.0000 0.0000 0.0014 0.2327 0.0099 0.6205 0.0433 0.1009 0.1729 0.3761
## A5         0.0000 0.0030 0.0030 0.0012 0.0082 0.0480 0.0094 0.0730 0.0000
## A6  0.0000        0.1764 0.0028 0.0000 0.0000 0.0552 0.0003 0.0038 0.0000
## A10 0.0030 0.1764        0.8723 0.7487 0.3573 0.3780 0.2291 0.0073 0.0380
## C1  0.0030 0.0028 0.8723        0.0000 0.0000 0.0000 0.0000 0.0000 0.0024
## C3  0.0012 0.0000 0.7487 0.0000        0.0000 0.0078 0.0000 0.0000 0.0006
## C4  0.0082 0.0000 0.3573 0.0000 0.0000        0.0000 0.0000 0.0000 0.0183
## C6  0.0480 0.0552 0.3780 0.0000 0.0078 0.0000        0.0000 0.0000 0.0000
## C8  0.0094 0.0003 0.2291 0.0000 0.0000 0.0000 0.0000        0.0000 0.0000
## C9  0.0730 0.0038 0.0073 0.0000 0.0000 0.0000 0.0000 0.0000        0.0000
## N1  0.0000 0.0000 0.0380 0.0024 0.0006 0.0183 0.0000 0.0000 0.0000       
## N2  0.0266 0.5945 0.0653 0.0848 0.3096 0.6396 0.0000 0.0216 0.0006 0.0000
## N4  0.0009 0.9486 0.1439 0.0587 0.4392 0.4524 0.0000 0.1303 0.0671 0.0000
## N5  0.0724 0.4246 0.1294 0.6848 0.3978 0.0542 0.0843 0.4115 0.0381 0.0000
## N6  0.0013 0.6638 0.8674 0.4567 0.0561 0.0010 0.1391 0.8157 0.3863 0.0000
## N7  0.0000 0.0003 0.2812 0.1074 0.0736 0.1525 0.1195 0.0930 0.2264 0.0000
## O3  0.0341 0.0000 0.5889 0.0248 0.0008 0.1844 0.5390 0.0127 0.2845 0.1593
## O4  0.0664 0.0049 0.1692 0.6493 0.0026 0.9674 0.4450 0.3391 0.2915 0.0716
## O7  0.8227 0.2837 0.0403 0.9371 0.2026 0.0000 0.1715 0.0955 0.1272 0.7761
## O8  0.1695 0.2483 0.0039 0.0404 0.0977 0.1107 0.0004 0.0143 0.0000 0.0023
## O9  0.3861 0.7737 0.0166 0.0233 0.2717 0.1308 0.0000 0.0574 0.0001 0.1124
## O10 0.0759 0.8476 0.0001 0.3447 0.0031 0.8437 0.0086 0.0059 0.0007 0.0068
##     N2     N4     N5     N6     N7     O3     O4     O7     O8     O9    
## E1  0.0013 0.0000 0.0000 0.0001 0.0000 0.1023 0.0271 0.4783 0.0293 0.2474
## E2  0.0023 0.0000 0.0000 0.0002 0.0000 0.0259 0.0293 0.7911 0.1947 0.7180
## E4  0.0000 0.0000 0.0000 0.0000 0.0000 0.0794 0.2045 0.7669 0.5721 0.7038
## E5  0.8214 0.3343 0.5209 0.6739 0.0018 0.0000 0.0770 0.1138 0.0294 0.1173
## E7  0.0084 0.0094 0.0304 0.0034 0.0321 0.6129 0.0010 0.7446 0.9588 0.1452
## E8  0.0000 0.0000 0.0000 0.0000 0.0000 0.1853 0.0581 0.1170 0.0136 0.1159
## E10 0.0226 0.0009 0.0021 0.0169 0.0147 0.2632 0.2124 0.8659 0.6887 0.1546
## A1  0.7687 0.5109 0.5169 0.6108 0.0160 0.0000 0.0159 0.4925 0.0338 0.9410
## A2  0.3225 0.1032 0.1039 0.4078 0.0000 0.0000 0.0064 0.1228 0.3911 0.2090
## A3  0.1077 0.8253 0.7176 0.0264 0.2296 0.0050 0.0134 0.1835 0.8716 0.0770
## A5  0.0266 0.0009 0.0724 0.0013 0.0000 0.0341 0.0664 0.8227 0.1695 0.3861
## A6  0.5945 0.9486 0.4246 0.6638 0.0003 0.0000 0.0049 0.2837 0.2483 0.7737
## A10 0.0653 0.1439 0.1294 0.8674 0.2812 0.5889 0.1692 0.0403 0.0039 0.0166
## C1  0.0848 0.0587 0.6848 0.4567 0.1074 0.0248 0.6493 0.9371 0.0404 0.0233
## C3  0.3096 0.4392 0.3978 0.0561 0.0736 0.0008 0.0026 0.2026 0.0977 0.2717
## C4  0.6396 0.4524 0.0542 0.0010 0.1525 0.1844 0.9674 0.0000 0.1107 0.1308
## C6  0.0000 0.0000 0.0843 0.1391 0.1195 0.5390 0.4450 0.1715 0.0004 0.0000
## C8  0.0216 0.1303 0.4115 0.8157 0.0930 0.0127 0.3391 0.0955 0.0143 0.0574
## C9  0.0006 0.0671 0.0381 0.3863 0.2264 0.2845 0.2915 0.1272 0.0000 0.0001
## N1  0.0000 0.0000 0.0000 0.0000 0.0000 0.1593 0.0716 0.7761 0.0023 0.1124
## N2         0.0000 0.0000 0.0000 0.0000 0.0294 0.0000 0.2151 0.0616 0.5226
## N4  0.0000        0.0000 0.0000 0.0000 0.0074 0.0015 0.7454 0.0415 0.1623
## N5  0.0000 0.0000        0.0000 0.0000 0.1922 0.0157 0.0133 0.0333 0.2436
## N6  0.0000 0.0000 0.0000        0.0000 0.0045 0.0000 0.3436 0.5737 0.9381
## N7  0.0000 0.0000 0.0000 0.0000        0.0142 0.0556 0.1840 0.5635 0.7748
## O3  0.0294 0.0074 0.1922 0.0045 0.0142        0.0000 0.0000 0.0000 0.0000
## O4  0.0000 0.0015 0.0157 0.0000 0.0556 0.0000        0.0000 0.0000 0.0000
## O7  0.2151 0.7454 0.0133 0.3436 0.1840 0.0000 0.0000        0.0000 0.0000
## O8  0.0616 0.0415 0.0333 0.5737 0.5635 0.0000 0.0000 0.0000        0.0000
## O9  0.5226 0.1623 0.2436 0.9381 0.7748 0.0000 0.0000 0.0000 0.0000       
## O10 0.1892 0.0120 0.0769 0.3345 0.7842 0.2722 0.0097 0.0000 0.0000 0.0000
##     O10   
## E1  0.0110
## E2  0.0954
## E4  0.4578
## E5  0.0213
## E7  0.5176
## E8  0.0001
## E10 0.4204
## A1  0.9156
## A2  0.5071
## A3  0.8137
## A5  0.0759
## A6  0.8476
## A10 0.0001
## C1  0.3447
## C3  0.0031
## C4  0.8437
## C6  0.0086
## C8  0.0059
## C9  0.0007
## N1  0.0068
## N2  0.1892
## N4  0.0120
## N5  0.0769
## N6  0.3345
## N7  0.7842
## O3  0.2722
## O4  0.0097
## O7  0.0000
## O8  0.0000
## O9  0.0000
## O10

###Using ggcorrplot

#Using ggcorrplot. Note these are examples you need to choose a style for yourself, you do not need to create multiple correlation matrices
p.mat <- ggcorrplot::cor_pmat(sData)
ggcorrplot::ggcorrplot(sMatrix, title = "Correlation matrix for s data")

#Showing Xs for non-significant correlations
ggcorrplot::ggcorrplot(sMatrix, title = "Correlation matrix for s data", p.mat = p.mat, sig.level = .05)

#Showing lower diagonal
ggcorrplot::ggcorrplot(sMatrix, title = "Correlation matrix for s data", p.mat = p.mat, sig.level = .05, type="lower")

#Overlay plot with a white grid to space things out.
#t1.cex is the text size, pch is controlling what is shown for non-significant correlations
ggcorrplot(sMatrix, sig.level=0.05, lab_size = 1.5, p.mat = NULL,
           insig = c("pch", "blank"), pch = 1, pch.col = "black", pch.cex =1,
           tl.cex = 1) +
  theme(axis.text.x = element_text(margin=margin(-2,0,0,0)),
        axis.text.y = element_text(margin=margin(0,-2,0,0)),
        panel.grid.minor = element_line(size=5)) + 
  geom_tile(fill="white") +
  geom_tile(height=0.8, width=0.8)

#Showing the co-coefficients (this will be messy given the number of variables)
ggcorrplot::ggcorrplot(sMatrix, lab=TRUE, title = "Correlation matrix for s data",  type="lower")

###Using corrplot

#Visualization of correlations using circles
#corrplot parameters method = c("circle", "square", "ellipse", "number", "shade",
#"color", "pie")
#type = c("full", "lower", "upper"),
corrplot::corrplot(sMatrix, method="circle")

corrplot::corrplot(sMatrix, method="circle", type="upper")

#Visualization using numbers
corrplot::corrplot(sMatrix, method="number")

#Visualization of significance levels at 0.05
res1 <- corrplot::cor.mtest(sMatrix, conf.level = .95)
corrplot::corrplot(sMatrix, p.mat = res1$p, type="lower", sig.level = .05)

#Showing p-value for non-significant results
corrplot(sMatrix, p.mat = res1$p, type="lower",insig = "p-value")

##Step 2: Check if data is suitable - look at the relevant Statistics ###Bartlett’s test

psych::cortest.bartlett(sData)
## R was not square, finding R from data
## $chisq
## [1] 4005.796
## 
## $p.value
## [1] 0
## 
## $df
## [1] 465
psych::cortest.bartlett(sMatrix, n=nrow(sData))
## $chisq
## [1] 4005.796
## 
## $p.value
## [1] 0
## 
## $df
## [1] 465

###KMO

#KMO (execute one of these):
REdaS::KMOS(sData)
## 
## Kaiser-Meyer-Olkin Statistics
## 
## Call: REdaS::KMOS(x = sData)
## 
## Measures of Sampling Adequacy (MSA):
##        E1        E2        E4        E5        E7        E8       E10        A1 
## 0.8641884 0.8407491 0.8385573 0.7917548 0.6765679 0.8673551 0.7046220 0.8019284 
##        A2        A3        A5        A6       A10        C1        C3        C4 
## 0.8648503 0.7601020 0.8576180 0.8622363 0.7057069 0.8319078 0.8381345 0.8067884 
##        C6        C8        C9        N1        N2        N4        N5        N6 
## 0.7859700 0.8037283 0.7973788 0.8830593 0.8695670 0.8603581 0.8870846 0.8212266 
##        N7        O3        O4        O7        O8        O9       O10 
## 0.8863330 0.7351661 0.7821279 0.7408812 0.7561814 0.7837176 0.7913902 
## 
## KMO-Criterion: 0.8243515
psych::KMO(sData)
## Kaiser-Meyer-Olkin factor adequacy
## Call: psych::KMO(r = sData)
## Overall MSA =  0.82
## MSA for each item = 
##   E1   E2   E4   E5   E7   E8  E10   A1   A2   A3   A5   A6  A10   C1   C3   C4 
## 0.86 0.84 0.84 0.79 0.68 0.87 0.70 0.80 0.86 0.76 0.86 0.86 0.71 0.83 0.84 0.81 
##   C6   C8   C9   N1   N2   N4   N5   N6   N7   O3   O4   O7   O8   O9  O10 
## 0.79 0.80 0.80 0.88 0.87 0.86 0.89 0.82 0.89 0.74 0.78 0.74 0.76 0.78 0.79

###Determinant

#Determinant (execute one of these):
det(sMatrix)
## [1] 1.976978e-05
det(cor(sData))
## [1] 1.976978e-05

##Step 3: Do the Dimension Reduction (PRINCIPAL COMPONENTS ANALYSIS)

#pcModel<-principal(dataframe/R-matrix, nfactors = number of factors, rotate = "method of rotation", scores = TRUE)

#On raw data using principal components analysis
#For PCA we know how many factors if is possible to find
#principal will work out our loadings of each variable onto each component, the proportion each component explained and the cumulative proportion of variance explained 
pc1 <-  principal(sData, nfactors = 31, rotate = "none")
pc1 <-  principal(sData, nfactors = length(sData), rotate = "none")
pc1#output all details of the PCA
## Principal Components Analysis
## Call: principal(r = sData, nfactors = length(sData), rotate = "none")
## Standardized loadings (pattern matrix) based upon correlation matrix
##       PC1   PC2   PC3   PC4   PC5   PC6   PC7   PC8   PC9  PC10  PC11  PC12
## E1  -0.70  0.11  0.08 -0.07  0.28  0.02 -0.03 -0.10  0.24 -0.20  0.04 -0.04
## E2  -0.64 -0.02  0.16 -0.13  0.53 -0.06 -0.03 -0.10  0.01  0.08 -0.01  0.12
## E4  -0.62 -0.04  0.23 -0.13  0.48 -0.12 -0.01 -0.07 -0.04  0.18  0.03 -0.02
## E5  -0.44  0.49  0.25 -0.01 -0.05 -0.13  0.34  0.01  0.09 -0.25 -0.13 -0.02
## E7   0.25  0.03 -0.17 -0.04  0.35  0.52 -0.37  0.11 -0.20 -0.07  0.35  0.24
## E8   0.62  0.34 -0.05  0.06 -0.24  0.28  0.09  0.02 -0.11 -0.18 -0.17  0.02
## E10  0.16  0.24 -0.16  0.23 -0.18  0.50  0.15 -0.43  0.38  0.30 -0.12  0.00
## A1  -0.37  0.54  0.12 -0.21 -0.32  0.06 -0.15  0.05 -0.10 -0.01  0.22 -0.29
## A2  -0.52  0.47  0.26 -0.13 -0.03  0.05 -0.05 -0.07 -0.06  0.13 -0.17  0.26
## A3  -0.25  0.55  0.20 -0.20 -0.34  0.03 -0.21  0.01 -0.12  0.27  0.17 -0.10
## A5  -0.57  0.30  0.10 -0.08 -0.23 -0.12  0.04  0.30  0.15  0.01  0.06  0.04
## A6  -0.50  0.56  0.02  0.09 -0.17  0.14  0.01  0.12 -0.12  0.11 -0.05  0.02
## A10  0.15 -0.01  0.15  0.13  0.55  0.31  0.17  0.32 -0.15  0.15 -0.24 -0.44
## C1  -0.27  0.01 -0.33  0.37  0.01  0.12  0.26  0.36  0.32 -0.09  0.33  0.20
## C3  -0.41  0.36 -0.27  0.29  0.17  0.04 -0.22 -0.18  0.02 -0.34  0.02 -0.28
## C4  -0.28  0.26 -0.17  0.60  0.14 -0.12 -0.07  0.03 -0.11  0.09 -0.26  0.21
## C6   0.32  0.24  0.43 -0.42  0.10  0.10 -0.11 -0.21  0.03 -0.35  0.02  0.01
## C8   0.41 -0.04  0.45 -0.46 -0.08 -0.05 -0.02  0.27  0.03  0.15 -0.12  0.13
## C9   0.33  0.09  0.51 -0.44  0.15  0.17  0.05  0.05  0.30 -0.03 -0.07  0.08
## N1   0.65  0.29 -0.01 -0.12  0.18 -0.29  0.10  0.05  0.00 -0.11  0.06  0.03
## N2   0.42  0.48 -0.09 -0.06  0.25 -0.14 -0.14  0.02  0.28  0.07  0.04 -0.11
## N4   0.55  0.49 -0.17  0.07  0.08 -0.14  0.02 -0.08 -0.16 -0.10 -0.10  0.08
## N5   0.42  0.43 -0.13  0.18  0.03 -0.04 -0.08  0.27  0.26 -0.06 -0.06 -0.06
## N6   0.41  0.53 -0.27  0.11  0.15 -0.23 -0.17 -0.04 -0.14  0.08 -0.05  0.14
## N7   0.50  0.21 -0.23 -0.04  0.17 -0.30  0.07 -0.15  0.15  0.33  0.29 -0.15
## O3  -0.15  0.43 -0.34 -0.28  0.13  0.05  0.48 -0.10 -0.22 -0.04  0.13  0.10
## O4  -0.03  0.41 -0.33 -0.32  0.32  0.19  0.02  0.11  0.06  0.09 -0.09  0.09
## O7   0.07  0.12  0.51  0.51  0.01 -0.02 -0.34  0.17  0.12 -0.01 -0.05  0.02
## O8   0.24  0.11  0.64  0.43  0.11 -0.04  0.06 -0.08  0.01 -0.03  0.13  0.14
## O9   0.15  0.13  0.64  0.39  0.04  0.01  0.05 -0.23 -0.03  0.07  0.15  0.02
## O10  0.24  0.14  0.50  0.30  0.05  0.08  0.40  0.07 -0.22  0.02  0.22 -0.08
##      PC13  PC14  PC15  PC16  PC17  PC18  PC19  PC20  PC21  PC22  PC23  PC24
## E1  -0.05  0.02  0.05 -0.18  0.16 -0.01  0.23 -0.12 -0.17  0.08  0.08 -0.03
## E2   0.05  0.11 -0.05 -0.01  0.14  0.00 -0.03 -0.01  0.01  0.05 -0.04  0.03
## E4   0.09  0.12 -0.04 -0.13 -0.08  0.13 -0.03  0.02  0.04 -0.15  0.07  0.08
## E5  -0.02 -0.07  0.04  0.09  0.37 -0.15  0.06  0.11 -0.01  0.01 -0.19  0.06
## E7   0.11 -0.21 -0.01  0.00  0.22 -0.08 -0.04  0.02 -0.03  0.00 -0.06  0.00
## E8  -0.06  0.02  0.07  0.11  0.05  0.08  0.27 -0.02 -0.13 -0.01  0.16  0.06
## E10  0.10  0.03  0.05 -0.12  0.13  0.01 -0.10 -0.03  0.12 -0.07 -0.08  0.04
## A1   0.06  0.05 -0.08 -0.02  0.12 -0.05 -0.01 -0.11  0.33 -0.03 -0.06  0.04
## A2   0.12 -0.08  0.07  0.07 -0.15  0.22  0.11 -0.04 -0.14 -0.16 -0.12 -0.08
## A3  -0.04  0.23  0.05  0.00 -0.07 -0.23  0.15 -0.06 -0.16 -0.09  0.08 -0.12
## A5  -0.02 -0.45  0.15 -0.12 -0.06  0.08 -0.05 -0.05  0.14  0.09  0.07 -0.09
## A6   0.12 -0.07  0.02 -0.04 -0.03  0.05 -0.23  0.12 -0.25  0.10  0.08  0.23
## A10  0.15 -0.06  0.18  0.02 -0.08 -0.05  0.12 -0.07  0.02  0.03 -0.11 -0.06
## C1   0.09  0.31  0.24  0.03 -0.17  0.00  0.05 -0.06  0.02  0.03 -0.04  0.04
## C3   0.01  0.11  0.07  0.08 -0.12 -0.03 -0.17  0.30 -0.08  0.03  0.06 -0.03
## C4   0.11 -0.02 -0.10  0.22  0.06 -0.21 -0.03 -0.23  0.14  0.08  0.25  0.06
## C6   0.14  0.03  0.05  0.11 -0.17  0.21  0.03 -0.22  0.12  0.11  0.02  0.17
## C8   0.06  0.21  0.06  0.11  0.08 -0.04 -0.13  0.18 -0.01  0.17 -0.12  0.13
## C9   0.09  0.05 -0.05 -0.05  0.01 -0.19 -0.08  0.09  0.02  0.06  0.30 -0.25
## N1   0.16 -0.01  0.13 -0.13  0.03 -0.21 -0.01 -0.05  0.00 -0.37  0.05  0.20
## N2  -0.24 -0.05  0.01  0.29 -0.03 -0.01 -0.27 -0.29 -0.17 -0.01 -0.13 -0.07
## N4   0.09  0.00  0.26 -0.29 -0.07  0.05 -0.19  0.05  0.08  0.02  0.01 -0.15
## N5   0.20 -0.01 -0.55 -0.20 -0.09  0.08  0.09  0.04 -0.07 -0.01 -0.07  0.02
## N6  -0.09  0.21  0.05 -0.21  0.12  0.05  0.13 -0.03  0.05  0.23 -0.14 -0.10
## N7   0.17 -0.18  0.10  0.18  0.12  0.16  0.19  0.17 -0.03  0.12  0.15  0.07
## O3   0.11  0.06 -0.21  0.26 -0.11  0.01  0.00  0.09  0.12 -0.01 -0.03 -0.19
## O4  -0.55 -0.05 -0.03 -0.05 -0.13 -0.02  0.09  0.16  0.17 -0.06  0.07  0.17
## O7  -0.04  0.13  0.06  0.19  0.12  0.23  0.05  0.17  0.21 -0.15  0.05 -0.07
## O8  -0.11 -0.18 -0.01  0.04 -0.07 -0.08  0.06  0.12 -0.07 -0.12 -0.13 -0.10
## O9  -0.05 -0.07 -0.04 -0.07 -0.29 -0.22  0.08  0.03  0.07  0.22 -0.07  0.14
## O10 -0.23  0.12 -0.11 -0.13  0.18  0.23 -0.18 -0.13 -0.07  0.00  0.15  0.00
##      PC25  PC26  PC27  PC28  PC29  PC30  PC31 h2       u2  com
## E1   0.14  0.09  0.04 -0.08  0.16 -0.08 -0.22  1 -2.2e-16  3.8
## E2  -0.04 -0.14  0.20  0.01  0.04  0.35  0.08  1 -2.4e-15  3.8
## E4   0.12  0.10 -0.10  0.21  0.06 -0.18  0.20  1 -1.3e-15  4.7
## E5  -0.02 -0.08 -0.11 -0.07 -0.06 -0.10  0.18  1 -2.2e-16  7.4
## E7   0.03  0.03  0.01 -0.04 -0.02 -0.08  0.07  1  2.6e-15  7.3
## E8   0.10 -0.01  0.18  0.24  0.10  0.05  0.12  1 -8.9e-16  5.5
## E10  0.02  0.13  0.00 -0.01 -0.01  0.04  0.00  1 -2.2e-16  7.3
## A1  -0.12 -0.12  0.07  0.17  0.12 -0.05 -0.11  1 -2.2e-16  7.3
## A2  -0.21 -0.07  0.17 -0.04 -0.10 -0.14 -0.07  1  2.2e-16  7.1
## A3   0.01  0.09 -0.09 -0.17  0.01  0.09  0.14  1 -6.7e-16  7.7
## A5   0.08  0.21  0.09  0.04 -0.07  0.10  0.08  1 -4.4e-16  5.8
## A6   0.13 -0.15 -0.18  0.06 -0.02  0.07 -0.13  1 -6.7e-16  5.5
## A10 -0.02  0.01 -0.04 -0.03 -0.03  0.02 -0.03  1  5.6e-16  6.3
## C1  -0.09 -0.06 -0.02  0.03  0.02 -0.01  0.03  1  1.8e-15 10.7
## C3  -0.14  0.17  0.13  0.03 -0.08 -0.01  0.02  1  2.2e-16 11.0
## C4  -0.12  0.09 -0.02 -0.03  0.06 -0.05 -0.01  1  1.3e-15  6.3
## C6  -0.06  0.07 -0.19 -0.09 -0.03  0.09  0.04  1  1.2e-15  9.4
## C8  -0.02  0.24  0.13 -0.02  0.14 -0.06 -0.05  1  6.7e-16  7.8
## C9  -0.07 -0.14 -0.04  0.10 -0.12 -0.05 -0.02  1  1.3e-15  7.1
## N1   0.06  0.06  0.09  0.00 -0.14  0.06 -0.11  1  2.2e-16  4.7
## N2   0.11 -0.05  0.04  0.06  0.03 -0.05  0.03  1  2.0e-15  8.3
## N4   0.01 -0.13  0.02 -0.13  0.26 -0.03  0.07  1  0.0e+00  6.0
## N5  -0.03  0.02  0.02 -0.07  0.05  0.02  0.07  1  8.9e-16  5.8
## N6   0.01  0.07 -0.10  0.16 -0.21  0.02 -0.06  1  1.1e-16  7.7
## N7  -0.11 -0.05 -0.01 -0.04  0.03 -0.03  0.00  1  6.7e-16  9.7
## O3   0.22  0.08  0.00 -0.03  0.01  0.03 -0.09  1 -2.2e-16  8.3
## O4  -0.09 -0.03 -0.04 -0.08  0.03 -0.01 -0.02  1  0.0e+00  6.3
## O7   0.23 -0.07 -0.02 -0.11 -0.04  0.02 -0.05  1 -2.2e-16  6.3
## O8  -0.15  0.11 -0.18  0.17  0.18  0.12 -0.08  1  5.6e-16  4.7
## O9   0.16 -0.10  0.17 -0.04 -0.07 -0.10  0.03  1  6.7e-16  4.8
## O10 -0.12  0.07  0.08 -0.09 -0.07 -0.02  0.00  1  6.7e-16  8.5
## 
##                        PC1  PC2  PC3  PC4  PC5  PC6  PC7  PC8  PC9 PC10 PC11
## SS loadings           5.36 3.40 2.95 2.33 1.79 1.16 1.10 0.93 0.88 0.84 0.78
## Proportion Var        0.17 0.11 0.10 0.08 0.06 0.04 0.04 0.03 0.03 0.03 0.03
## Cumulative Var        0.17 0.28 0.38 0.45 0.51 0.55 0.58 0.61 0.64 0.67 0.69
## Proportion Explained  0.17 0.11 0.10 0.08 0.06 0.04 0.04 0.03 0.03 0.03 0.03
## Cumulative Proportion 0.17 0.28 0.38 0.45 0.51 0.55 0.58 0.61 0.64 0.67 0.69
##                       PC12 PC13 PC14 PC15 PC16 PC17 PC18 PC19 PC20 PC21 PC22
## SS loadings           0.73 0.70 0.66 0.63 0.62 0.60 0.53 0.52 0.52 0.48 0.44
## Proportion Var        0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.01
## Cumulative Var        0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.85 0.87 0.89 0.90
## Proportion Explained  0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.01
## Cumulative Proportion 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.85 0.87 0.89 0.90
##                       PC23 PC24 PC25 PC26 PC27 PC28 PC29 PC30 PC31
## SS loadings           0.43 0.40 0.38 0.35 0.34 0.32 0.30 0.28 0.26
## Proportion Var        0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
## Cumulative Var        0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00
## Proportion Explained  0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
## Cumulative Proportion 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00
## 
## Mean item complexity =  6.9
## Test of the hypothesis that 31 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0 
##  with the empirical chi square  0  with prob <  NA 
## 
## Fit based upon off diagonal values = 1

##Step 4: Decide which components to retain (PRINCIPAL COMPONENTS ANALYSIS)

#Create the scree plot
plot(pc1$values, type = "b") 

#Print the variance explained by each component
pc1$Vaccounted 
##                             PC1       PC2        PC3       PC4        PC5
## SS loadings           5.3620195 3.3966708 2.94746733 2.3274522 1.79040792
## Proportion Var        0.1729684 0.1095700 0.09507959 0.0750791 0.05775509
## Cumulative Var        0.1729684 0.2825384 0.37761799 0.4526971 0.51045219
## Proportion Explained  0.1729684 0.1095700 0.09507959 0.0750791 0.05775509
## Cumulative Proportion 0.1729684 0.2825384 0.37761799 0.4526971 0.51045219
##                              PC6        PC7        PC8        PC9       PC10
## SS loadings           1.15931750 1.09850937 0.93342698 0.88231360 0.83605728
## Proportion Var        0.03739734 0.03543579 0.03011055 0.02846173 0.02696959
## Cumulative Var        0.54784953 0.58328531 0.61339586 0.64185759 0.66882718
## Proportion Explained  0.03739734 0.03543579 0.03011055 0.02846173 0.02696959
## Cumulative Proportion 0.54784953 0.58328531 0.61339586 0.64185759 0.66882718
##                             PC11       PC12       PC13       PC14       PC15
## SS loadings           0.77524848 0.73171304 0.69842929 0.65968066 0.63242960
## Proportion Var        0.02500802 0.02360365 0.02252998 0.02128002 0.02040095
## Cumulative Var        0.69383519 0.71743884 0.73996882 0.76124884 0.78164979
## Proportion Explained  0.02500802 0.02360365 0.02252998 0.02128002 0.02040095
## Cumulative Proportion 0.69383519 0.71743884 0.73996882 0.76124884 0.78164979
##                             PC16       PC17       PC18      PC19       PC20
## SS loadings           0.61833110 0.59641435 0.53346260 0.5230507 0.51641237
## Proportion Var        0.01994616 0.01923917 0.01720847 0.0168726 0.01665846
## Cumulative Var        0.80159596 0.82083513 0.83804360 0.8549162 0.87157467
## Proportion Explained  0.01994616 0.01923917 0.01720847 0.0168726 0.01665846
## Cumulative Proportion 0.80159596 0.82083513 0.83804360 0.8549162 0.87157467
##                             PC21       PC22       PC23       PC24      PC25
## SS loadings           0.48424207 0.43712456 0.42510769 0.39936926 0.3848867
## Proportion Var        0.01562071 0.01410079 0.01371315 0.01288288 0.0124157
## Cumulative Var        0.88719538 0.90129617 0.91500932 0.92789220 0.9403079
## Proportion Explained  0.01562071 0.01410079 0.01371315 0.01288288 0.0124157
## Cumulative Proportion 0.88719538 0.90129617 0.91500932 0.92789220 0.9403079
##                             PC26       PC27       PC28        PC29        PC30
## SS loadings           0.35449104 0.34192245 0.31667258 0.301706982 0.277745193
## Proportion Var        0.01143519 0.01102976 0.01021524 0.009732483 0.008959522
## Cumulative Var        0.95174310 0.96277285 0.97298810 0.982720582 0.991680104
## Proportion Explained  0.01143519 0.01102976 0.01021524 0.009732483 0.008959522
## Cumulative Proportion 0.95174310 0.96277285 0.97298810 0.982720582 0.991680104
##                              PC31
## SS loadings           0.257916776
## Proportion Var        0.008319896
## Cumulative Var        1.000000000
## Proportion Explained  0.008319896
## Cumulative Proportion 1.000000000
#Print the Eigenvalues
pc1$values
##  [1] 5.3620195 3.3966708 2.9474673 2.3274522 1.7904079 1.1593175 1.0985094
##  [8] 0.9334270 0.8823136 0.8360573 0.7752485 0.7317130 0.6984293 0.6596807
## [15] 0.6324296 0.6183311 0.5964144 0.5334626 0.5230507 0.5164124 0.4842421
## [22] 0.4371246 0.4251077 0.3993693 0.3848867 0.3544910 0.3419225 0.3166726
## [29] 0.3017070 0.2777452 0.2579168
#Another way to look at eigen values plus variance explained (need to use princomp function of PCA to get right class for use with factoextra functions)
pcf=princomp(sData)
factoextra::get_eigenvalue(pcf)
##        eigenvalue variance.percent cumulative.variance.percent
## Dim.1   7.2229760       17.7878083                    17.78781
## Dim.2   4.3563605       10.7282794                    28.51609
## Dim.3   3.9367435        9.6949011                    38.21099
## Dim.4   3.3455339        8.2389470                    46.44994
## Dim.5   2.3524408        5.7932860                    52.24322
## Dim.6   1.4998321        3.6935919                    55.93681
## Dim.7   1.3479400        3.3195317                    59.25635
## Dim.8   1.2595122        3.1017631                    62.35811
## Dim.9   1.1506612        2.8336990                    65.19181
## Dim.10  1.1015688        2.7128008                    67.90461
## Dim.11  0.9793638        2.4118500                    70.31646
## Dim.12  0.9292927        2.2885414                    72.60500
## Dim.13  0.9193765        2.2641212                    74.86912
## Dim.14  0.8626665        2.1244632                    76.99358
## Dim.15  0.7965352        1.9616035                    78.95519
## Dim.16  0.7770077        1.9135138                    80.86870
## Dim.17  0.7609949        1.8740795                    82.74278
## Dim.18  0.6853564        1.6878068                    84.43059
## Dim.19  0.6535380        1.6094486                    86.04004
## Dim.20  0.6261561        1.5420161                    87.58205
## Dim.21  0.6058311        1.4919622                    89.07401
## Dim.22  0.5769480        1.4208326                    90.49485
## Dim.23  0.5486778        1.3512125                    91.84606
## Dim.24  0.5448046        1.3416740                    93.18773
## Dim.25  0.5000232        1.2313923                    94.41913
## Dim.26  0.4594281        1.1314198                    95.55055
## Dim.27  0.4415621        1.0874219                    96.63797
## Dim.28  0.3924032        0.9663597                    97.60433
## Dim.29  0.3564223        0.8777506                    98.48208
## Dim.30  0.3260599        0.8029780                    99.28506
## Dim.31  0.2903126        0.7149441                   100.00000
factoextra::fviz_eig(pcf, addlabels = TRUE, ylim = c(0, 50))#Visualize the Eigenvalues

factoextra::fviz_pca_var(pcf, col.var = "black")

factoextra::fviz_pca_var(pcf, col.var = "cos2",
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"), 
             repel = TRUE # Avoid text overlapping
             )

#Print the loadings above the level of 0.3
psych::print.psych(pc1, cut = 0.3, sort = TRUE)
## Principal Components Analysis
## Call: principal(r = sData, nfactors = length(sData), rotate = "none")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     item   PC1   PC2   PC3   PC4   PC5   PC6   PC7   PC8   PC9  PC10  PC11
## E1     1 -0.70                                                            
## N1    20  0.65                                                            
## E2     2 -0.64                    0.53                                    
## E4     3 -0.62                    0.48                                    
## E8     6  0.62  0.34                                                      
## A5    11 -0.57  0.30                                                      
## N4    22  0.55  0.49                                                      
## A2     9 -0.52  0.47                                                      
## N7    25  0.50                                                  0.33      
## C3    15 -0.41  0.36                                           -0.34      
## A6    12 -0.50  0.56                                                      
## A3    10        0.55             -0.34                                    
## A1     8 -0.37  0.54             -0.32                                    
## N6    24  0.41  0.53                                                      
## E5     4 -0.44  0.49                          0.34                        
## N2    21  0.42  0.48                                                      
## O9    30              0.64  0.39                                          
## O8    29              0.64  0.43                                          
## C9    19  0.33        0.51 -0.44                          0.30            
## O7    28              0.51  0.51             -0.34                        
## O10   31              0.50                    0.40                        
## C6    17  0.32        0.43 -0.42                               -0.35      
## C4    16                    0.60                                          
## C8    18  0.41        0.45 -0.46                                          
## C1    14             -0.33  0.37                    0.36  0.32        0.33
## A10   13                          0.55  0.31        0.32                  
## E7     5                          0.35  0.52 -0.37                    0.35
## E10    7                                0.50       -0.43  0.38  0.30      
## O3    26        0.43 -0.34                    0.48                        
## O4    27        0.41 -0.33 -0.32  0.32                                    
## N5    23  0.42  0.43                                                      
##      PC12  PC13  PC14  PC15  PC16  PC17  PC18  PC19  PC20  PC21  PC22  PC23
## E1                                                                         
## N1                                                              -0.37      
## E2                                                                         
## E4                                                                         
## E8                                                                         
## A5              -0.45                                                      
## N4                                                                         
## A2                                                                         
## N7                                                                         
## C3                                                                         
## A6                                                                         
## A3                                                                         
## A1                                                         0.33            
## N6                                                                         
## E5                                 0.37                                    
## N2                                                                         
## O9                                                                         
## O8                                                                         
## C9                                                                         
## O7                                                                         
## O10                                                                        
## C6                                                                         
## C4                                                                         
## C8                                                                         
## C1               0.31                                                      
## A10 -0.44                                                                  
## E7                                                                         
## E10                                                                        
## O3                                                                         
## O4        -0.55                                                            
## N5                    -0.55                                                
##      PC24  PC25  PC26  PC27  PC28  PC29  PC30  PC31 h2       u2  com
## E1                                                   1 -2.2e-16  3.8
## N1                                                   1  2.2e-16  4.7
## E2                                       0.35        1 -2.4e-15  3.8
## E4                                                   1 -1.3e-15  4.7
## E8                                                   1 -8.9e-16  5.5
## A5                                                   1 -4.4e-16  5.8
## N4                                                   1  0.0e+00  6.0
## A2                                                   1  2.2e-16  7.1
## N7                                                   1  6.7e-16  9.7
## C3                                                   1  2.2e-16 11.0
## A6                                                   1 -6.7e-16  5.5
## A3                                                   1 -6.7e-16  7.7
## A1                                                   1 -2.2e-16  7.3
## N6                                                   1  1.1e-16  7.7
## E5                                                   1 -2.2e-16  7.4
## N2                                                   1  2.0e-15  8.3
## O9                                                   1  6.7e-16  4.8
## O8                                                   1  5.6e-16  4.7
## C9                                                   1  1.3e-15  7.1
## O7                                                   1 -2.2e-16  6.3
## O10                                                  1  6.7e-16  8.5
## C6                                                   1  1.2e-15  9.4
## C4                                                   1  1.3e-15  6.3
## C8                                                   1  6.7e-16  7.8
## C1                                                   1  1.8e-15 10.7
## A10                                                  1  5.6e-16  6.3
## E7                                                   1  2.6e-15  7.3
## E10                                                  1 -2.2e-16  7.3
## O3                                                   1 -2.2e-16  8.3
## O4                                                   1  0.0e+00  6.3
## N5                                                   1  8.9e-16  5.8
## 
##                        PC1  PC2  PC3  PC4  PC5  PC6  PC7  PC8  PC9 PC10 PC11
## SS loadings           5.36 3.40 2.95 2.33 1.79 1.16 1.10 0.93 0.88 0.84 0.78
## Proportion Var        0.17 0.11 0.10 0.08 0.06 0.04 0.04 0.03 0.03 0.03 0.03
## Cumulative Var        0.17 0.28 0.38 0.45 0.51 0.55 0.58 0.61 0.64 0.67 0.69
## Proportion Explained  0.17 0.11 0.10 0.08 0.06 0.04 0.04 0.03 0.03 0.03 0.03
## Cumulative Proportion 0.17 0.28 0.38 0.45 0.51 0.55 0.58 0.61 0.64 0.67 0.69
##                       PC12 PC13 PC14 PC15 PC16 PC17 PC18 PC19 PC20 PC21 PC22
## SS loadings           0.73 0.70 0.66 0.63 0.62 0.60 0.53 0.52 0.52 0.48 0.44
## Proportion Var        0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.01
## Cumulative Var        0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.85 0.87 0.89 0.90
## Proportion Explained  0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.01
## Cumulative Proportion 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.85 0.87 0.89 0.90
##                       PC23 PC24 PC25 PC26 PC27 PC28 PC29 PC30 PC31
## SS loadings           0.43 0.40 0.38 0.35 0.34 0.32 0.30 0.28 0.26
## Proportion Var        0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
## Cumulative Var        0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00
## Proportion Explained  0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
## Cumulative Proportion 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00
## 
## Mean item complexity =  6.9
## Test of the hypothesis that 31 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0 
##  with the empirical chi square  0  with prob <  NA 
## 
## Fit based upon off diagonal values = 1
#create a diagram showing the components and how the manifest variables load
fa.diagram(pc1) 

#Show the loadings of variables on to components
fa.sort(pc1$loading)
## 
## Loadings:
##     PC1    PC2    PC3    PC4    PC5    PC6    PC7    PC8    PC9    PC10  
## E1  -0.704  0.107                0.280               -0.104  0.238 -0.202
## N1   0.647  0.292        -0.122  0.181 -0.287                      -0.107
## E2  -0.638         0.164 -0.129  0.533                                   
## E4  -0.624         0.229 -0.126  0.477 -0.116                       0.184
## E8   0.616  0.344               -0.242  0.280               -0.109 -0.179
## A5  -0.573  0.302               -0.233 -0.122         0.299  0.149       
## N4   0.548  0.486 -0.166               -0.139               -0.160       
## A2  -0.519  0.473  0.256 -0.134                                     0.127
## N7   0.499  0.208 -0.234         0.168 -0.298        -0.147  0.146  0.328
## C3  -0.407  0.361 -0.265  0.294  0.167        -0.217 -0.182        -0.338
## A6  -0.504  0.564               -0.175  0.144         0.124 -0.121  0.112
## A3  -0.246  0.550  0.195 -0.200 -0.343        -0.213        -0.117  0.274
## A1  -0.370  0.537  0.123 -0.209 -0.316        -0.155                     
## N6   0.408  0.532 -0.273  0.114  0.149 -0.230 -0.167        -0.136       
## E5  -0.437  0.487  0.246               -0.134  0.336               -0.248
## N2   0.424  0.479                0.254 -0.137 -0.136         0.281       
## O9   0.152  0.126  0.640  0.388                      -0.234              
## O8   0.240  0.109  0.638  0.434  0.115                                   
## C9   0.326         0.514 -0.437  0.152  0.169                0.303       
## O7          0.123  0.509  0.508               -0.337  0.167  0.116       
## O10  0.235  0.139  0.505  0.299                0.405        -0.224       
## C6   0.316  0.239  0.432 -0.423         0.102 -0.109 -0.208        -0.354
## C4  -0.282  0.265 -0.166  0.596  0.145 -0.121               -0.113       
## C8   0.406         0.449 -0.460                       0.267         0.155
## C1  -0.271        -0.325  0.368         0.117  0.260  0.359  0.318       
## A10  0.153         0.147  0.131  0.551  0.310  0.169  0.320 -0.153  0.147
## E7   0.252        -0.173         0.352  0.521 -0.366  0.111 -0.202       
## E10  0.158  0.236 -0.162  0.227 -0.183  0.503  0.152 -0.427  0.379  0.303
## O3  -0.147  0.425 -0.341 -0.281  0.127         0.480        -0.216       
## O4          0.414 -0.329 -0.324  0.316  0.186         0.105              
## N5   0.416  0.433 -0.126  0.178                       0.269  0.256       
##     PC11   PC12   PC13   PC14   PC15   PC16   PC17   PC18   PC19   PC20  
## E1                                     -0.181  0.157         0.227 -0.123
## N1                 0.161         0.126 -0.127        -0.210              
## E2          0.117         0.111                0.138                     
## E4                        0.123        -0.131         0.129              
## E8  -0.173                              0.112                0.270       
## A5                       -0.447  0.148 -0.123                            
## N4  -0.102                       0.262 -0.291               -0.190       
## A2  -0.167  0.262  0.122                      -0.150  0.223  0.113       
## N7   0.291 -0.153  0.169 -0.183  0.104  0.179  0.122  0.156  0.186  0.170
## C3         -0.280         0.107               -0.117        -0.174  0.300
## A6                 0.123                                    -0.231  0.120
## A3   0.170 -0.102         0.227                      -0.228  0.153       
## A1   0.215 -0.288                              0.117               -0.106
## N6          0.137         0.209        -0.211  0.122         0.134       
## E5  -0.132                                     0.365 -0.145         0.107
## N2         -0.111 -0.239                0.292               -0.268 -0.293
## O9   0.155                                    -0.290 -0.221              
## O8   0.129  0.136 -0.107 -0.185                                     0.121
## C9                                                   -0.186              
## O7                        0.135         0.185  0.116  0.226         0.171
## O10  0.221        -0.227  0.115 -0.113 -0.127  0.185  0.232 -0.176 -0.133
## C6                 0.141                0.111 -0.168  0.207        -0.220
## C4  -0.261  0.210  0.113        -0.102  0.216        -0.212        -0.225
## C8  -0.119  0.130         0.209         0.110               -0.129  0.176
## C1   0.327  0.204         0.313  0.235        -0.168                     
## A10 -0.243 -0.442  0.152         0.178                       0.117       
## E7   0.352  0.242  0.110 -0.213                0.223                     
## E10 -0.122                             -0.115  0.127                     
## O3   0.131  0.103  0.114        -0.214  0.263 -0.110                     
## O4                -0.550                      -0.133                0.159
## N5                 0.197        -0.552 -0.201                            
##     PC21   PC22   PC23   PC24   PC25   PC26   PC27   PC28   PC29   PC30  
## E1  -0.170                       0.145                       0.162       
## N1         -0.372         0.203                             -0.137       
## E2                                     -0.139  0.197                0.348
## E4         -0.152                0.121  0.101         0.211        -0.181
## E8  -0.133         0.163         0.104         0.177  0.237              
## A5   0.144                              0.206                       0.101
## N4                       -0.154        -0.132        -0.132  0.262       
## A2  -0.137 -0.158 -0.121        -0.209         0.167               -0.141
## N7          0.119  0.154        -0.114                                   
## C3                              -0.141  0.175  0.128                     
## A6  -0.250                0.229  0.131 -0.148 -0.184                     
## A3  -0.164               -0.116                      -0.172              
## A1   0.326                      -0.121 -0.123         0.174  0.117       
## N6          0.230 -0.138 -0.101                       0.163 -0.215       
## E5                -0.188                      -0.107                     
## N2  -0.168        -0.130         0.110                                   
## O9          0.220         0.141  0.156         0.175                     
## O8         -0.117 -0.129 -0.100 -0.149  0.108 -0.181  0.171  0.179  0.123
## C9                 0.295 -0.246        -0.139         0.102 -0.115       
## O7   0.214 -0.151                0.234               -0.109              
## O10                0.154        -0.120                                   
## C6   0.119  0.110         0.166               -0.194                     
## C4   0.138         0.249        -0.118                                   
## C8          0.169 -0.121  0.132         0.245  0.129         0.141       
## C1                                                                       
## A10               -0.106                                                 
## E7                                                                       
## E10  0.119                              0.129                            
## O3   0.122               -0.188  0.220                                   
## O4   0.165                0.170                                          
## N5                                                                       
##     PC31  
## E1  -0.219
## N1  -0.110
## E2        
## E4   0.200
## E8   0.124
## A5        
## N4        
## A2        
## N7        
## C3        
## A6  -0.131
## A3   0.135
## A1  -0.111
## N6        
## E5   0.183
## N2        
## O9        
## O8        
## C9        
## O7        
## O10       
## C6        
## C4        
## C8        
## C1        
## A10       
## E7        
## E10       
## O3        
## O4        
## N5        
## 
##                  PC1   PC2   PC3   PC4   PC5   PC6   PC7   PC8   PC9  PC10
## SS loadings    5.362 3.397 2.947 2.327 1.790 1.159 1.099 0.933 0.882 0.836
## Proportion Var 0.173 0.110 0.095 0.075 0.058 0.037 0.035 0.030 0.028 0.027
## Cumulative Var 0.173 0.283 0.378 0.453 0.510 0.548 0.583 0.613 0.642 0.669
##                 PC11  PC12  PC13  PC14  PC15  PC16  PC17  PC18  PC19  PC20
## SS loadings    0.775 0.732 0.698 0.660 0.632 0.618 0.596 0.533 0.523 0.516
## Proportion Var 0.025 0.024 0.023 0.021 0.020 0.020 0.019 0.017 0.017 0.017
## Cumulative Var 0.694 0.717 0.740 0.761 0.782 0.802 0.821 0.838 0.855 0.872
##                 PC21  PC22  PC23  PC24  PC25  PC26  PC27  PC28  PC29  PC30
## SS loadings    0.484 0.437 0.425 0.399 0.385 0.354 0.342 0.317 0.302 0.278
## Proportion Var 0.016 0.014 0.014 0.013 0.012 0.011 0.011 0.010 0.010 0.009
## Cumulative Var 0.887 0.901 0.915 0.928 0.940 0.952 0.963 0.973 0.983 0.992
##                 PC31
## SS loadings    0.258
## Proportion Var 0.008
## Cumulative Var 1.000
#Output the communalities of variables across components (will be one for PCA since all the variance is used)
pc1$communality 
##  E1  E2  E4  E5  E7  E8 E10  A1  A2  A3  A5  A6 A10  C1  C3  C4  C6  C8  C9  N1 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 
##  N2  N4  N5  N6  N7  O3  O4  O7  O8  O9 O10 
##   1   1   1   1   1   1   1   1   1   1   1
#Visualize contribution of variables to each component
var <- factoextra::get_pca_var(pcf)
corrplot::corrplot(var$contrib, is.corr=FALSE) 

# Contributions of variables to PC1
factoextra::fviz_contrib(pcf, choice = "var", axes = 1, top = 10)

# Contributions of variables to PC2
factoextra::fviz_contrib(pcf, choice = "var", axes = 2, top = 10)

##Step 5: Apply rotation

#Apply rotation to try to refine the component structure
pc2 <-  principal(sData, nfactors = 5, rotate = "varimax")#Extracting 4 factors
#output the components
psych::print.psych(pc2, cut = 0.3, sort = TRUE)
## Principal Components Analysis
## Call: principal(r = sData, nfactors = 5, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     item   RC1   RC2   RC4   RC3   RC5   h2   u2 com
## N6    24  0.72                         0.56 0.44 1.2
## N4    22  0.70                         0.57 0.43 1.3
## N2    21  0.69                         0.49 0.51 1.1
## N1    20  0.63        0.31             0.55 0.45 1.8
## N5    23  0.57                         0.41 0.59 1.5
## N7    25  0.55                         0.38 0.62 1.5
## O4    27  0.48             -0.39       0.49 0.51 2.9
## E7     5  0.35                         0.22 0.78 2.4
## A1     8        0.76                   0.58 0.42 1.0
## A3    10        0.73                   0.56 0.44 1.1
## A6    12        0.72                   0.61 0.39 1.3
## A2     9        0.70                   0.58 0.42 1.3
## E5     4        0.65                   0.49 0.51 1.3
## A5    11        0.63                   0.49 0.51 1.4
## C8    18              0.75             0.59 0.41 1.1
## C9    19              0.72             0.59 0.41 1.3
## C4    16             -0.67             0.55 0.45 1.5
## C6    17              0.65             0.53 0.47 1.6
## C1    14             -0.56             0.32 0.68 1.0
## C3    15        0.31 -0.55             0.48 0.52 2.2
## O8    29                    0.81       0.68 0.32 1.1
## O9    30                    0.76       0.60 0.40 1.1
## O7    28                    0.72       0.54 0.46 1.0
## O10   31                    0.63       0.42 0.58 1.2
## O3    26  0.35  0.31       -0.40       0.41 0.59 3.3
## E2     2                          0.81 0.73 0.27 1.2
## E4     3                          0.77 0.69 0.31 1.3
## E1     1        0.37              0.60 0.60 0.40 2.3
## E8     6  0.48                   -0.54 0.56 0.44 2.3
## A10   13                          0.39 0.37 0.63 3.5
## E10    7                         -0.31 0.19 0.81 2.9
## 
##                        RC1  RC2  RC4  RC3  RC5
## SS loadings           3.68 3.66 2.98 2.78 2.72
## Proportion Var        0.12 0.12 0.10 0.09 0.09
## Cumulative Var        0.12 0.24 0.33 0.42 0.51
## Proportion Explained  0.23 0.23 0.19 0.18 0.17
## Cumulative Proportion 0.23 0.46 0.65 0.83 1.00
## 
## Mean item complexity =  1.7
## Test of the hypothesis that 5 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.05 
##  with the empirical chi square  961.55  with prob <  2.2e-65 
## 
## Fit based upon off diagonal values = 0.93
#output the communalities
pc2$communality
##        E1        E2        E4        E5        E7        E8       E10        A1 
## 0.5950986 0.7340796 0.6870828 0.4906798 0.2197046 0.5624587 0.1921658 0.5833365 
##        A2        A3        A5        A6       A10        C1        C3        C4 
## 0.5785891 0.5586902 0.4898214 0.6109292 0.3654486 0.3153426 0.4805751 0.5535264 
##        C6        C8        C9        N1        N2        N4        N5        N6 
## 0.5322111 0.5865772 0.5929027 0.5510816 0.4860990 0.5744249 0.4090745 0.5596758 
##        N7        O3        O4        O7        O8        O9       O10 
## 0.3777081 0.4140158 0.4853921 0.5366989 0.6790055 0.6002451 0.4213765
#NOTE: you can do all the other things done for the model created in pc1

##Step 3: Do the dimension reduction and Step 4: Decide which factors/components to retain (FACTOR ANALYSIS)

#Factor Analysis - the default here is principal axis factoring fm=pa
#If we know our data going in is normally distributed we use maximum likelihood
facsol <- psych::fa(sMatrix, nfactors=5, obs=NA, n.iter=1, rotate="varimax", fm="pa")

#Create your scree plot
plot(facsol$values, type = "b") #scree plot

#Print the Variance accounted for by each factor/component
facsol$Vaccounted
##                             PA2       PA1        PA4        PA3        PA5
## SS loadings           3.1242347 3.1129711 2.42967385 2.24229110 2.21900146
## Proportion Var        0.1007818 0.1004184 0.07837658 0.07233197 0.07158069
## Cumulative Var        0.1007818 0.2012002 0.27957676 0.35190873 0.42348943
## Proportion Explained  0.2379794 0.2371214 0.18507328 0.17079995 0.16902593
## Cumulative Proportion 0.2379794 0.4751009 0.66017413 0.83097407 1.00000000
#Output the Eigenvalues
facsol$values 
##  [1]  4.852945576  2.844349777  2.405285652  1.767867218  1.257723978
##  [6]  0.466286721  0.434095835  0.299373252  0.290345985  0.205915199
## [11]  0.158279258  0.102028578  0.086714067  0.054795845  0.019749853
## [16]  0.001157938 -0.014060215 -0.027338985 -0.040157756 -0.049978343
## [21] -0.063822217 -0.100939952 -0.108816615 -0.134368997 -0.161522477
## [26] -0.178654131 -0.210469246 -0.227316507 -0.234606308 -0.264508730
## [31] -0.303063955
#Print the components with loadings
psych::print.psych(facsol,cut=0.3, sort=TRUE)
## Factor Analysis using method =  pa
## Call: psych::fa(r = sMatrix, nfactors = 5, n.iter = 1, rotate = "varimax", 
##     fm = "pa", obs = NA)
## Standardized loadings (pattern matrix) based upon correlation matrix
##     item   PA2   PA1   PA4   PA3   PA5   h2   u2 com
## A1     8  0.70                         0.50 0.50 1.0
## A6    12  0.70                         0.56 0.44 1.3
## A2     9  0.66                         0.51 0.49 1.3
## A3    10  0.66                         0.45 0.55 1.1
## E5     4  0.59                         0.40 0.60 1.3
## A5    11  0.58                         0.41 0.59 1.5
## N6    24        0.69                   0.50 0.50 1.1
## N4    22        0.68                   0.52 0.48 1.3
## N2    21        0.62                   0.40 0.60 1.1
## N1    20        0.60                   0.50 0.50 1.8
## N5    23        0.51                   0.32 0.68 1.5
## N7    25        0.49                   0.31 0.69 1.6
## O4    27        0.40       -0.33       0.34 0.66 2.9
## E7     5                               0.11 0.89 2.1
## C8    18              0.69             0.50 0.50 1.1
## C9    19              0.67             0.51 0.49 1.3
## C4    16             -0.59             0.44 0.56 1.5
## C6    17              0.58             0.42 0.58 1.6
## C3    15             -0.49             0.38 0.62 2.2
## C1    14             -0.45             0.21 0.79 1.1
## O8    29                    0.79       0.64 0.36 1.1
## O9    30                    0.70       0.51 0.49 1.1
## O7    28                    0.63       0.40 0.60 1.0
## O10   31                    0.52       0.30 0.70 1.2
## O3    26                   -0.34       0.30 0.70 3.3
## E2     2                          0.80 0.72 0.28 1.3
## E4     3                          0.73 0.63 0.37 1.4
## E1     1  0.36                    0.55 0.53 0.47 2.5
## E8     6        0.47             -0.49 0.49 0.51 2.3
## A10   13                               0.16 0.84 3.9
## E10    7                               0.11 0.89 2.9
## 
##                        PA2  PA1  PA4  PA3  PA5
## SS loadings           3.12 3.11 2.43 2.24 2.22
## Proportion Var        0.10 0.10 0.08 0.07 0.07
## Cumulative Var        0.10 0.20 0.28 0.35 0.42
## Proportion Explained  0.24 0.24 0.19 0.17 0.17
## Cumulative Proportion 0.24 0.48 0.66 0.83 1.00
## 
## Mean item complexity =  1.7
## Test of the hypothesis that 5 factors are sufficient.
## 
## The degrees of freedom for the null model are  465  and the objective function was  10.83
## The degrees of freedom for the model are 320  and the objective function was  1.55 
## 
## The root mean square of the residuals (RMSR) is  0.03 
## The df corrected root mean square of the residuals is  0.04 
## 
## Fit based upon off diagonal values = 0.97
## Measures of factor score adequacy             
##                                                    PA2  PA1  PA4  PA3  PA5
## Correlation of (regression) scores with factors   0.92 0.91 0.89 0.90 0.90
## Multiple R square of scores with factors          0.84 0.82 0.80 0.81 0.81
## Minimum correlation of possible factor scores     0.68 0.65 0.60 0.63 0.62
#Print sorted list of loadings
fa.sort(facsol$loading)
## 
## Loadings:
##     PA2    PA1    PA4    PA3    PA5   
## A1   0.704                            
## A6   0.695        -0.273              
## A2   0.661                       0.262
## A3   0.659         0.110              
## E5   0.589                0.120  0.194
## A5   0.577 -0.219 -0.129         0.113
## N6          0.688               -0.136
## N4          0.680               -0.233
## N2          0.622  0.111              
## N1  -0.167  0.601  0.297        -0.138
## N5          0.511         0.120 -0.214
## N7  -0.194  0.493               -0.130
## O4   0.185  0.402        -0.329  0.194
## E7  -0.192  0.259                     
## C8                 0.693  0.104       
## C9          0.141  0.668  0.176  0.108
## C4   0.148  0.114 -0.594  0.202  0.107
## C6   0.120  0.231  0.579  0.139       
## C3   0.294  0.128 -0.491         0.194
## C1                -0.445              
## O8                 0.107  0.792       
## O9                 0.108  0.703       
## O7                        0.627       
## O10                0.131  0.524       
## O3   0.283  0.293        -0.336  0.121
## E2   0.183 -0.191                0.802
## E4   0.192 -0.248                0.725
## E1   0.360 -0.228 -0.202         0.546
## E8          0.466  0.159  0.119 -0.488
## A10 -0.190  0.176         0.196  0.223
## E10         0.193 -0.138        -0.220
## 
##                  PA2   PA1   PA4   PA3   PA5
## SS loadings    3.124 3.113 2.430 2.242 2.219
## Proportion Var 0.101 0.100 0.078 0.072 0.072
## Cumulative Var 0.101 0.201 0.280 0.352 0.423
#create a diagram showing the factors and how the manifest variables load
fa.diagram(facsol)

#Note: you can apply rotation as you did for PCA

##Step 5: Apply rotation

#Apply rotation to try to refine the component structure
facsolrot <-  principal(sMatrix, rotate = "varimax")
#output the components
psych::print.psych(facsolrot, cut = 0.3, sort = TRUE)
## Principal Components Analysis
## Call: principal(r = sMatrix, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      V   PC1     h2   u2 com
## E1   1 -0.70 0.4949 0.51   1
## N1  20  0.65 0.4182 0.58   1
## E2   2 -0.64 0.4066 0.59   1
## E4   3 -0.62 0.3895 0.61   1
## E8   6  0.62 0.3793 0.62   1
## A5  11 -0.57 0.3287 0.67   1
## N4  22  0.55 0.3000 0.70   1
## A2   9 -0.52 0.2695 0.73   1
## A6  12 -0.50 0.2538 0.75   1
## N7  25  0.50 0.2492 0.75   1
## E5   4 -0.44 0.1906 0.81   1
## N2  21  0.42 0.1798 0.82   1
## N5  23  0.42 0.1732 0.83   1
## N6  24  0.41 0.1668 0.83   1
## C3  15 -0.41 0.1654 0.83   1
## C8  18  0.41 0.1648 0.84   1
## A1   8 -0.37 0.1366 0.86   1
## C9  19  0.33 0.1061 0.89   1
## C6  17  0.32 0.1002 0.90   1
## C4  16       0.0793 0.92   1
## C1  14       0.0736 0.93   1
## E7   5       0.0634 0.94   1
## A3  10       0.0605 0.94   1
## O8  29       0.0578 0.94   1
## O10 31       0.0552 0.94   1
## E10  7       0.0250 0.97   1
## A10 13       0.0233 0.98   1
## O9  30       0.0230 0.98   1
## O3  26       0.0217 0.98   1
## O7  28       0.0049 1.00   1
## O4  27       0.0011 1.00   1
## 
##                 PC1
## SS loadings    5.36
## Proportion Var 0.17
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 component is sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.14 
## 
## Fit based upon off diagonal values = 0.53
#output the communalities
facsolrot$communality
##          E1          E2          E4          E5          E7          E8 
## 0.494926381 0.406647063 0.389467986 0.190572844 0.063369993 0.379281993 
##         E10          A1          A2          A3          A5          A6 
## 0.025049575 0.136626173 0.269473040 0.060537662 0.328688668 0.253826408 
##         A10          C1          C3          C4          C6          C8 
## 0.023294309 0.073642526 0.165388951 0.079304631 0.100155772 0.164808128 
##          C9          N1          N2          N4          N5          N6 
## 0.106117618 0.418150978 0.179774377 0.299967255 0.173172585 0.166793188 
##          N7          O3          O4          O7          O8          O9 
## 0.249211928 0.021689535 0.001102876 0.004935733 0.057837081 0.022970963 
##         O10 
## 0.055233310

##Step 6: Reliability Analysis

#If you know that variables are grouped, test each group as a separate scale
Extraversion <-sData[,c('E1','E2','E4','E5','E7','E8','E10')]
Agreeableness <- sData[, c('A1','A2','A3','A5','A6','A10')]
Conscientiousness <- sData[, c('C1','C3','C4','C6','C8','C9')]
Neuroticism <- sData[, c('N1','N2','N4','N5','N6','N7')]
Openness <- sData[, c('O3','O4','O7','O8','O9','O10')]

#Output our Cronbach Alpha values
psych::alpha(Extraversion,check.keys=TRUE)
## Warning in psych::alpha(Extraversion, check.keys = TRUE): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
## 
## Reliability analysis   
## Call: psych::alpha(x = Extraversion, check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N  ase mean   sd median_r
##       0.73      0.72    0.74      0.27 2.6 0.02  2.8 0.73     0.22
## 
##  lower alpha upper     95% confidence boundaries
## 0.69 0.73 0.77 
## 
##  Reliability if an item is dropped:
##      raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## E1        0.67      0.65    0.68      0.24 1.9    0.025 0.039  0.20
## E2        0.64      0.64    0.65      0.23 1.8    0.028 0.029  0.20
## E4        0.64      0.64    0.66      0.23 1.8    0.027 0.032  0.20
## E5        0.73      0.71    0.72      0.29 2.5    0.021 0.047  0.22
## E7-       0.76      0.75    0.75      0.33 2.9    0.018 0.041  0.28
## E8-       0.67      0.66    0.69      0.25 2.0    0.025 0.042  0.20
## E10-      0.75      0.74    0.76      0.32 2.8    0.019 0.044  0.28
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## E1   382  0.72  0.72  0.68   0.58  2.6 1.17
## E2   382  0.78  0.76  0.76   0.64  2.9 1.33
## E4   382  0.78  0.76  0.75   0.65  2.7 1.25
## E5   382  0.47  0.52  0.40   0.31  3.9 0.95
## E7-  382  0.37  0.40  0.22   0.16  2.9 1.11
## E8-  382  0.71  0.69  0.63   0.55  1.9 1.25
## E10- 382  0.43  0.43  0.25   0.22  2.7 1.17
## 
## Non missing response frequency for each item
##        0    1    2    3    4    5 miss
## E1  0.01 0.20 0.31 0.27 0.15 0.06    0
## E2  0.01 0.16 0.23 0.19 0.28 0.13    0
## E4  0.01 0.20 0.27 0.21 0.24 0.07    0
## E5  0.02 0.01 0.04 0.13 0.54 0.25    0
## E7  0.01 0.35 0.37 0.12 0.12 0.03    0
## E8  0.01 0.08 0.28 0.22 0.25 0.16    0
## E10 0.01 0.27 0.39 0.15 0.12 0.05    0
#Some items were negatively correlated with the total scale and probably 
## should be reversed.  
psych::alpha(Agreeableness,check.keys = TRUE)
## Warning in psych::alpha(Agreeableness, check.keys = TRUE): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
## 
## Reliability analysis   
## Call: psych::alpha(x = Agreeableness, check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N  ase mean   sd median_r
##       0.75      0.75    0.74      0.33   3 0.02  3.6 0.67     0.42
## 
##  lower alpha upper     95% confidence boundaries
## 0.71 0.75 0.79 
## 
##  Reliability if an item is dropped:
##      raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## A1        0.68      0.69    0.67      0.31 2.2    0.026 0.0300  0.37
## A2        0.70      0.70    0.68      0.32 2.3    0.024 0.0290  0.36
## A3        0.69      0.69    0.67      0.31 2.3    0.025 0.0309  0.41
## A5        0.70      0.71    0.69      0.32 2.4    0.024 0.0348  0.41
## A6        0.69      0.69    0.67      0.31 2.2    0.025 0.0260  0.35
## A10-      0.80      0.80    0.77      0.44 3.9    0.016 0.0045  0.44
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## A1   382  0.76  0.74  0.69   0.59  3.7 1.13
## A2   382  0.71  0.71  0.64   0.54  3.9 1.00
## A3   382  0.74  0.72  0.66   0.57  3.8 1.08
## A5   382  0.67  0.69  0.60   0.52  3.9 0.87
## A6   382  0.72  0.73  0.67   0.57  3.7 0.92
## A10- 382  0.41  0.40  0.19   0.17  2.6 1.05
## 
## Non missing response frequency for each item
##        0    1    2    3    4    5 miss
## A1  0.01 0.03 0.12 0.14 0.47 0.23    0
## A2  0.01 0.02 0.06 0.18 0.48 0.26    0
## A3  0.01 0.03 0.08 0.15 0.47 0.25    0
## A5  0.00 0.01 0.05 0.17 0.52 0.25    0
## A6  0.01 0.02 0.05 0.25 0.49 0.18    0
## A10 0.01 0.17 0.43 0.21 0.15 0.03    0
psych::alpha(Conscientiousness,check.keys = TRUE)
## Warning in psych::alpha(Conscientiousness, check.keys = TRUE): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
## 
## Reliability analysis   
## Call: psych::alpha(x = Conscientiousness, check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N  ase mean   sd median_r
##       0.75      0.75    0.73      0.33 2.9 0.02  2.2 0.79     0.33
## 
##  lower alpha upper     95% confidence boundaries
## 0.71 0.75 0.79 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## C1-      0.74      0.74    0.71      0.36 2.8    0.021 0.0112  0.36
## C3-      0.73      0.73    0.70      0.35 2.7    0.022 0.0073  0.33
## C4-      0.72      0.72    0.69      0.34 2.5    0.022 0.0134  0.31
## C6       0.71      0.71    0.68      0.33 2.5    0.023 0.0079  0.32
## C8       0.68      0.68    0.64      0.29 2.1    0.026 0.0080  0.30
## C9       0.69      0.69    0.65      0.30 2.2    0.025 0.0078  0.31
## 
##  Item statistics 
##       n raw.r std.r r.cor r.drop mean  sd
## C1- 382  0.59  0.59  0.45   0.39  2.2 1.2
## C3- 382  0.58  0.61  0.49   0.41  1.6 1.0
## C4- 382  0.64  0.65  0.53   0.46  1.6 1.1
## C6  382  0.68  0.65  0.56   0.48  2.9 1.3
## C8  382  0.76  0.75  0.70   0.60  2.4 1.2
## C9  382  0.73  0.73  0.67   0.58  2.3 1.2
## 
## Non missing response frequency for each item
##       0    1    2    3    4    5 miss
## C1 0.01 0.12 0.30 0.26 0.23 0.09    0
## C3 0.01 0.03 0.13 0.26 0.47 0.10    0
## C4 0.02 0.05 0.18 0.20 0.44 0.12    0
## C6 0.01 0.14 0.30 0.21 0.21 0.13    0
## C8 0.00 0.31 0.30 0.20 0.12 0.08    0
## C9 0.01 0.27 0.37 0.15 0.15 0.05    0
psych::alpha(Neuroticism,check.keys = TRUE)
## 
## Reliability analysis   
## Call: psych::alpha(x = Neuroticism, check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean  sd median_r
##        0.8       0.8    0.78       0.4   4 0.016  3.5 0.8     0.39
## 
##  lower alpha upper     95% confidence boundaries
## 0.77 0.8 0.83 
## 
##  Reliability if an item is dropped:
##    raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## N1      0.76      0.76    0.73      0.39 3.2    0.019 0.0057  0.38
## N2      0.77      0.77    0.74      0.40 3.4    0.018 0.0078  0.38
## N4      0.75      0.75    0.71      0.38 3.1    0.020 0.0021  0.39
## N5      0.79      0.79    0.76      0.43 3.7    0.017 0.0049  0.41
## N6      0.76      0.76    0.72      0.38 3.1    0.020 0.0045  0.37
## N7      0.78      0.78    0.75      0.42 3.6    0.018 0.0053  0.40
## 
##  Item statistics 
##      n raw.r std.r r.cor r.drop mean   sd
## N1 382  0.74  0.74  0.67   0.59  2.8 1.22
## N2 382  0.70  0.70  0.60   0.54  3.6 1.17
## N4 382  0.76  0.76  0.71   0.62  3.3 1.16
## N5 382  0.66  0.65  0.53   0.48  3.7 1.21
## N6 382  0.74  0.74  0.68   0.61  3.7 1.10
## N7 382  0.63  0.66  0.55   0.49  4.1 0.95
## 
## Non missing response frequency for each item
##       0    1    2    3    4    5 miss
## N1 0.01 0.12 0.33 0.23 0.21 0.10    0
## N2 0.02 0.02 0.17 0.20 0.36 0.23    0
## N4 0.01 0.05 0.17 0.28 0.34 0.15    0
## N5 0.01 0.04 0.15 0.12 0.39 0.29    0
## N6 0.01 0.03 0.10 0.19 0.42 0.24    0
## N7 0.01 0.01 0.06 0.12 0.43 0.38    0
psych::alpha(Openness,check.keys = TRUE) #for illustrative proposes
## Warning in psych::alpha(Openness, check.keys = TRUE): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
## 
## Reliability analysis   
## Call: psych::alpha(x = Openness, check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N  ase mean   sd median_r
##       0.73      0.73    0.72      0.31 2.7 0.02  2.6 0.79     0.29
## 
##  lower alpha upper     95% confidence boundaries
## 0.69 0.73 0.77 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## O3-      0.73      0.72    0.70      0.34 2.6    0.021 0.022  0.34
## O4-      0.74      0.73    0.71      0.35 2.7    0.020 0.025  0.37
## O7       0.68      0.67    0.66      0.29 2.0    0.025 0.028  0.23
## O8       0.64      0.64    0.62      0.26 1.8    0.029 0.014  0.25
## O9       0.66      0.66    0.64      0.28 1.9    0.027 0.018  0.26
## O10      0.71      0.71    0.69      0.32 2.4    0.023 0.018  0.29
## 
##  Item statistics 
##       n raw.r std.r r.cor r.drop mean  sd
## O3- 382  0.52  0.56  0.42   0.34  1.4 1.0
## O4- 382  0.52  0.54  0.38   0.32  1.5 1.1
## O7  382  0.70  0.70  0.61   0.52  2.9 1.2
## O8  382  0.79  0.77  0.74   0.64  3.1 1.4
## O9  382  0.75  0.73  0.68   0.58  3.1 1.3
## O10 382  0.61  0.61  0.49   0.42  3.5 1.2
## 
## Non missing response frequency for each item
##        0    1    2    3    4    5 miss
## O3  0.01 0.03 0.10 0.20 0.52 0.13    0
## O4  0.01 0.04 0.15 0.26 0.37 0.18    0
## O7  0.01 0.12 0.33 0.18 0.29 0.07    0
## O8  0.01 0.13 0.21 0.16 0.31 0.17    0
## O9  0.01 0.12 0.25 0.15 0.34 0.13    0
## O10 0.01 0.05 0.16 0.14 0.47 0.17    0