SDQI Please select from the list below to what extent you think each / item is true or untrue. 1. I do lots of important things
2. Overall I am no good 3. In general, I like being the way I am
4. Overall I have a lot to be proud of
5. I can’t do anything right
6. I can do things as well as most other people 7. Other people think I am a good person
8. A lot of things about me are good
9. I am as good as most other people
10. When I do something, I do it well
library(lavaan)
## This is lavaan 0.5-18
## lavaan is BETA software! Please report any bugs.
library(semPlot)
library(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
library(GPArotation)
library(psych)
library(car)
##
## Attaching package: 'car'
##
## The following object is masked from 'package:psych':
##
## logit
library(ggplot2)
##
## Attaching package: 'ggplot2'
##
## The following object is masked from 'package:psych':
##
## %+%
library(GGally)
##
## Attaching package: 'GGally'
##
## The following object is masked from 'package:dplyr':
##
## nasa
data <- read.csv("~/Psychometric_study_data/allsurveysT1.csv")
data<-tbl_df(data)
SDQI<-select(data, SDQI_1, SDQI_2, SDQI_3, SDQI_4, SDQI_5, SDQI_6,SDQI_7, SDQI_8, SDQI_9, SDQI_9.1)
names(SDQI)[10] <- "SDQI_10"
SDQI$SDQI_2 <- 9- SDQI$SDQI_2
SDQI$SDQI_5 <- 9- SDQI$SDQI_5
SDQI<-tbl_df(SDQI)
SDQI
## Source: local data frame [757 x 10]
##
## SDQI_1 SDQI_2 SDQI_3 SDQI_4 SDQI_5 SDQI_6 SDQI_7 SDQI_8 SDQI_9 SDQI_10
## 1 6 6 6 7 6 7 7 7 7 7
## 2 5 6 6 6 6 6 8 7 7 6
## 3 5 8 5 5 8 6 5 6 6 8
## 4 6 8 7 6 6 7 7 7 7 6
## 5 4 6 5 5 6 4 6 6 6 4
## 6 7 6 6 5 8 5 4 6 4 5
## 7 4 4 7 6 6 7 7 7 7 5
## 8 5 8 5 6 7 4 6 6 6 7
## 9 7 8 7 8 8 7 8 8 8 7
## 10 5 6 5 7 4 5 7 7 6 7
## .. ... ... ... ... ... ... ... ... ... ...
#ggpairs(SDQI, columns = 1:15, title="Big 5 Marsh" )
two.model= ' Factor1 =~ SDQI_1 + SDQI_2 + SDQI_3 + SDQI_4 + SDQI_5
Factor2 =~ SDQI_6 + SDQI_7 + SDQI_8 + SDQI_9 +SDQI_10'
one.model= 'SDQI =~ SDQI_1 + SDQI_2 + SDQI_3 + SDQI_4 + SDQI_5 + SDQI_6 + SDQI_7 + SDQI_8 + SDQI_9 + SDQI_10'
two.fit=cfa(two.model, data=SDQI)
one.fit=cfa(one.model, data=SDQI)
semPaths(two.fit, whatLabels = "std", layout = "tree")
semPaths(one.fit, whatLabels = "std", layout = "tree")
#summaries
summary(two.fit, standardized = TRUE, rsquare=TRUE)
## lavaan (0.5-18) converged normally after 34 iterations
##
## Used Total
## Number of observations 105 757
##
## Estimator ML
## Minimum Function Test Statistic 95.750
## Degrees of freedom 34
## P-value (Chi-square) 0.000
##
## Parameter estimates:
##
## Information Expected
## Standard Errors Standard
##
## Estimate Std.err Z-value P(>|z|) Std.lv Std.all
## Latent variables:
## Factor1 =~
## SDQI_1 1.000 1.120 0.728
## SDQI_2 0.886 0.148 6.000 0.000 0.993 0.610
## SDQI_3 0.884 0.127 6.985 0.000 0.991 0.708
## SDQI_4 1.166 0.134 8.709 0.000 1.307 0.897
## SDQI_5 0.924 0.150 6.169 0.000 1.035 0.627
## Factor2 =~
## SDQI_6 1.000 0.917 0.599
## SDQI_7 1.134 0.186 6.103 0.000 1.040 0.729
## SDQI_8 1.258 0.174 7.212 0.000 1.154 0.962
## SDQI_9 1.290 0.194 6.639 0.000 1.184 0.826
## SDQI_10 1.084 0.168 6.444 0.000 0.995 0.789
##
## Covariances:
## Factor1 ~~
## Factor2 0.834 0.192 4.347 0.000 0.812 0.812
##
## Variances:
## SDQI_1 1.117 0.177 1.117 0.471
## SDQI_2 1.663 0.246 1.663 0.628
## SDQI_3 0.976 0.152 0.976 0.499
## SDQI_4 0.417 0.108 0.417 0.196
## SDQI_5 1.653 0.246 1.653 0.607
## SDQI_6 1.504 0.214 1.504 0.641
## SDQI_7 0.954 0.141 0.954 0.469
## SDQI_8 0.106 0.044 0.106 0.074
## SDQI_9 0.652 0.104 0.652 0.318
## SDQI_10 0.599 0.092 0.599 0.377
## Factor1 1.255 0.302 1.000 1.000
## Factor2 0.841 0.254 1.000 1.000
##
## R-Square:
##
## SDQI_1 0.529
## SDQI_2 0.372
## SDQI_3 0.501
## SDQI_4 0.804
## SDQI_5 0.393
## SDQI_6 0.359
## SDQI_7 0.531
## SDQI_8 0.926
## SDQI_9 0.682
## SDQI_10 0.623
summary(one.fit, standardized = TRUE, rsquare=TRUE)
## lavaan (0.5-18) converged normally after 26 iterations
##
## Used Total
## Number of observations 105 757
##
## Estimator ML
## Minimum Function Test Statistic 147.093
## Degrees of freedom 35
## P-value (Chi-square) 0.000
##
## Parameter estimates:
##
## Information Expected
## Standard Errors Standard
##
## Estimate Std.err Z-value P(>|z|) Std.lv Std.all
## Latent variables:
## SDQI =~
## SDQI_1 1.000 1.084 0.704
## SDQI_2 0.792 0.152 5.213 0.000 0.859 0.528
## SDQI_3 0.792 0.131 6.057 0.000 0.859 0.614
## SDQI_4 1.074 0.137 7.843 0.000 1.164 0.799
## SDQI_5 0.772 0.154 5.016 0.000 0.837 0.507
## SDQI_6 0.877 0.143 6.124 0.000 0.951 0.621
## SDQI_7 0.931 0.134 6.962 0.000 1.009 0.707
## SDQI_8 1.026 0.114 9.020 0.000 1.113 0.928
## SDQI_9 1.052 0.135 7.815 0.000 1.141 0.796
## SDQI_10 0.937 0.118 7.907 0.000 1.015 0.806
##
## Variances:
## SDQI_1 1.197 0.177 1.197 0.504
## SDQI_2 1.912 0.271 1.912 0.722
## SDQI_3 1.220 0.175 1.220 0.623
## SDQI_4 0.768 0.120 0.768 0.362
## SDQI_5 2.022 0.286 2.022 0.743
## SDQI_6 1.441 0.207 1.441 0.615
## SDQI_7 1.017 0.150 1.017 0.500
## SDQI_8 0.200 0.047 0.200 0.139
## SDQI_9 0.752 0.117 0.752 0.366
## SDQI_10 0.557 0.088 0.557 0.351
## SDQI 1.175 0.289 1.000 1.000
##
## R-Square:
##
## SDQI_1 0.496
## SDQI_2 0.278
## SDQI_3 0.377
## SDQI_4 0.638
## SDQI_5 0.257
## SDQI_6 0.385
## SDQI_7 0.500
## SDQI_8 0.861
## SDQI_9 0.634
## SDQI_10 0.649
correl = residuals(two.fit, type="cor")
correl
## $type
## [1] "cor.bollen"
##
## $cor
## SDQI_1 SDQI_2 SDQI_3 SDQI_4 SDQI_5 SDQI_6 SDQI_7 SDQI_8 SDQI_9
## SDQI_1 0.000
## SDQI_2 -0.010 0.000
## SDQI_3 0.022 -0.135 0.000
## SDQI_4 -0.037 -0.002 0.037 0.000
## SDQI_5 0.028 0.268 0.003 -0.028 0.000
## SDQI_6 0.111 -0.048 0.077 0.082 0.013 0.000
## SDQI_7 0.022 -0.111 -0.013 -0.059 -0.095 -0.062 0.000
## SDQI_8 0.055 -0.024 -0.041 0.027 -0.080 -0.029 0.008 0.000
## SDQI_9 -0.059 -0.001 -0.102 -0.045 -0.125 0.134 0.013 0.005 0.000
## SDQI_10 0.174 0.003 0.047 0.048 -0.045 -0.007 0.014 -0.003 -0.036
## SDQI_10
## SDQI_1
## SDQI_2
## SDQI_3
## SDQI_4
## SDQI_5
## SDQI_6
## SDQI_7
## SDQI_8
## SDQI_9
## SDQI_10 0.000
##
## $mean
## SDQI_1 SDQI_2 SDQI_3 SDQI_4 SDQI_5 SDQI_6 SDQI_7 SDQI_8 SDQI_9
## 0 0 0 0 0 0 0 0 0
## SDQI_10
## 0
View(correl$cor)
correl1 = residuals(one.fit, type="cor")
correl1
## $type
## [1] "cor.bollen"
##
## $cor
## SDQI_1 SDQI_2 SDQI_3 SDQI_4 SDQI_5 SDQI_6 SDQI_7 SDQI_8 SDQI_9
## SDQI_1 0.000
## SDQI_2 0.062 0.000
## SDQI_3 0.105 -0.027 0.000
## SDQI_4 0.052 0.124 0.181 0.000
## SDQI_5 0.127 0.383 0.135 0.129 0.000
## SDQI_6 0.028 -0.079 0.041 0.022 0.003 0.000
## SDQI_7 -0.045 -0.124 -0.028 -0.094 -0.083 -0.065 0.000
## SDQI_8 -0.030 -0.037 -0.057 -0.014 -0.061 -0.029 0.053 0.000
## SDQI_9 -0.131 -0.012 -0.116 -0.080 -0.109 0.135 0.052 0.061 0.000
## SDQI_10 0.073 -0.031 0.006 -0.021 -0.052 -0.034 0.020 0.009 -0.026
## SDQI_10
## SDQI_1
## SDQI_2
## SDQI_3
## SDQI_4
## SDQI_5
## SDQI_6
## SDQI_7
## SDQI_8
## SDQI_9
## SDQI_10 0.000
##
## $mean
## SDQI_1 SDQI_2 SDQI_3 SDQI_4 SDQI_5 SDQI_6 SDQI_7 SDQI_8 SDQI_9
## 0 0 0 0 0 0 0 0 0
## SDQI_10
## 0
View(correl1$cor)
zcorrels = residuals(two.fit, type = "standardized")
View(zcorrels$cov)
zcorrels1 = residuals(one.fit, type = "standardized")
View(zcorrels1$cov)
modindices(two.fit, sort. = TRUE, minimum.value = 3.84)
## lhs op rhs mi epc sepc.lv sepc.all sepc.nox
## 1 SDQI_2 ~~ SDQI_5 23.304 0.849 0.849 0.316 0.316
## 2 SDQI_6 ~~ SDQI_9 11.254 0.357 0.357 0.163 0.163
## 3 SDQI_2 ~~ SDQI_3 7.721 -0.387 -0.387 -0.170 -0.170
## 4 SDQI_1 ~~ SDQI_10 6.999 0.234 0.234 0.121 0.121
## 5 SDQI_6 ~~ SDQI_8 6.709 -0.190 -0.190 -0.104 -0.104
## 6 Factor1 =~ SDQI_9 5.697 -0.400 -0.448 -0.313 -0.313
## 7 SDQI_1 ~~ SDQI_4 5.105 -0.270 -0.270 -0.120 -0.120
## 8 Factor2 =~ SDQI_5 4.939 -0.675 -0.619 -0.375 -0.375
## 9 SDQI_3 ~~ SDQI_4 4.405 0.226 0.226 0.111 0.111
modindices(one.fit, sort. = TRUE, minimum.value = 3.84)
## lhs op rhs mi epc sepc.lv sepc.all sepc.nox
## 1 SDQI_2 ~~ SDQI_5 30.144 1.080 1.080 0.402 0.402
## 2 SDQI_8 ~~ SDQI_9 19.096 0.261 0.261 0.152 0.152
## 3 SDQI_3 ~~ SDQI_4 18.402 0.444 0.444 0.218 0.218
## 4 SDQI_1 ~~ SDQI_9 12.181 -0.361 -0.361 -0.164 -0.164
## 5 SDQI_6 ~~ SDQI_9 10.139 0.354 0.354 0.162 0.162
## 6 SDQI_7 ~~ SDQI_8 8.747 0.188 0.188 0.110 0.110
## 7 SDQI_4 ~~ SDQI_5 7.640 0.363 0.363 0.151 0.151
## 8 SDQI_3 ~~ SDQI_8 7.600 -0.183 -0.183 -0.109 -0.109
## 9 SDQI_3 ~~ SDQI_9 7.363 -0.278 -0.278 -0.138 -0.138
## 10 SDQI_2 ~~ SDQI_4 7.236 0.345 0.345 0.145 0.145
## 11 SDQI_4 ~~ SDQI_9 7.004 -0.229 -0.229 -0.110 -0.110
## 12 SDQI_5 ~~ SDQI_8 6.715 -0.215 -0.215 -0.109 -0.109
## 13 SDQI_4 ~~ SDQI_7 6.381 -0.244 -0.244 -0.117 -0.117
## 14 SDQI_5 ~~ SDQI_9 5.317 -0.300 -0.300 -0.127 -0.127
## 15 SDQI_1 ~~ SDQI_5 4.964 0.355 0.355 0.140 0.140
## 16 SDQI_2 ~~ SDQI_7 4.905 -0.317 -0.317 -0.136 -0.136
## 17 SDQI_3 ~~ SDQI_5 4.432 0.334 0.334 0.144 0.144
## 18 SDQI_1 ~~ SDQI_3 4.114 0.254 0.254 0.118 0.118
## 19 SDQI_1 ~~ SDQI_10 3.997 0.179 0.179 0.092 0.092
fitmeasures(two.fit)
## npar fmin chisq
## 21.000 0.456 95.750
## df pvalue baseline.chisq
## 34.000 0.000 693.269
## baseline.df baseline.pvalue cfi
## 45.000 0.000 0.905
## tli nnfi rfi
## 0.874 0.874 0.817
## nfi pnfi ifi
## 0.862 0.651 0.906
## rni logl unrestricted.logl
## 0.905 -1578.199 -1530.324
## aic bic ntotal
## 3198.398 3254.132 105.000
## bic2 rmsea rmsea.ci.lower
## 3187.789 0.132 0.101
## rmsea.ci.upper rmsea.pvalue rmr
## 0.163 0.000 0.158
## rmr_nomean srmr srmr_bentler
## 0.158 0.068 0.068
## srmr_bentler_nomean srmr_bollen srmr_bollen_nomean
## 0.068 0.068 0.068
## srmr_mplus srmr_mplus_nomean cn_05
## 0.068 0.068 54.297
## cn_01 gfi agfi
## 62.476 0.870 0.790
## pgfi mfi ecvi
## 0.538 0.745 1.312
fitmeasures(one.fit)
## npar fmin chisq
## 20.000 0.700 147.093
## df pvalue baseline.chisq
## 35.000 0.000 693.269
## baseline.df baseline.pvalue cfi
## 45.000 0.000 0.827
## tli nnfi rfi
## 0.778 0.778 0.727
## nfi pnfi ifi
## 0.788 0.613 0.830
## rni logl unrestricted.logl
## 0.827 -1603.871 -1530.324
## aic bic ntotal
## 3247.741 3300.820 105.000
## bic2 rmsea rmsea.ci.lower
## 3237.637 0.175 0.146
## rmsea.ci.upper rmsea.pvalue rmr
## 0.204 0.000 0.206
## rmr_nomean srmr srmr_bentler
## 0.206 0.086 0.086
## srmr_bentler_nomean srmr_bollen srmr_bollen_nomean
## 0.086 0.086 0.086
## srmr_mplus srmr_mplus_nomean cn_05
## 0.086 0.086 36.550
## cn_01 gfi agfi
## 41.933 0.773 0.643
## pgfi mfi ecvi
## 0.492 0.586 1.782
SDQITR<-select(SDQI, SDQI_1 , SDQI_2 , SDQI_3, SDQI_4 , SDQI_5 , SDQI_6 ,SDQI_7 , SDQI_8 , SDQI_9 , SDQI_10)
colnames(SDQITR) <- c("1","2", "3", "4", "5", "6", "7", "8", "9", "10")
#Target Roration
Targ_key <- make.keys(10,list(f1=1:5,f2=6:10))
Targ_key <- scrub(Targ_key,isvalue=1) #fix the 0s, allow the NAs to be estimated
Targ_key <- list(Targ_key)
out_targetQ <- fa(SDQITR,2,rotate="TargetQ",Target=Targ_key) #TargetT for orthogonal rotation
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : A Heywood case was detected. Examine the loadings carefully.
out_targetQ[c("loadings", "score.cor", "TLI", "RMSEA","uniquenesses")]
## $loadings
##
## Loadings:
## MR2 MR1
## 1 0.753
## 2 0.349 0.410
## 3 0.660
## 4 0.799 0.172
## 5 -0.320 0.680
## 6 0.665 0.188
## 7 0.788
## 8 0.836 0.221
## 9 1.019 -0.119
## 10 0.600 0.372
##
## MR2 MR1
## SS loadings 4.033 1.900
## Proportion Var 0.403 0.190
## Cumulative Var 0.403 0.593
##
## $score.cor
## [,1] [,2]
## [1,] 1.0000000 0.5421326
## [2,] 0.5421326 1.0000000
##
## $TLI
## [1] 0.6891925
##
## $RMSEA
## RMSEA lower upper confidence
## 0.2513522 0.2385670 0.2621346 0.1000000
##
## $uniquenesses
## 1 2 3 4 5 6
## 0.44474586 0.57361999 0.49293033 0.20116271 0.64328390 0.40270116
## 7 8 9 10
## 0.37266517 0.07485861 0.06338803 0.28862137
out_targetQ
## Factor Analysis using method = minres
## Call: fa(r = SDQITR, nfactors = 2, rotate = "TargetQ", Target = Targ_key)
##
## Warning: A Heywood case was detected.
## Standardized loadings (pattern matrix) based upon correlation matrix
## MR2 MR1 h2 u2 com
## 1 -0.02 0.75 0.56 0.445 1.0
## 2 0.35 0.41 0.43 0.574 2.0
## 3 0.10 0.66 0.51 0.493 1.0
## 4 0.80 0.17 0.80 0.201 1.1
## 5 -0.32 0.68 0.36 0.643 1.4
## 6 0.66 0.19 0.60 0.403 1.2
## 7 0.79 0.01 0.63 0.373 1.0
## 8 0.84 0.22 0.93 0.075 1.1
## 9 1.02 -0.12 0.94 0.063 1.0
## 10 0.60 0.37 0.71 0.289 1.7
##
## MR2 MR1
## SS loadings 4.29 2.15
## Proportion Var 0.43 0.22
## Cumulative Var 0.43 0.64
## Proportion Explained 0.67 0.33
## Cumulative Proportion 0.67 1.00
##
## With factor correlations of
## MR2 MR1
## MR2 1.00 0.48
## MR1 0.48 1.00
##
## Mean item complexity = 1.3
## Test of the hypothesis that 2 factors are sufficient.
##
## The degrees of freedom for the null model are 45 and the objective function was 9.21 with Chi Square of 6921.17
## The degrees of freedom for the model are 26 and the objective function was 1.68
##
## The root mean square of the residuals (RMSR) is 0.06
## The df corrected root mean square of the residuals is 0.08
##
## The harmonic number of observations is 122 with the empirical chi square 37.18 with prob < 0.072
## The total number of observations was 757 with MLE Chi Square = 1258.6 with prob < 4.1e-249
##
## Tucker Lewis Index of factoring reliability = 0.689
## RMSEA index = 0.251 and the 90 % confidence intervals are 0.239 0.262
## BIC = 1086.24
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy
## MR2 MR1
## Correlation of scores with factors 0.99 0.91
## Multiple R square of scores with factors 0.97 0.83
## Minimum correlation of possible factor scores 0.94 0.67
CFI
1-((out_targetQ$STATISTIC - out_targetQ$dof)/(out_targetQ$null.chisq- out_targetQ$null.dof))
## [1] 0.8207429
As one Factor
Targ_key <- make.keys(10,list(f1=1:10))
Targ_key <- scrub(Targ_key,isvalue=1) #fix the 0s, allow the NAs to be estimated
Targ_key <- list(Targ_key)
out_targetQ <- fa(SDQITR,1,rotate="TargetQ",Target=Targ_key) #TargetT for orthogonal rotation
out_targetQ[c("loadings", "score.cor", "TLI", "RMSEA","uniquenesses")]
## $loadings
##
## Loadings:
## MR1
## 1 0.456
## 2 0.597
## 3 0.520
## 4 0.891
## 5 0.114
## 6 0.743
## 7 0.791
## 8 0.978
## 9 0.900
## 10 0.818
##
## MR1
## SS loadings 5.255
## Proportion Var 0.525
##
## $<NA>
## NULL
##
## $TLI
## [1] 0.6479753
##
## $RMSEA
## RMSEA lower upper confidence
## 0.2674960 0.2563662 0.2766677 0.1000000
##
## $uniquenesses
## 1 2 3 4 5 6 7
## 0.7921042 0.6432833 0.7299681 0.2067172 0.9870978 0.4485997 0.3739752
## 8 9 10
## 0.0436710 0.1895581 0.3304892
out_targetQ
## Factor Analysis using method = minres
## Call: fa(r = SDQITR, nfactors = 1, rotate = "TargetQ", Target = Targ_key)
## Standardized loadings (pattern matrix) based upon correlation matrix
## MR1 h2 u2 com
## 1 0.46 0.208 0.792 1
## 2 0.60 0.357 0.643 1
## 3 0.52 0.270 0.730 1
## 4 0.89 0.793 0.207 1
## 5 0.11 0.013 0.987 1
## 6 0.74 0.551 0.449 1
## 7 0.79 0.626 0.374 1
## 8 0.98 0.956 0.044 1
## 9 0.90 0.810 0.190 1
## 10 0.82 0.670 0.330 1
##
## MR1
## SS loadings 5.25
## Proportion Var 0.53
##
## Mean item complexity = 1
## Test of the hypothesis that 1 factor is sufficient.
##
## The degrees of freedom for the null model are 45 and the objective function was 9.21 with Chi Square of 6921.17
## The degrees of freedom for the model are 35 and the objective function was 2.55
##
## The root mean square of the residuals (RMSR) is 0.12
## The df corrected root mean square of the residuals is 0.14
##
## The harmonic number of observations is 122 with the empirical chi square 155.86 with prob < 3.5e-17
## The total number of observations was 757 with MLE Chi Square = 1915.99 with prob < 0
##
## Tucker Lewis Index of factoring reliability = 0.648
## RMSEA index = 0.267 and the 90 % confidence intervals are 0.256 0.277
## BIC = 1683.97
## Fit based upon off diagonal values = 0.95
## Measures of factor score adequacy
## MR1
## Correlation of scores with factors 0.99
## Multiple R square of scores with factors 0.97
## Minimum correlation of possible factor scores 0.95
CFI
1-((out_targetQ$STATISTIC - out_targetQ$dof)/(out_targetQ$null.chisq- out_targetQ$null.dof))
## [1] 0.7264474