setwd("~/Dropbox/Teaching_MRes_Northumbria/Lecture7")
require(haven)
## Loading required package: haven
in_class<-read_spss('https://stats.idre.ucla.edu/wp-content/uploads/2016/02/M255.sav')
require(dplyr)
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
in_class_red<- select(in_class, num_range("ITEM",13:24))
require(skimr)
## Loading required package: skimr
## 
## Attaching package: 'skimr'
## The following object is masked from 'package:stats':
## 
##     filter
skim(in_class_red)
require(psych)
## Loading required package: psych
KMO(in_class_red)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = in_class_red)
## Overall MSA =  0.94
## MSA for each item = 
## ITEM13 ITEM14 ITEM15 ITEM16 ITEM17 ITEM18 ITEM19 ITEM20 ITEM21 ITEM22 
##   0.93   0.92   0.94   0.94   0.96   0.92   0.91   0.96   0.96   0.96 
## ITEM23 ITEM24 
##   0.92   0.91
fa_6<-fa(in_class_red,6, fm = 'minres', rotate='varimax', fa = 'fa')
sink('fa6_Sidanius.txt')
fa_6
## Factor Analysis using method =  minres
## Call: fa(r = in_class_red, nfactors = 6, rotate = "varimax", fm = "minres", 
##     fa = "fa")
## Standardized loadings (pattern matrix) based upon correlation matrix
##         MR2  MR6  MR3  MR4   MR1   MR5   h2   u2 com
## ITEM13 0.19 0.66 0.24 0.28  0.12  0.08 0.63 0.37 2.0
## ITEM14 0.22 0.84 0.19 0.15 -0.04 -0.12 0.83 0.17 1.4
## ITEM15 0.30 0.64 0.21 0.20  0.16  0.10 0.62 0.38 2.1
## ITEM16 0.22 0.36 0.17 0.80  0.05  0.00 0.85 0.15 1.7
## ITEM17 0.42 0.46 0.28 0.33  0.21  0.13 0.64 0.36 4.2
## ITEM18 0.78 0.26 0.21 0.12 -0.03  0.11 0.74 0.26 1.5
## ITEM19 0.73 0.14 0.13 0.11  0.06 -0.07 0.59 0.41 1.2
## ITEM20 0.54 0.20 0.16 0.12  0.04  0.08 0.37 0.63 1.6
## ITEM21 0.52 0.32 0.29 0.17  0.38  0.00 0.63 0.37 3.6
## ITEM22 0.55 0.17 0.28 0.14  0.15 -0.06 0.46 0.54 2.1
## ITEM23 0.40 0.44 0.59 0.12  0.15  0.08 0.75 0.25 3.0
## ITEM24 0.30 0.26 0.75 0.17  0.03 -0.01 0.76 0.24 1.7
## 
##                        MR2  MR6  MR3  MR4  MR1  MR5
## SS loadings           2.64 2.41 1.41 1.02 0.29 0.08
## Proportion Var        0.22 0.20 0.12 0.09 0.02 0.01
## Cumulative Var        0.22 0.42 0.54 0.62 0.65 0.65
## Proportion Explained  0.34 0.31 0.18 0.13 0.04 0.01
## Cumulative Proportion 0.34 0.64 0.82 0.95 0.99 1.00
## 
## Mean item complexity =  2.2
## Test of the hypothesis that 6 factors are sufficient.
## 
## The degrees of freedom for the null model are  66  and the objective function was  6.43 with Chi Square of  9147.29
## The degrees of freedom for the model are 9  and the objective function was  0.01 
## 
## The root mean square of the residuals (RMSR) is  0 
## The df corrected root mean square of the residuals is  0.01 
## 
## The harmonic number of observations is  1412 with the empirical chi square  2.01  with prob <  0.99 
## The total number of observations was  1428  with Likelihood Chi Square =  8.36  with prob <  0.5 
## 
## Tucker Lewis Index of factoring reliability =  1.001
## RMSEA index =  0  and the 90 % confidence intervals are  0 0.028
## BIC =  -57.01
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    MR2  MR6  MR3  MR4
## Correlation of (regression) scores with factors   0.88 0.89 0.83 0.87
## Multiple R square of scores with factors          0.77 0.80 0.68 0.76
## Minimum correlation of possible factor scores     0.54 0.60 0.36 0.52
##                                                     MR1   MR5
## Correlation of (regression) scores with factors    0.57  0.43
## Multiple R square of scores with factors           0.33  0.19
## Minimum correlation of possible factor scores     -0.35 -0.63
sink()
fa.parallel(in_class_red, fm = 'minres', fa = 'fa')

## Parallel analysis suggests that the number of factors =  3  and the number of components =  NA
require(labelled)
## Loading required package: labelled
fa_3_sid<-fa(in_class_red,3, fm = 'minres', rotate='varimax', fa = 'fa')
sink('fa_3_sidanius_output.txt')
fa_3_sid
## Factor Analysis using method =  minres
## Call: fa(r = in_class_red, nfactors = 3, rotate = "varimax", fm = "minres", 
##     fa = "fa")
## Standardized loadings (pattern matrix) based upon correlation matrix
##         MR1  MR2  MR3   h2   u2 com
## ITEM13 0.77 0.18 0.23 0.67 0.33 1.3
## ITEM14 0.74 0.21 0.21 0.64 0.36 1.3
## ITEM15 0.69 0.30 0.22 0.61 0.39 1.6
## ITEM16 0.58 0.28 0.19 0.45 0.55 1.7
## ITEM17 0.59 0.44 0.29 0.62 0.38 2.4
## ITEM18 0.29 0.74 0.22 0.68 0.32 1.5
## ITEM19 0.17 0.74 0.13 0.59 0.41 1.2
## ITEM20 0.23 0.54 0.16 0.37 0.63 1.6
## ITEM21 0.40 0.53 0.33 0.54 0.46 2.6
## ITEM22 0.22 0.56 0.30 0.45 0.55 1.9
## ITEM23 0.46 0.38 0.66 0.78 0.22 2.4
## ITEM24 0.33 0.32 0.66 0.64 0.36 2.0
## 
##                        MR1  MR2  MR3
## SS loadings           2.98 2.65 1.42
## Proportion Var        0.25 0.22 0.12
## Cumulative Var        0.25 0.47 0.59
## Proportion Explained  0.42 0.38 0.20
## Cumulative Proportion 0.42 0.80 1.00
## 
## Mean item complexity =  1.8
## Test of the hypothesis that 3 factors are sufficient.
## 
## The degrees of freedom for the null model are  66  and the objective function was  6.43 with Chi Square of  9147.29
## The degrees of freedom for the model are 33  and the objective function was  0.1 
## 
## The root mean square of the residuals (RMSR) is  0.02 
## The df corrected root mean square of the residuals is  0.02 
## 
## The harmonic number of observations is  1412 with the empirical chi square  47.53  with prob <  0.049 
## The total number of observations was  1428  with Likelihood Chi Square =  140.51  with prob <  3.2e-15 
## 
## Tucker Lewis Index of factoring reliability =  0.976
## RMSEA index =  0.048  and the 90 % confidence intervals are  0.04 0.056
## BIC =  -99.2
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    MR1  MR2  MR3
## Correlation of (regression) scores with factors   0.88 0.87 0.79
## Multiple R square of scores with factors          0.78 0.75 0.63
## Minimum correlation of possible factor scores     0.55 0.50 0.25
sink()