##load packages
library(psych)
library(GPArotation)
library(plyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# data preparation
data <- read.csv("~/Psychometric_study_data/allsurveysT1.csv")
purposescales<-select(data, PWB_1, PWB_2, PWB_3, PWB_4, PWB_5, PWB_6, PWB_7, PWB_8, PWB_9, APSI_1, APSI_2,  APSI_3,  APSI_4,  APSI_5,  APSI_6, APSI_7, APSI_8, LET_1, LET_2, LET_3,  LET_4,  LET_5,  LET_6, MLQ_1, MLQ_2, MLQ_3, MLQ_4, MLQ_5, MLQ_6,MLQ_7, MLQ_8, MLQ_9, MLQ_10)
purposescales$PWB_1  <-  7- purposescales$PWB_1
purposescales$PWB_2  <-  7- purposescales$PWB_2
purposescales$PWB_3  <-  7- purposescales$PWB_3
purposescales$PWB_4  <-  7- purposescales$PWB_4
purposescales$PWB_9  <-  7- purposescales$PWB_9
purposescales$MLQ_9  <-  8- purposescales$MLQ_9
purposescales$LET_1  <-  6- purposescales$LET_1
purposescales$LET_3  <-  6- purposescales$LET_3
purposescales$LET_5  <-  6- purposescales$LET_5
purposescales<- data.frame(apply(purposescales,2, as.numeric))
purposescales<-tbl_df(purposescales)
purposescales
## Source: local data frame [757 x 33]
## 
##    PWB_1 PWB_2 PWB_3 PWB_4 PWB_5 PWB_6 PWB_7 PWB_8 PWB_9 APSI_1 APSI_2
## 1      4     3     5     2     4     5     4     3     6      2      4
## 2      4     5     5     2     2     5     3     2     5      4      3
## 3      5     6     5     6     1     4     6     3     6      3      4
## 4      2     2     4     4     3     4     5     4     4      4      4
## 5      2     2     3     3     4     3     2     3     4      3      3
## 6      5     4     6     5     3     4     3     4     6      3      4
## 7      2     2     5     2     1     4     3     3     3      2      2
## 8      6     6     5     1     2     4     4     4     6      3      3
## 9      5     5     5     5     1     5     5     5     6      4      5
## 10     6     6     3     3     2     6     6     3     6      2      2
## ..   ...   ...   ...   ...   ...   ...   ...   ...   ...    ...    ...
## Variables not shown: APSI_3 (dbl), APSI_4 (dbl), APSI_5 (dbl), APSI_6
##   (dbl), APSI_7 (dbl), APSI_8 (dbl), LET_1 (dbl), LET_2 (dbl), LET_3
##   (dbl), LET_4 (dbl), LET_5 (dbl), LET_6 (dbl), MLQ_1 (dbl), MLQ_2 (dbl),
##   MLQ_3 (dbl), MLQ_4 (dbl), MLQ_5 (dbl), MLQ_6 (dbl), MLQ_7 (dbl), MLQ_8
##   (dbl), MLQ_9 (dbl), MLQ_10 (dbl)
str(purposescales)
## Classes 'tbl_df', 'tbl' and 'data.frame':    757 obs. of  33 variables:
##  $ PWB_1 : num  4 4 5 2 2 5 2 6 5 6 ...
##  $ PWB_2 : num  3 5 6 2 2 4 2 6 5 6 ...
##  $ PWB_3 : num  5 5 5 4 3 6 5 5 5 3 ...
##  $ PWB_4 : num  2 2 6 4 3 5 2 1 5 3 ...
##  $ PWB_5 : num  4 2 1 3 4 3 1 2 1 2 ...
##  $ PWB_6 : num  5 5 4 4 3 4 4 4 5 6 ...
##  $ PWB_7 : num  4 3 6 5 2 3 3 4 5 6 ...
##  $ PWB_8 : num  3 2 3 4 3 4 3 4 5 3 ...
##  $ PWB_9 : num  6 5 6 4 4 6 3 6 6 6 ...
##  $ APSI_1: num  2 4 3 4 3 3 2 3 4 2 ...
##  $ APSI_2: num  4 3 4 4 3 4 2 3 5 2 ...
##  $ APSI_3: num  4 4 4 5 4 4 4 4 5 2 ...
##  $ APSI_4: num  4 5 3 4 3 4 3 3 4 3 ...
##  $ APSI_5: num  4 4 3 5 4 4 4 5 4 5 ...
##  $ APSI_6: num  4 3 3 4 3 2 4 3 2 3 ...
##  $ APSI_7: num  4 4 4 4 2 5 2 3 4 3 ...
##  $ APSI_8: num  4 4 3 3 3 3 2 1 5 4 ...
##  $ LET_1 : num  4 3 3 1 3 5 3 3 5 3 ...
##  $ LET_2 : num  4 3 4 4 2 5 4 4 4 3 ...
##  $ LET_3 : num  4 4 3 4 3 5 2 3 5 5 ...
##  $ LET_4 : num  5 4 4 4 4 5 3 4 5 5 ...
##  $ LET_5 : num  5 4 4 4 2 5 3 4 5 5 ...
##  $ LET_6 : num  5 5 5 4 4 4 5 5 5 5 ...
##  $ MLQ_1 : num  4 3 4 5 4 5 6 3 6 1 ...
##  $ MLQ_2 : num  7 5 7 6 6 5 2 7 5 7 ...
##  $ MLQ_3 : num  7 5 5 7 5 3 2 7 2 1 ...
##  $ MLQ_4 : num  5 5 4 3 4 4 3 5 7 3 ...
##  $ MLQ_5 : num  6 4 4 5 4 5 6 5 6 5 ...
##  $ MLQ_6 : num  4 3 4 5 4 5 3 4 6 1 ...
##  $ MLQ_7 : num  5 5 4 5 5 3 5 5 5 5 ...
##  $ MLQ_8 : num  7 4 5 5 5 4 4 7 7 5 ...
##  $ MLQ_9 : num  3 3 4 3 5 7 5 4 7 6 ...
##  $ MLQ_10: num  7 5 4 6 5 3 4 5 2 1 ...
colnames(purposescales) <- c("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33")
#purposescales<- purposescales[complete.cases(purposescales[,]),]
##EFA
##number of factors
##parallal analysis and scree plot
parallel<-fa.parallel(purposescales, fm="ml",fa="fa")

## Parallel analysis suggests that the number of factors =  5  and the number of components =  NA
#two factors are greater than one Eigenvalue scree plot says there are two factors. Paralel analysis suggests 4 factors
#eigenvalues (kaiser)
parallel$fa.values
##  [1]  7.86492483  6.11092669  2.15452487  0.67489536  0.47121242
##  [6]  0.22914309  0.17898852  0.12511231  0.01864097 -0.02040029
## [11] -0.08284879 -0.09406141 -0.13655348 -0.15699714 -0.16493689
## [16] -0.22067990 -0.24666433 -0.32352263 -0.34405605 -0.39602304
## [21] -0.44555951 -0.48643807 -0.50761022 -0.54271424 -0.59219248
## [26] -0.59872898 -0.62150523 -0.62816232 -0.65326968 -0.70223466
## [31] -0.73574460 -0.74417600 -0.78119902
#over 1=2, over .7=2
#doign aprincipal components analysis to see how many factors there might be using that method
#Deal with NA doing principle componant analysis
princomp(na.omit(purposescales), cor = TRUE)
## Call:
## princomp(x = na.omit(purposescales), cor = TRUE)
## 
## Standard deviations:
##    Comp.1    Comp.2    Comp.3    Comp.4    Comp.5    Comp.6    Comp.7 
## 2.9123873 2.6344008 1.7625717 1.2284666 1.1162543 0.9615061 0.8959260 
##    Comp.8    Comp.9   Comp.10   Comp.11   Comp.12   Comp.13   Comp.14 
## 0.8575081 0.8423550 0.7797400 0.7509777 0.7333973 0.7113940 0.6911814 
##   Comp.15   Comp.16   Comp.17   Comp.18   Comp.19   Comp.20   Comp.21 
## 0.6717013 0.6529565 0.6386146 0.6227516 0.6102691 0.6086141 0.5933355 
##   Comp.22   Comp.23   Comp.24   Comp.25   Comp.26   Comp.27   Comp.28 
## 0.5858159 0.5703668 0.5557393 0.5464648 0.5247000 0.5022309 0.4988762 
##   Comp.29   Comp.30   Comp.31   Comp.32   Comp.33 
## 0.4852249 0.4573967 0.4529373 0.4432153 0.4286089 
## 
##  33  variables and  470 observations.
parallel2<-princomp(na.omit(purposescales), cor = TRUE)
summary(parallel2)
## Importance of components:
##                           Comp.1    Comp.2     Comp.3     Comp.4
## Standard deviation     2.9123873 2.6344008 1.76257166 1.22846658
## Proportion of Variance 0.2570303 0.2103051 0.09414118 0.04573122
## Cumulative Proportion  0.2570303 0.4673354 0.56147655 0.60720777
##                            Comp.5     Comp.6     Comp.7     Comp.8
## Standard deviation     1.11625426 0.96150614 0.89592600 0.85750805
## Proportion of Variance 0.03775829 0.02801497 0.02432374 0.02228243
## Cumulative Proportion  0.64496606 0.67298103 0.69730477 0.71958719
##                            Comp.9    Comp.10    Comp.11    Comp.12
## Standard deviation     0.84235502 0.77974004 0.75097766 0.73339727
## Proportion of Variance 0.02150188 0.01842408 0.01708992 0.01629914
## Cumulative Proportion  0.74108907 0.75951315 0.77660307 0.79290221
##                          Comp.13    Comp.14   Comp.15    Comp.16
## Standard deviation     0.7113940 0.69118137 0.6717013 0.65295652
## Proportion of Variance 0.0153358 0.01447672 0.0136722 0.01291976
## Cumulative Proportion  0.8082380 0.82271473 0.8363869 0.84930669
##                           Comp.17    Comp.18    Comp.19    Comp.20
## Standard deviation     0.63861463 0.62275155 0.61026912 0.60861414
## Proportion of Variance 0.01235844 0.01175211 0.01128571 0.01122458
## Cumulative Proportion  0.86166514 0.87341724 0.88470295 0.89592753
##                           Comp.21   Comp.22     Comp.23     Comp.24
## Standard deviation     0.59333548 0.5858159 0.570366778 0.555739320
## Proportion of Variance 0.01066809 0.0103994 0.009858129 0.009358976
## Cumulative Proportion  0.90659562 0.9169950 0.926853154 0.936212129
##                            Comp.25    Comp.26     Comp.27     Comp.28
## Standard deviation     0.546464760 0.52470002 0.502230900 0.498876228
## Proportion of Variance 0.009049204 0.00834273 0.007643511 0.007541742
## Cumulative Proportion  0.945261333 0.95360406 0.961247575 0.968789317
##                            Comp.29    Comp.30     Comp.31     Comp.32
## Standard deviation     0.485224883 0.45739670 0.452937343 0.443215287
## Proportion of Variance 0.007134642 0.00633975 0.006216734 0.005952721
## Cumulative Proportion  0.975923960 0.98226371 0.988480444 0.994433165
##                            Comp.33
## Standard deviation     0.428608872
## Proportion of Variance 0.005566835
## Cumulative Proportion  1.000000000
plot(parallel2)##results show at least two factors

#simple structure
twofactor<-fa(purposescales, nfactors=2, rotate="oblimin", fm="ml")
twofactor
## Factor Analysis using method =  ml
## Call: fa(r = purposescales, nfactors = 2, rotate = "oblimin", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      ML1   ML2    h2   u2 com
## 1  -0.29  0.57 0.396 0.60 1.5
## 2   0.06  0.36 0.132 0.87 1.1
## 3  -0.02  0.83 0.682 0.32 1.0
## 4   0.41  0.53 0.466 0.53 1.9
## 5  -0.02 -0.76 0.579 0.42 1.0
## 6   0.07  0.62 0.388 0.61 1.0
## 7   0.72  0.01 0.525 0.47 1.0
## 8   0.70  0.16 0.526 0.47 1.1
## 9   0.11  0.28 0.096 0.90 1.3
## 10  0.87 -0.10 0.760 0.24 1.0
## 11  0.77 -0.10 0.596 0.40 1.0
## 12  0.07  0.43 0.189 0.81 1.1
## 13  0.79 -0.11 0.631 0.37 1.0
## 14  0.64 -0.24 0.453 0.55 1.3
## 15  0.11 -0.84 0.709 0.29 1.0
## 16  0.78 -0.07 0.605 0.39 1.0
## 17  0.83 -0.10 0.691 0.31 1.0
## 18  0.15  0.69 0.500 0.50 1.1
## 19  0.68 -0.05 0.467 0.53 1.0
## 20 -0.12  0.83 0.701 0.30 1.0
## 21  0.60 -0.03 0.355 0.64 1.0
## 22 -0.20  0.81 0.686 0.31 1.1
## 23  0.36  0.46 0.349 0.65 1.9
## 24  0.47  0.41 0.404 0.60 2.0
## 25 -0.01 -0.34 0.119 0.88 1.0
## 26  0.14 -0.30 0.106 0.89 1.4
## 27  0.72  0.22 0.577 0.42 1.2
## 28  0.47  0.45 0.440 0.56 2.0
## 29  0.70  0.23 0.564 0.44 1.2
## 30  0.03 -0.18 0.034 0.97 1.0
## 31  0.04 -0.23 0.053 0.95 1.0
## 32  0.16  0.71 0.541 0.46 1.1
## 33 -0.13 -0.30 0.108 0.89 1.4
## 
##                        ML1  ML2
## SS loadings           7.53 6.90
## Proportion Var        0.23 0.21
## Cumulative Var        0.23 0.44
## Proportion Explained  0.52 0.48
## Cumulative Proportion 0.52 1.00
## 
##  With factor correlations of 
##      ML1  ML2
## ML1 1.00 0.04
## ML2 0.04 1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  528  and the objective function was  21.35 with Chi Square of  15888.56
## The degrees of freedom for the model are 463  and the objective function was  5.77 
## 
## The root mean square of the residuals (RMSR) is  0.09 
## The df corrected root mean square of the residuals is  0.1 
## 
## The harmonic number of observations is  472 with the empirical chi square  4082.05  with prob <  0 
## The total number of observations was  757  with MLE Chi Square =  4284.8  with prob <  0 
## 
## Tucker Lewis Index of factoring reliability =  0.716
## RMSEA index =  0.106  and the 90 % confidence intervals are  0.102 0.107
## BIC =  1215.41
## Fit based upon off diagonal values = 0.92
## Measures of factor score adequacy             
##                                                 ML1  ML2
## Correlation of scores with factors             0.97 0.97
## Multiple R square of scores with factors       0.95 0.94
## Minimum correlation of possible factor scores  0.90 0.89
threefactor<-fa(purposescales, nfactors=3, rotate="oblimin", fm="ml")
threefactor
## Factor Analysis using method =  ml
## Call: fa(r = purposescales, nfactors = 3, rotate = "oblimin", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      ML1   ML2   ML3    h2   u2 com
## 1  -0.29  0.58  0.00 0.402 0.60 1.5
## 2   0.06  0.33 -0.07 0.131 0.87 1.2
## 3  -0.02  0.82 -0.02 0.685 0.32 1.0
## 4   0.41  0.49 -0.11 0.465 0.53 2.0
## 5  -0.01 -0.76  0.00 0.587 0.41 1.0
## 6   0.06  0.67  0.13 0.433 0.57 1.1
## 7   0.72  0.03  0.06 0.528 0.47 1.0
## 8   0.70  0.16 -0.02 0.525 0.48 1.1
## 9   0.11  0.29  0.03 0.098 0.90 1.3
## 10  0.87 -0.12 -0.05 0.767 0.23 1.0
## 11  0.77 -0.11 -0.03 0.598 0.40 1.0
## 12  0.07  0.47  0.10 0.214 0.79 1.1
## 13  0.79 -0.13 -0.04 0.633 0.37 1.1
## 14  0.64 -0.21  0.08 0.456 0.54 1.2
## 15  0.11 -0.82  0.08 0.710 0.29 1.1
## 16  0.78 -0.06  0.03 0.604 0.40 1.0
## 17  0.83 -0.11 -0.04 0.691 0.31 1.0
## 18  0.15  0.62 -0.20 0.514 0.49 1.3
## 19  0.69 -0.05 -0.01 0.469 0.53 1.0
## 20 -0.13  0.81 -0.08 0.697 0.30 1.1
## 21  0.60 -0.02  0.02 0.355 0.65 1.0
## 22 -0.21  0.81  0.00 0.693 0.31 1.1
## 23  0.35  0.50  0.10 0.373 0.63 1.9
## 24  0.46  0.44  0.05 0.417 0.58 2.0
## 25 -0.02 -0.09  0.77 0.634 0.37 1.0
## 26  0.13 -0.06  0.73 0.578 0.42 1.1
## 27  0.72  0.24  0.03 0.581 0.42 1.2
## 28  0.46  0.50  0.12 0.474 0.53 2.1
## 29  0.70  0.24  0.00 0.567 0.43 1.2
## 30  0.02  0.07  0.75 0.546 0.45 1.0
## 31  0.03  0.03  0.77 0.583 0.42 1.0
## 32  0.15  0.66 -0.16 0.545 0.46 1.2
## 33 -0.14 -0.03  0.81 0.692 0.31 1.1
## 
##                        ML1  ML2  ML3
## SS loadings           7.53 6.54 3.17
## Proportion Var        0.23 0.20 0.10
## Cumulative Var        0.23 0.43 0.52
## Proportion Explained  0.44 0.38 0.18
## Cumulative Proportion 0.44 0.82 1.00
## 
##  With factor correlations of 
##      ML1   ML2   ML3
## ML1 1.00  0.04  0.00
## ML2 0.04  1.00 -0.24
## ML3 0.00 -0.24  1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 3 factors are sufficient.
## 
## The degrees of freedom for the null model are  528  and the objective function was  21.35 with Chi Square of  15888.56
## The degrees of freedom for the model are 432  and the objective function was  3.26 
## 
## The root mean square of the residuals (RMSR) is  0.04 
## The df corrected root mean square of the residuals is  0.05 
## 
## The harmonic number of observations is  472 with the empirical chi square  1000.77  with prob <  4.1e-47 
## The total number of observations was  757  with MLE Chi Square =  2418.39  with prob <  1e-272 
## 
## Tucker Lewis Index of factoring reliability =  0.842
## RMSEA index =  0.079  and the 90 % confidence intervals are  0.075 0.081
## BIC =  -445.5
## Fit based upon off diagonal values = 0.98
## Measures of factor score adequacy             
##                                                 ML1  ML2  ML3
## Correlation of scores with factors             0.97 0.97 0.94
## Multiple R square of scores with factors       0.95 0.94 0.89
## Minimum correlation of possible factor scores  0.90 0.88 0.78
fourfactor<-fa(purposescales, nfactors=4, rotate="oblimin", fm="ml")
fourfactor
## Factor Analysis using method =  ml
## Call: fa(r = purposescales, nfactors = 4, rotate = "oblimin", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      ML1   ML2   ML3   ML4   h2   u2 com
## 1  -0.13  0.67  0.02 -0.21 0.45 0.55 1.3
## 2   0.21  0.44 -0.06 -0.21 0.19 0.81 2.0
## 3  -0.01  0.81 -0.02  0.04 0.69 0.31 1.0
## 4   0.39  0.49 -0.11  0.08 0.47 0.53 2.1
## 5  -0.08 -0.80  0.00  0.04 0.62 0.38 1.0
## 6   0.05  0.65  0.13  0.08 0.44 0.56 1.1
## 7   0.69  0.06  0.06  0.08 0.53 0.47 1.1
## 8   0.70  0.20 -0.01  0.04 0.54 0.46 1.2
## 9   0.34  0.47  0.05 -0.31 0.21 0.79 2.7
## 10  0.78 -0.13 -0.06  0.15 0.76 0.24 1.1
## 11  0.74 -0.07 -0.03  0.05 0.60 0.40 1.0
## 12  0.03  0.44  0.10  0.09 0.22 0.78 1.2
## 13  0.75 -0.09 -0.04  0.07 0.64 0.36 1.1
## 14  0.73 -0.09  0.09 -0.13 0.50 0.50 1.1
## 15  0.18 -0.74  0.08 -0.17 0.71 0.29 1.3
## 16  0.78  0.00  0.03  0.02 0.62 0.38 1.0
## 17  0.85 -0.04 -0.03 -0.01 0.72 0.28 1.0
## 18  0.06  0.55 -0.21  0.18 0.51 0.49 1.5
## 19  0.60 -0.07 -0.01  0.15 0.47 0.53 1.2
## 20 -0.12  0.78 -0.09  0.05 0.69 0.31 1.1
## 21  0.59  0.02  0.03  0.02 0.36 0.64 1.0
## 22 -0.18  0.80  0.00  0.02 0.70 0.30 1.1
## 23  0.30  0.48  0.09  0.12 0.37 0.63 2.0
## 24  0.02  0.13  0.01  0.74 0.64 0.36 1.1
## 25  0.02 -0.05  0.78 -0.06 0.64 0.36 1.0
## 26  0.10 -0.07  0.73  0.06 0.58 0.42 1.1
## 27  0.38  0.03  0.00  0.56 0.68 0.32 1.8
## 28  0.13  0.28  0.10  0.56 0.57 0.43 1.7
## 29  0.34  0.01 -0.03  0.61 0.69 0.31 1.6
## 30 -0.08  0.00  0.75  0.18 0.56 0.44 1.1
## 31  0.07  0.06  0.78 -0.04 0.59 0.41 1.0
## 32  0.04  0.57 -0.17  0.23 0.55 0.45 1.5
## 33 -0.11 -0.01  0.82 -0.03 0.69 0.31 1.0
## 
##                        ML1  ML2  ML3  ML4
## SS loadings           6.42 6.05 3.20 2.52
## Proportion Var        0.19 0.18 0.10 0.08
## Cumulative Var        0.19 0.38 0.47 0.55
## Proportion Explained  0.35 0.33 0.18 0.14
## Cumulative Proportion 0.35 0.69 0.86 1.00
## 
##  With factor correlations of 
##       ML1   ML2   ML3   ML4
## ML1  1.00 -0.06  0.00  0.48
## ML2 -0.06  1.00 -0.25  0.32
## ML3  0.00 -0.25  1.00 -0.08
## ML4  0.48  0.32 -0.08  1.00
## 
## Mean item complexity =  1.3
## Test of the hypothesis that 4 factors are sufficient.
## 
## The degrees of freedom for the null model are  528  and the objective function was  21.35 with Chi Square of  15888.56
## The degrees of freedom for the model are 402  and the objective function was  2.5 
## 
## The root mean square of the residuals (RMSR) is  0.04 
## The df corrected root mean square of the residuals is  0.04 
## 
## The harmonic number of observations is  472 with the empirical chi square  655.09  with prob <  2e-14 
## The total number of observations was  757  with MLE Chi Square =  1856.01  with prob <  4.9e-185 
## 
## Tucker Lewis Index of factoring reliability =  0.875
## RMSEA index =  0.07  and the 90 % confidence intervals are  0.066 0.072
## BIC =  -808.99
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy             
##                                                 ML1  ML2  ML3  ML4
## Correlation of scores with factors             0.97 0.97 0.94 0.92
## Multiple R square of scores with factors       0.94 0.94 0.89 0.85
## Minimum correlation of possible factor scores  0.88 0.87 0.78 0.70
fivefactor<-fa(purposescales, nfactors=5, rotate="oblimin", fm="ml")
fivefactor
## Factor Analysis using method =  ml
## Call: fa(r = purposescales, nfactors = 5, rotate = "oblimin", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      ML1   ML2   ML3   ML4   ML5   h2   u2 com
## 1  -0.13  0.62 -0.01 -0.19  0.18 0.46 0.54 1.5
## 2   0.17  0.51 -0.02 -0.21 -0.15 0.23 0.77 1.8
## 3  -0.03  0.78 -0.03  0.06  0.07 0.69 0.31 1.0
## 4   0.33  0.57 -0.06  0.08 -0.23 0.54 0.46 2.0
## 5  -0.06 -0.76  0.01  0.02 -0.12 0.61 0.39 1.1
## 6   0.05  0.56  0.09  0.11  0.24 0.46 0.54 1.5
## 7   0.68  0.07  0.06  0.09 -0.03 0.53 0.47 1.1
## 8   0.68  0.19 -0.02  0.06  0.01 0.54 0.46 1.2
## 9   0.29  0.53  0.09 -0.31 -0.16 0.25 0.75 2.6
## 10  0.76 -0.09 -0.04  0.16 -0.13 0.77 0.23 1.2
## 11  0.76 -0.09 -0.04  0.06  0.05 0.62 0.38 1.1
## 12  0.13  0.26 -0.01  0.11  0.60 0.52 0.48 1.6
## 13  0.76 -0.12 -0.06  0.09  0.05 0.65 0.35 1.1
## 14  0.78 -0.14  0.05 -0.13  0.20 0.56 0.44 1.3
## 15  0.19 -0.69  0.10 -0.18 -0.14 0.72 0.28 1.4
## 16  0.76  0.00  0.03  0.04 -0.01 0.62 0.38 1.0
## 17  0.82 -0.02 -0.03  0.01 -0.07 0.71 0.29 1.0
## 18  0.01  0.60 -0.17  0.18 -0.17 0.56 0.44 1.5
## 19  0.56 -0.01  0.03  0.15 -0.20 0.49 0.51 1.4
## 20 -0.16  0.80 -0.06  0.05 -0.05 0.72 0.28 1.1
## 21  0.60 -0.01  0.00  0.04  0.09 0.38 0.62 1.1
## 22 -0.20  0.79  0.00  0.02  0.04 0.70 0.30 1.1
## 23  0.34  0.38  0.04  0.15  0.30 0.45 0.55 3.3
## 24  0.02  0.06 -0.01  0.78  0.13 0.68 0.32 1.1
## 25  0.00 -0.03  0.79 -0.06 -0.06 0.65 0.35 1.0
## 26  0.08 -0.04  0.75  0.06 -0.08 0.59 0.41 1.1
## 27  0.35  0.07  0.04  0.57 -0.17 0.70 0.30 1.9
## 28  0.14  0.23  0.08  0.58  0.12 0.59 0.41 1.6
## 29  0.31  0.04  0.00  0.62 -0.15 0.70 0.30 1.6
## 30 -0.09  0.00  0.75  0.18 -0.02 0.56 0.44 1.1
## 31  0.06  0.06  0.78 -0.04  0.01 0.59 0.41 1.0
## 32  0.01  0.58 -0.15  0.23 -0.05 0.55 0.45 1.5
## 33 -0.10 -0.04  0.80 -0.03  0.10 0.69 0.31 1.1
## 
##                        ML1  ML2  ML3  ML4  ML5
## SS loadings           6.33 5.85 3.18 2.69 1.02
## Proportion Var        0.19 0.18 0.10 0.08 0.03
## Cumulative Var        0.19 0.37 0.47 0.55 0.58
## Proportion Explained  0.33 0.31 0.17 0.14 0.05
## Cumulative Proportion 0.33 0.64 0.81 0.95 1.00
## 
##  With factor correlations of 
##       ML1   ML2   ML3   ML4   ML5
## ML1  1.00 -0.04  0.02  0.46 -0.17
## ML2 -0.04  1.00 -0.26  0.35  0.18
## ML3  0.02 -0.26  1.00 -0.08  0.07
## ML4  0.46  0.35 -0.08  1.00  0.01
## ML5 -0.17  0.18  0.07  0.01  1.00
## 
## Mean item complexity =  1.4
## Test of the hypothesis that 5 factors are sufficient.
## 
## The degrees of freedom for the null model are  528  and the objective function was  21.35 with Chi Square of  15888.56
## The degrees of freedom for the model are 373  and the objective function was  1.95 
## 
## The root mean square of the residuals (RMSR) is  0.03 
## The df corrected root mean square of the residuals is  0.03 
## 
## The harmonic number of observations is  472 with the empirical chi square  397.38  with prob <  0.18 
## The total number of observations was  757  with MLE Chi Square =  1447.91  with prob <  2.8e-126 
## 
## Tucker Lewis Index of factoring reliability =  0.9
## RMSEA index =  0.063  and the 90 % confidence intervals are  0.058 0.065
## BIC =  -1024.84
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy             
##                                                 ML1  ML2  ML3  ML4  ML5
## Correlation of scores with factors             0.97 0.97 0.94 0.93 0.82
## Multiple R square of scores with factors       0.94 0.94 0.89 0.86 0.68
## Minimum correlation of possible factor scores  0.88 0.87 0.79 0.73 0.36
#1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
 
#Create dataset for Target rotation
all_surveys<-read.csv("allsurveysT1.csv")
purposescales<-select(all_surveys,  PWB_7, PWB_8, APSI_1, APSI_2, APSI_4,  APSI_5, APSI_7,  APSI_8, LET_2, LET_4, PWB_1,  PWB_2,  PWB_3,  PWB_4,  PWB_5,  PWB_6,  PWB_9, APSI_3, APSI_6,  LET_1, LET_3,    LET_5,  LET_6, MLQ_9,  MLQ_2, MLQ_3, MLQ_7, MLQ_8,MLQ_10,    MLQ_1, MLQ_4, MLQ_5, MLQ_6)
purposescales$PWB_1  <-  7- purposescales$PWB_1
purposescales$PWB_2  <-  7- purposescales$PWB_2
purposescales$PWB_3  <-  7- purposescales$PWB_3
purposescales$PWB_4  <-  7- purposescales$PWB_4
purposescales$PWB_9  <-  7- purposescales$PWB_9
purposescales$MLQ_9  <-  8- purposescales$MLQ_9
purposescales$LET_1  <-  6- purposescales$LET_1
purposescales$LET_3  <-  6- purposescales$LET_3
purposescales$LET_5  <-  6- purposescales$LET_5
purposescales<- data.frame(apply(purposescales,2, as.numeric))
library(GPArotation)
library(psych)
library(dplyr)

purposescales<-tbl_df(purposescales)
purposescales
## Source: local data frame [757 x 33]
## 
##    PWB_7 PWB_8 APSI_1 APSI_2 APSI_4 APSI_5 APSI_7 APSI_8 LET_2 LET_4 PWB_1
## 1      4     3      2      4      4      4      4      4     4     5     4
## 2      3     2      4      3      5      4      4      4     3     4     4
## 3      6     3      3      4      3      3      4      3     4     4     5
## 4      5     4      4      4      4      5      4      3     4     4     2
## 5      2     3      3      3      3      4      2      3     2     4     2
## 6      3     4      3      4      4      4      5      3     5     5     5
## 7      3     3      2      2      3      4      2      2     4     3     2
## 8      4     4      3      3      3      5      3      1     4     4     6
## 9      5     5      4      5      4      4      4      5     4     5     5
## 10     6     3      2      2      3      5      3      4     3     5     6
## ..   ...   ...    ...    ...    ...    ...    ...    ...   ...   ...   ...
## Variables not shown: PWB_2 (dbl), PWB_3 (dbl), PWB_4 (dbl), PWB_5 (dbl),
##   PWB_6 (dbl), PWB_9 (dbl), APSI_3 (dbl), APSI_6 (dbl), LET_1 (dbl), LET_3
##   (dbl), LET_5 (dbl), LET_6 (dbl), MLQ_9 (dbl), MLQ_2 (dbl), MLQ_3 (dbl),
##   MLQ_7 (dbl), MLQ_8 (dbl), MLQ_10 (dbl), MLQ_1 (dbl), MLQ_4 (dbl), MLQ_5
##   (dbl), MLQ_6 (dbl)
str(purposescales)
## Classes 'tbl_df', 'tbl' and 'data.frame':    757 obs. of  33 variables:
##  $ PWB_7 : num  4 3 6 5 2 3 3 4 5 6 ...
##  $ PWB_8 : num  3 2 3 4 3 4 3 4 5 3 ...
##  $ APSI_1: num  2 4 3 4 3 3 2 3 4 2 ...
##  $ APSI_2: num  4 3 4 4 3 4 2 3 5 2 ...
##  $ APSI_4: num  4 5 3 4 3 4 3 3 4 3 ...
##  $ APSI_5: num  4 4 3 5 4 4 4 5 4 5 ...
##  $ APSI_7: num  4 4 4 4 2 5 2 3 4 3 ...
##  $ APSI_8: num  4 4 3 3 3 3 2 1 5 4 ...
##  $ LET_2 : num  4 3 4 4 2 5 4 4 4 3 ...
##  $ LET_4 : num  5 4 4 4 4 5 3 4 5 5 ...
##  $ PWB_1 : num  4 4 5 2 2 5 2 6 5 6 ...
##  $ PWB_2 : num  3 5 6 2 2 4 2 6 5 6 ...
##  $ PWB_3 : num  5 5 5 4 3 6 5 5 5 3 ...
##  $ PWB_4 : num  2 2 6 4 3 5 2 1 5 3 ...
##  $ PWB_5 : num  4 2 1 3 4 3 1 2 1 2 ...
##  $ PWB_6 : num  5 5 4 4 3 4 4 4 5 6 ...
##  $ PWB_9 : num  6 5 6 4 4 6 3 6 6 6 ...
##  $ APSI_3: num  4 4 4 5 4 4 4 4 5 2 ...
##  $ APSI_6: num  4 3 3 4 3 2 4 3 2 3 ...
##  $ LET_1 : num  4 3 3 1 3 5 3 3 5 3 ...
##  $ LET_3 : num  4 4 3 4 3 5 2 3 5 5 ...
##  $ LET_5 : num  5 4 4 4 2 5 3 4 5 5 ...
##  $ LET_6 : num  5 5 5 4 4 4 5 5 5 5 ...
##  $ MLQ_9 : num  3 3 4 3 5 7 5 4 7 6 ...
##  $ MLQ_2 : num  7 5 7 6 6 5 2 7 5 7 ...
##  $ MLQ_3 : num  7 5 5 7 5 3 2 7 2 1 ...
##  $ MLQ_7 : num  5 5 4 5 5 3 5 5 5 5 ...
##  $ MLQ_8 : num  7 4 5 5 5 4 4 7 7 5 ...
##  $ MLQ_10: num  7 5 4 6 5 3 4 5 2 1 ...
##  $ MLQ_1 : num  4 3 4 5 4 5 6 3 6 1 ...
##  $ MLQ_4 : num  5 5 4 3 4 4 3 5 7 3 ...
##  $ MLQ_5 : num  6 4 4 5 4 5 6 5 6 5 ...
##  $ MLQ_6 : num  4 3 4 5 4 5 3 4 6 1 ...
colnames(purposescales) <- c("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33")
#Target rotation: choose "simple structure" a priori and can be applied to oblique and orthogonal rotation based on 
#what paper says facotrs should be purposescales
Targ_key <- make.keys(33,list(f1=1:10,f2=11:24, f3=25:29,f4=30:33))
Targ_key <- scrub(Targ_key,isvalue=1)  #fix the 0s, allow the NAs to be estimated
Targ_key <- list(Targ_key)
out_targetQ <- fa(purposescales,4,rotate="TargetQ",Target=Targ_key) #TargetT for orthogonal rotation
out_targetQ[c("loadings", "score.cor", "TLI", "RMSEA")]
## $loadings
## 
## Loadings:
##    MR2    MR1    MR3    MR4   
## 1          0.671         0.102
## 2   0.221  0.668              
## 3  -0.113  0.761         0.192
## 4          0.732              
## 5          0.740         0.103
## 6          0.736        -0.114
## 7          0.762              
## 8          0.838              
## 9          0.578         0.180
## 10         0.576              
## 11  0.690 -0.140        -0.252
## 12  0.480  0.217        -0.243
## 13  0.814                     
## 14  0.507  0.350 -0.102       
## 15 -0.813                     
## 16  0.649         0.148       
## 17  0.504  0.339        -0.343
## 18  0.442         0.114       
## 19 -0.732  0.234        -0.156
## 20  0.547        -0.201  0.178
## 21  0.776 -0.171              
## 22  0.796 -0.228              
## 23  0.482  0.260  0.106  0.134
## 24  0.563        -0.156  0.234
## 25                0.772       
## 26                0.727       
## 27                0.745  0.183
## 28                0.774       
## 29        -0.112  0.817       
## 30  0.102                0.774
## 31         0.338         0.595
## 32  0.264         0.106  0.590
## 33         0.288         0.654
## 
##                  MR2   MR1   MR3   MR4
## SS loadings    5.958 5.801 3.120 2.289
## Proportion Var 0.181 0.176 0.095 0.069
## Cumulative Var 0.181 0.356 0.451 0.520
## 
## $score.cor
##             [,1]       [,2]        [,3]        [,4]
## [1,]  1.00000000 0.04012196 -0.26146080  0.41687774
## [2,]  0.04012196 1.00000000  0.02146049  0.60399438
## [3,] -0.26146080 0.02146049  1.00000000 -0.04316592
## [4,]  0.41687774 0.60399438 -0.04316592  1.00000000
## 
## $TLI
## [1] 0.8751593
## 
## $RMSEA
##      RMSEA      lower      upper confidence 
## 0.07004073 0.06597274 0.07233424 0.10000000
out_targetQ
## Factor Analysis using method =  minres
## Call: fa(r = purposescales, nfactors = 4, rotate = "TargetQ", Target = Targ_key)
## Standardized loadings (pattern matrix) based upon correlation matrix
##      MR2   MR1   MR3   MR4   h2   u2 com
## 1   0.07  0.67  0.06  0.10 0.54 0.46 1.1
## 2   0.22  0.67 -0.01  0.06 0.54 0.46 1.2
## 3  -0.11  0.76 -0.06  0.19 0.76 0.24 1.2
## 4  -0.05  0.73 -0.03  0.08 0.61 0.39 1.0
## 5  -0.08  0.74 -0.04  0.10 0.64 0.36 1.1
## 6  -0.06  0.74  0.09 -0.11 0.50 0.50 1.1
## 7   0.02  0.76  0.03  0.05 0.62 0.38 1.0
## 8  -0.01  0.84 -0.04  0.02 0.72 0.28 1.0
## 9  -0.06  0.58 -0.02  0.18 0.47 0.53 1.2
## 10  0.04  0.58  0.03  0.05 0.36 0.64 1.0
## 11  0.69 -0.14  0.04 -0.25 0.46 0.54 1.4
## 12  0.48  0.22 -0.05 -0.24 0.20 0.80 2.0
## 13  0.81 -0.06  0.00  0.03 0.69 0.31 1.0
## 14  0.51  0.35 -0.10  0.08 0.47 0.53 1.9
## 15 -0.81 -0.04 -0.02  0.06 0.62 0.38 1.0
## 16  0.65  0.00  0.15  0.08 0.44 0.56 1.1
## 17  0.50  0.34  0.06 -0.34 0.22 0.78 2.6
## 18  0.44  0.00  0.11  0.09 0.22 0.78 1.2
## 19 -0.73  0.23  0.07 -0.16 0.71 0.29 1.3
## 20  0.55  0.02 -0.20  0.18 0.51 0.49 1.5
## 21  0.78 -0.17 -0.07  0.04 0.69 0.31 1.1
## 22  0.80 -0.23  0.02  0.00 0.69 0.31 1.2
## 23  0.48  0.26  0.11  0.13 0.38 0.62 1.8
## 24  0.56 -0.01 -0.16  0.23 0.55 0.45 1.5
## 25 -0.06  0.03  0.77 -0.06 0.64 0.36 1.0
## 26 -0.08  0.10  0.73  0.08 0.58 0.42 1.1
## 27 -0.02 -0.09  0.74  0.18 0.56 0.44 1.2
## 28  0.06  0.06  0.77 -0.04 0.59 0.41 1.0
## 29 -0.02 -0.11  0.82 -0.03 0.70 0.30 1.0
## 30  0.10 -0.04  0.02  0.77 0.64 0.36 1.0
## 31  0.02  0.34  0.00  0.59 0.67 0.33 1.6
## 32  0.26  0.07  0.11  0.59 0.57 0.43 1.5
## 33 -0.01  0.29 -0.03  0.65 0.69 0.31 1.4
## 
##                        MR2  MR1  MR3  MR4
## SS loadings           6.11 6.18 3.15 2.78
## Proportion Var        0.19 0.19 0.10 0.08
## Cumulative Var        0.19 0.37 0.47 0.55
## Proportion Explained  0.34 0.34 0.17 0.15
## Cumulative Proportion 0.34 0.67 0.85 1.00
## 
##  With factor correlations of 
##       MR2   MR1   MR3   MR4
## MR2  1.00 -0.04 -0.26  0.38
## MR1 -0.04  1.00  0.02  0.49
## MR3 -0.26  0.02  1.00 -0.08
## MR4  0.38  0.49 -0.08  1.00
## 
## Mean item complexity =  1.3
## Test of the hypothesis that 4 factors are sufficient.
## 
## The degrees of freedom for the null model are  528  and the objective function was  21.35 with Chi Square of  15888.56
## The degrees of freedom for the model are 402  and the objective function was  2.5 
## 
## The root mean square of the residuals (RMSR) is  0.04 
## The df corrected root mean square of the residuals is  0.04 
## 
## The harmonic number of observations is  472 with the empirical chi square  650.24  with prob <  5.3e-14 
## The total number of observations was  757  with MLE Chi Square =  1856.6  with prob <  3.9e-185 
## 
## Tucker Lewis Index of factoring reliability =  0.875
## RMSEA index =  0.07  and the 90 % confidence intervals are  0.066 0.072
## BIC =  -808.41
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy             
##                                                 MR2  MR1  MR3  MR4
## Correlation of scores with factors             0.97 0.97 0.94 0.93
## Multiple R square of scores with factors       0.94 0.94 0.89 0.87
## Minimum correlation of possible factor scores  0.88 0.88 0.78 0.74
#The best fit to the data seems to be three factors. F1: questions 1,3,5,6. f2: 8,7,4. f3: 2,9

CFI

1-((out_targetQ$STATISTIC - out_targetQ$dof)/(out_targetQ$null.chisq- out_targetQ$null.dof))
## [1] 0.9053032