Rmd

Quelle

Infos

Datenaufbereitung

require(foreign)
df <- read.spss("/Users/pzezula/lehre/lehre_ss_2016/unit/fa/example_bfi/data/bfi-unique-3-exploratory.sav", to.data.frame=T)
names(df) <- tolower(names(df))
write.table(df, file="bfi-expl.txt", quote=F, sep="\t", row.names=F)
df <- read.spss("/Users/pzezula/lehre/lehre_ss_2016/unit/fa/example_bfi/data/bfi-unique-3-confirmatory.sav", to.data.frame=T)
names(df) <- tolower(names(df))
write.table(df, file="bfi-conf.txt", quote=F, sep="\t", row.names=F)
# we find the files written to the current directory
getwd()

# for convenience reasons we can read the data from our data server
df <- read.delim("http://md.psych.bio.uni-goettingen.de/mv/data/div/bfi-expl.txt")
df <- read.delim("http://md.psych.bio.uni-goettingen.de/mv/data/div/bfi-expl.txt")
head(df)
##   a1 a2 a3 a4 a5 c1 c2 c3 c4 c5 e1 e2 e3 e4 e5 n1 n2 n3 n4 n5 o1 o2 o3 o4 o5
## 1  1  5  5  5  6  6  6  1  1  1  6  1  1  5  1  1  1  1  6  1  6  6  6  1  1
## 2  3  1  1  2  1  6  4  2  6  5  6  5  4  6  5  1  4  6  6  6  6  5  1  6  1
## 3  1  6  6  4  1  1  6  5  4  2  6  1  3  5  1  5  5  5  6  4  6  1  6  6  6
## 4  4  6  1  6  6  1  1  6  6  6  4  6  4  1  1  4  3  6  5  6  1  6  2  6  2
## 5  6  5  6  5  6  1  1  1  6  6  6  1  6  3  1  6  6  6  6  6  6  1  6  2  2
## 6  3  3  5  5  5  1  6  6  2  1  1  1  1  5  2  5  5  5  4  3  5  1  1  1  1
##   gender       education age    id missing_count mahal_items     dataset a1r
## 1 Female    some college  40 62092             1    91.92642 Exploratory   5
## 2   Male graduate degree  21 65439             0    86.72993 Exploratory   3
## 3 Female    some college  41 63763             0    83.05337 Exploratory   5
## 4 Female              HS  20 64341             0    79.19262 Exploratory   2
## 5 Female    some college  20 64192             0    78.37850 Exploratory   0
## 6 Female            <NA>  13 65170             0    73.75773 Exploratory   3
##   a2r a3r a4r a5r c1r c2r c3r c4r c5r e1r e2r e3r e4r e5r n1r n2r n3r n4r n5r
## 1   5   5   5   6   6   6   1   5   5   0   5   1   5   1   1   1   1   6   1
## 2   1   1   2   1   6   4   2   0   1   0   1   4   6   5   1   4   6   6   6
## 3   6   6   4   1   1   6   5   2   4   0   5   3   5   1   5   5   5   6   4
## 4   6   1   6   6   1   1   6   0   0   2   0   4   1   1   4   3   6   5   6
## 5   5   6   5   6   1   1   1   0   0   0   5   6   3   1   6   6   6   6   6
## 6   3   5   5   5   1   6   6   4   5   5   5   1   5   2   5   5   5   4   3
##   o1r o2r o3r o4r o5r neuroticism extraversion openness agreeableness
## 1   6   0   6   1   5         2.0         2.75     4.25           5.2
## 2   6   1   1   6   5         4.6         3.00     3.25           1.6
## 3   6   5   6   6   0         5.0         2.75     4.25           4.4
## 4   1   0   2   6   4         4.8         1.00     1.75           4.2
## 5   6   5   6   2   4         6.0         2.25     5.25           4.4
## 6   5   5   1   1   5         4.4         4.25     4.00           4.2
##   conscientiousness
## 1               4.6
## 2               2.6
## 3               3.6
## 4               1.6
## 5               0.6
## 6               4.4
v <- list()
v$items <- names(df[,1:25])
# v$items

# we do a screeplot to have an idea of the number of factors, the data suggest
require(psych)
## Loading required package: psych
psych::scree(df[,v$items])

# or via fa.parallel
psych::fa.parallel(df[,v$items])

## Parallel analysis suggests that the number of factors =  6  and the number of components =  5
# we extract 5 factors due to the concept of the big five
f.1 <- factanal(df[,v$items], factors=5, rotation="promax")


# we set cutoff in order to show us factor loadings above .3 only
print(f.1, cutoff=.3)
## 
## Call:
## factanal(x = df[, v$items], factors = 5, rotation = "promax")
## 
## Uniquenesses:
##    a1    a2    a3    a4    a5    c1    c2    c3    c4    c5    e1    e2    e3 
## 0.824 0.582 0.460 0.702 0.549 0.679 0.590 0.697 0.505 0.547 0.589 0.453 0.546 
##    e4    e5    n1    n2    n3    n4    n5    o1    o2    o3    o4    o5 
## 0.460 0.590 0.301 0.341 0.475 0.468 0.640 0.611 0.775 0.491 0.747 0.796 
## 
## Loadings:
##    Factor1 Factor2 Factor3 Factor4 Factor5
## a1                         -0.424         
## a2                          0.600         
## a3                          0.666         
## a4                          0.467         
## a5                          0.554         
## c1                  0.534                 
## c2                  0.637                 
## c3                  0.582                 
## c4                 -0.700                 
## c5                 -0.609                 
## e1          0.685                         
## e2          0.685                         
## e3         -0.424                   0.351 
## e4         -0.609           0.342         
## e5         -0.438                         
## n1  0.890                                 
## n2  0.862                                 
## n3  0.683                                 
## n4  0.407   0.418                         
## n5  0.473                                 
## o1                                  0.600 
## o2                                 -0.413 
## o3                                  0.683 
## o4          0.351                   0.372 
## o5                                 -0.420 
## 
##                Factor1 Factor2 Factor3 Factor4 Factor5
## SS loadings      2.599   2.252   2.071   1.841   1.595
## Proportion Var   0.104   0.090   0.083   0.074   0.064
## Cumulative Var   0.104   0.194   0.277   0.350   0.414
## 
## Factor Correlations:
##         Factor1  Factor2 Factor3  Factor4 Factor5
## Factor1   1.000 -0.38256   0.337  0.24772  0.1812
## Factor2  -0.383  1.00000  -0.299 -0.00192 -0.0176
## Factor3   0.337 -0.29870   1.000  0.26534  0.3560
## Factor4   0.248 -0.00192   0.265  1.00000  0.2421
## Factor5   0.181 -0.01756   0.356  0.24212  1.0000
## 
## Test of the hypothesis that 5 factors are sufficient.
## The chi square statistic is 857 on 185 degrees of freedom.
## The p-value is 5.26e-87

Ein globales Modell anpassen - Ein-Faktor-Modell

df <- read.delim("http://md.psych.bio.uni-goettingen.de/mv/data/div/bfi-expl.txt")
v <- list()
v$items <- names(df[,1:25])

# to help us to produce the model syntax
# paste(v$items, collapse = ' + ')
require(lavaan)
## Loading required package: lavaan
## This is lavaan 0.6-8
## lavaan is FREE software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## The following object is masked from 'package:psych':
## 
##     cor2cov
# default item to put contstraint on is the first in the model
# we can put that to another item, here a3 by making it the first item 
m.g <- '
  global =~ a3 + a1 + a2 +  a4 + a5 + c1 + c2 + c3 + c4 + c5 + e1 + e2 + e3 + e4 + e5 + n1 + n2 + n3 + n4 + n5 + o1 + o2 + o3 + o4 + o5
'
fit.g <- lavaan::cfa(m.g, data=df)
summary(fit.g, fit.measures=T)
## lavaan 0.6-8 ended normally after 39 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        50
##                                                       
##   Number of observations                          1236
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                              5411.707
##   Degrees of freedom                               275
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              9406.973
##   Degrees of freedom                               300
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.436
##   Tucker-Lewis Index (TLI)                       0.385
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -52356.738
##   Loglikelihood unrestricted model (H1)     -49650.884
##                                                       
##   Akaike (AIC)                              104813.476
##   Bayesian (BIC)                            105069.458
##   Sample-size adjusted Bayesian (BIC)       104910.636
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.123
##   90 Percent confidence interval - lower         0.120
##   90 Percent confidence interval - upper         0.126
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.114
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   global =~                                           
##     a3                1.000                           
##     a1               -0.426    0.061   -6.978    0.000
##     a2                0.795    0.061   13.125    0.000
##     a4                0.846    0.071   12.003    0.000
##     a5                0.990    0.066   15.107    0.000
##     c1                0.552    0.058    9.589    0.000
##     c2                0.540    0.059    9.084    0.000
##     c3                0.506    0.059    8.585    0.000
##     c4               -0.841    0.067  -12.602    0.000
##     c5               -1.103    0.081  -13.624    0.000
##     e1               -0.926    0.078  -11.890    0.000
##     e2               -1.427    0.087  -16.407    0.000
##     e3                1.064    0.070   15.228    0.000
##     e4                1.236    0.077   16.016    0.000
##     e5                1.036    0.070   14.830    0.000
##     n1               -0.822    0.074  -11.129    0.000
##     n2               -0.787    0.072  -10.990    0.000
##     n3               -0.804    0.075  -10.744    0.000
##     n4               -1.196    0.081  -14.713    0.000
##     n5               -0.826    0.076  -10.905    0.000
##     o1                0.556    0.053   10.438    0.000
##     o2               -0.437    0.069   -6.365    0.000
##     o3                0.686    0.058   11.912    0.000
##     o4               -0.167    0.052   -3.198    0.001
##     o5               -0.415    0.059   -7.075    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .a3                1.200    0.052   23.099    0.000
##    .a1                1.808    0.073   24.647    0.000
##    .a2                1.206    0.051   23.754    0.000
##    .a4                1.812    0.075   24.025    0.000
##    .a5                1.111    0.048   22.993    0.000
##    .c1                1.424    0.058   24.408    0.000
##    .c2                1.558    0.064   24.466    0.000
##    .c3                1.576    0.064   24.516    0.000
##    .c4                1.540    0.064   23.890    0.000
##    .c5                2.045    0.087   23.604    0.000
##    .e1                2.231    0.093   24.048    0.000
##    .e2                1.560    0.071   22.098    0.000
##    .e3                1.239    0.054   22.928    0.000
##    .e4                1.325    0.059   22.421    0.000
##    .e5                1.312    0.057   23.131    0.000
##    .n1                2.126    0.088   24.189    0.000
##    .n2                2.018    0.083   24.212    0.000
##    .n3                2.245    0.093   24.251    0.000
##    .n4                1.805    0.078   23.186    0.000
##    .n5                2.275    0.094   24.226    0.000
##    .o1                1.159    0.048   24.297    0.000
##    .o2                2.334    0.095   24.687    0.000
##    .o3                1.216    0.051   24.044    0.000
##    .o4                1.445    0.058   24.819    0.000
##    .o5                1.660    0.067   24.641    0.000
##     global            0.514    0.053    9.725    0.000
# we get the standardized estimates
standardizedSolution(fit.g)
##       lhs op    rhs est.std    se       z pvalue ci.lower ci.upper
## 1  global =~     a3   0.548 0.022  24.452  0.000    0.504    0.591
## 2  global =~     a1  -0.222 0.029  -7.559  0.000   -0.279   -0.164
## 3  global =~     a2   0.460 0.025  18.563  0.000    0.412    0.509
## 4  global =~     a4   0.411 0.026  15.803  0.000    0.360    0.462
## 5  global =~     a5   0.559 0.022  25.333  0.000    0.515    0.602
## 6  global =~     c1   0.315 0.028  11.263  0.000    0.260    0.369
## 7  global =~     c2   0.296 0.028  10.474  0.000    0.241    0.351
## 8  global =~     c3   0.278 0.029   9.732  0.000    0.222    0.334
## 9  global =~     c4  -0.437 0.025 -17.209  0.000   -0.487   -0.387
## 10 global =~     c5  -0.484 0.024 -19.990  0.000   -0.531   -0.436
## 11 global =~     e1  -0.406 0.026 -15.555  0.000   -0.457   -0.355
## 12 global =~     e2  -0.634 0.020 -32.264  0.000   -0.672   -0.595
## 13 global =~     e3   0.565 0.022  25.867  0.000    0.522    0.608
## 14 global =~     e4   0.610 0.020  29.859  0.000    0.570    0.650
## 15 global =~     e5   0.544 0.022  24.180  0.000    0.500    0.588
## 16 global =~     n1  -0.375 0.027 -13.984  0.000   -0.427   -0.322
## 17 global =~     n2  -0.369 0.027 -13.715  0.000   -0.422   -0.316
## 18 global =~     n3  -0.359 0.027 -13.253  0.000   -0.412   -0.306
## 19 global =~     n4  -0.538 0.023 -23.716  0.000   -0.582   -0.493
## 20 global =~     n5  -0.366 0.027 -13.553  0.000   -0.418   -0.313
## 21 global =~     o1   0.347 0.027  12.697  0.000    0.294    0.401
## 22 global =~     o2  -0.201 0.030  -6.798  0.000   -0.259   -0.143
## 23 global =~     o3   0.407 0.026  15.603  0.000    0.356    0.458
## 24 global =~     o4  -0.099 0.030  -3.250  0.001   -0.159   -0.039
## 25 global =~     o5  -0.225 0.029  -7.682  0.000   -0.282   -0.168
## 26     a3 ~~     a3   0.700 0.025  28.556  0.000    0.652    0.748
## 27     a1 ~~     a1   0.951 0.013  73.125  0.000    0.925    0.976
## 28     a2 ~~     a2   0.788 0.023  34.499  0.000    0.743    0.833
## 29     a4 ~~     a4   0.831 0.021  38.906  0.000    0.789    0.873
## 30     a5 ~~     a5   0.688 0.025  27.912  0.000    0.640    0.736
## 31     c1 ~~     c1   0.901 0.018  51.245  0.000    0.867    0.935
## 32     c2 ~~     c2   0.912 0.017  54.554  0.000    0.880    0.945
## 33     c3 ~~     c3   0.923 0.016  58.181  0.000    0.892    0.954
## 34     c4 ~~     c4   0.809 0.022  36.474  0.000    0.766    0.853
## 35     c5 ~~     c5   0.766 0.023  32.722  0.000    0.720    0.812
## 36     e1 ~~     e1   0.835 0.021  39.385  0.000    0.794    0.877
## 37     e2 ~~     e2   0.599 0.025  24.049  0.000    0.550    0.647
## 38     e3 ~~     e3   0.680 0.025  27.543  0.000    0.632    0.729
## 39     e4 ~~     e4   0.628 0.025  25.195  0.000    0.579    0.677
## 40     e5 ~~     e5   0.704 0.024  28.765  0.000    0.656    0.752
## 41     n1 ~~     n1   0.860 0.020  42.831  0.000    0.820    0.899
## 42     n2 ~~     n2   0.864 0.020  43.505  0.000    0.825    0.903
## 43     n3 ~~     n3   0.871 0.019  44.732  0.000    0.833    0.909
## 44     n4 ~~     n4   0.711 0.024  29.132  0.000    0.663    0.759
## 45     n5 ~~     n5   0.866 0.020  43.927  0.000    0.828    0.905
## 46     o1 ~~     o1   0.879 0.019  46.335  0.000    0.842    0.917
## 47     o2 ~~     o2   0.960 0.012  80.708  0.000    0.936    0.983
## 48     o3 ~~     o3   0.834 0.021  39.290  0.000    0.793    0.876
## 49     o4 ~~     o4   0.990 0.006 164.545  0.000    0.978    1.002
## 50     o5 ~~     o5   0.949 0.013  72.043  0.000    0.924    0.975
## 51 global ~~ global   1.000 0.000      NA     NA    1.000    1.000

Modell mit den vermuteten 5 Faktoren anpassen - mit und ohne Korrelation der Faktoren

df <- read.delim("http://md.psych.bio.uni-goettingen.de/mv/data/div/bfi-expl.txt")
v <- list()
v$items <- names(df[,1:25])

# to help us to produce the model syntax
# paste(v$items, collapse = ' + ')
require(lavaan)
# default item to put contstraint on is the first in the model
# we can put that to another item, here a3 by making it the first item 
m.g <- '
  global =~ a3 + a1 + a2 +  a4 + a5 + c1 + c2 + c3 + c4 + c5 + e1 + e2 + e3 + e4 + e5 + n1 + n2 + n3 + n4 + n5 + o1 + o2 + o3 + o4 + o5
'
fit.g <- lavaan::cfa(m.g, data=df)
summary(fit.g, fit.measures=T)
## lavaan 0.6-8 ended normally after 39 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        50
##                                                       
##   Number of observations                          1236
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                              5411.707
##   Degrees of freedom                               275
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              9406.973
##   Degrees of freedom                               300
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.436
##   Tucker-Lewis Index (TLI)                       0.385
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -52356.738
##   Loglikelihood unrestricted model (H1)     -49650.884
##                                                       
##   Akaike (AIC)                              104813.476
##   Bayesian (BIC)                            105069.458
##   Sample-size adjusted Bayesian (BIC)       104910.636
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.123
##   90 Percent confidence interval - lower         0.120
##   90 Percent confidence interval - upper         0.126
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.114
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   global =~                                           
##     a3                1.000                           
##     a1               -0.426    0.061   -6.978    0.000
##     a2                0.795    0.061   13.125    0.000
##     a4                0.846    0.071   12.003    0.000
##     a5                0.990    0.066   15.107    0.000
##     c1                0.552    0.058    9.589    0.000
##     c2                0.540    0.059    9.084    0.000
##     c3                0.506    0.059    8.585    0.000
##     c4               -0.841    0.067  -12.602    0.000
##     c5               -1.103    0.081  -13.624    0.000
##     e1               -0.926    0.078  -11.890    0.000
##     e2               -1.427    0.087  -16.407    0.000
##     e3                1.064    0.070   15.228    0.000
##     e4                1.236    0.077   16.016    0.000
##     e5                1.036    0.070   14.830    0.000
##     n1               -0.822    0.074  -11.129    0.000
##     n2               -0.787    0.072  -10.990    0.000
##     n3               -0.804    0.075  -10.744    0.000
##     n4               -1.196    0.081  -14.713    0.000
##     n5               -0.826    0.076  -10.905    0.000
##     o1                0.556    0.053   10.438    0.000
##     o2               -0.437    0.069   -6.365    0.000
##     o3                0.686    0.058   11.912    0.000
##     o4               -0.167    0.052   -3.198    0.001
##     o5               -0.415    0.059   -7.075    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .a3                1.200    0.052   23.099    0.000
##    .a1                1.808    0.073   24.647    0.000
##    .a2                1.206    0.051   23.754    0.000
##    .a4                1.812    0.075   24.025    0.000
##    .a5                1.111    0.048   22.993    0.000
##    .c1                1.424    0.058   24.408    0.000
##    .c2                1.558    0.064   24.466    0.000
##    .c3                1.576    0.064   24.516    0.000
##    .c4                1.540    0.064   23.890    0.000
##    .c5                2.045    0.087   23.604    0.000
##    .e1                2.231    0.093   24.048    0.000
##    .e2                1.560    0.071   22.098    0.000
##    .e3                1.239    0.054   22.928    0.000
##    .e4                1.325    0.059   22.421    0.000
##    .e5                1.312    0.057   23.131    0.000
##    .n1                2.126    0.088   24.189    0.000
##    .n2                2.018    0.083   24.212    0.000
##    .n3                2.245    0.093   24.251    0.000
##    .n4                1.805    0.078   23.186    0.000
##    .n5                2.275    0.094   24.226    0.000
##    .o1                1.159    0.048   24.297    0.000
##    .o2                2.334    0.095   24.687    0.000
##    .o3                1.216    0.051   24.044    0.000
##    .o4                1.445    0.058   24.819    0.000
##    .o5                1.660    0.067   24.641    0.000
##     global            0.514    0.053    9.725    0.000
# we get the standardized estimates
standardizedSolution(fit.g)
##       lhs op    rhs est.std    se       z pvalue ci.lower ci.upper
## 1  global =~     a3   0.548 0.022  24.452  0.000    0.504    0.591
## 2  global =~     a1  -0.222 0.029  -7.559  0.000   -0.279   -0.164
## 3  global =~     a2   0.460 0.025  18.563  0.000    0.412    0.509
## 4  global =~     a4   0.411 0.026  15.803  0.000    0.360    0.462
## 5  global =~     a5   0.559 0.022  25.333  0.000    0.515    0.602
## 6  global =~     c1   0.315 0.028  11.263  0.000    0.260    0.369
## 7  global =~     c2   0.296 0.028  10.474  0.000    0.241    0.351
## 8  global =~     c3   0.278 0.029   9.732  0.000    0.222    0.334
## 9  global =~     c4  -0.437 0.025 -17.209  0.000   -0.487   -0.387
## 10 global =~     c5  -0.484 0.024 -19.990  0.000   -0.531   -0.436
## 11 global =~     e1  -0.406 0.026 -15.555  0.000   -0.457   -0.355
## 12 global =~     e2  -0.634 0.020 -32.264  0.000   -0.672   -0.595
## 13 global =~     e3   0.565 0.022  25.867  0.000    0.522    0.608
## 14 global =~     e4   0.610 0.020  29.859  0.000    0.570    0.650
## 15 global =~     e5   0.544 0.022  24.180  0.000    0.500    0.588
## 16 global =~     n1  -0.375 0.027 -13.984  0.000   -0.427   -0.322
## 17 global =~     n2  -0.369 0.027 -13.715  0.000   -0.422   -0.316
## 18 global =~     n3  -0.359 0.027 -13.253  0.000   -0.412   -0.306
## 19 global =~     n4  -0.538 0.023 -23.716  0.000   -0.582   -0.493
## 20 global =~     n5  -0.366 0.027 -13.553  0.000   -0.418   -0.313
## 21 global =~     o1   0.347 0.027  12.697  0.000    0.294    0.401
## 22 global =~     o2  -0.201 0.030  -6.798  0.000   -0.259   -0.143
## 23 global =~     o3   0.407 0.026  15.603  0.000    0.356    0.458
## 24 global =~     o4  -0.099 0.030  -3.250  0.001   -0.159   -0.039
## 25 global =~     o5  -0.225 0.029  -7.682  0.000   -0.282   -0.168
## 26     a3 ~~     a3   0.700 0.025  28.556  0.000    0.652    0.748
## 27     a1 ~~     a1   0.951 0.013  73.125  0.000    0.925    0.976
## 28     a2 ~~     a2   0.788 0.023  34.499  0.000    0.743    0.833
## 29     a4 ~~     a4   0.831 0.021  38.906  0.000    0.789    0.873
## 30     a5 ~~     a5   0.688 0.025  27.912  0.000    0.640    0.736
## 31     c1 ~~     c1   0.901 0.018  51.245  0.000    0.867    0.935
## 32     c2 ~~     c2   0.912 0.017  54.554  0.000    0.880    0.945
## 33     c3 ~~     c3   0.923 0.016  58.181  0.000    0.892    0.954
## 34     c4 ~~     c4   0.809 0.022  36.474  0.000    0.766    0.853
## 35     c5 ~~     c5   0.766 0.023  32.722  0.000    0.720    0.812
## 36     e1 ~~     e1   0.835 0.021  39.385  0.000    0.794    0.877
## 37     e2 ~~     e2   0.599 0.025  24.049  0.000    0.550    0.647
## 38     e3 ~~     e3   0.680 0.025  27.543  0.000    0.632    0.729
## 39     e4 ~~     e4   0.628 0.025  25.195  0.000    0.579    0.677
## 40     e5 ~~     e5   0.704 0.024  28.765  0.000    0.656    0.752
## 41     n1 ~~     n1   0.860 0.020  42.831  0.000    0.820    0.899
## 42     n2 ~~     n2   0.864 0.020  43.505  0.000    0.825    0.903
## 43     n3 ~~     n3   0.871 0.019  44.732  0.000    0.833    0.909
## 44     n4 ~~     n4   0.711 0.024  29.132  0.000    0.663    0.759
## 45     n5 ~~     n5   0.866 0.020  43.927  0.000    0.828    0.905
## 46     o1 ~~     o1   0.879 0.019  46.335  0.000    0.842    0.917
## 47     o2 ~~     o2   0.960 0.012  80.708  0.000    0.936    0.983
## 48     o3 ~~     o3   0.834 0.021  39.290  0.000    0.793    0.876
## 49     o4 ~~     o4   0.990 0.006 164.545  0.000    0.978    1.002
## 50     o5 ~~     o5   0.949 0.013  72.043  0.000    0.924    0.975
## 51 global ~~ global   1.000 0.000      NA     NA    1.000    1.000
# we choose a non negativ item to be the reference item: a3 and e3
m.5f <- '
  agree =~ a3 + a1 + a2 + a4 + a5 
  consc =~ c1 + c2 + c3 + c4 + c5
  extra =~ e3 + e1 + e2 + e4 + e5
  neuro =~ n1 + n2 + n3 + n4 + n5
  openn =~ o1 + o2 + o3 + o4 + o5
'

fit.5f.o <- lavaan::cfa(m.5f, data=df, orthogonal=T)
fit.5f.c <- lavaan::cfa(m.5f, data=df, orthogonal=F)

fitmeasures(fit.5f.o)
##                npar                fmin               chisq                  df 
##              50.000               1.222            3021.448             275.000 
##              pvalue      baseline.chisq         baseline.df     baseline.pvalue 
##               0.000            9406.973             300.000               0.000 
##                 cfi                 tli                nnfi                 rfi 
##               0.698               0.671               0.671               0.650 
##                 nfi                pnfi                 ifi                 rni 
##               0.679               0.622               0.699               0.698 
##                logl   unrestricted.logl                 aic                 bic 
##          -51161.608          -49650.884          102423.217          102679.198 
##              ntotal                bic2               rmsea      rmsea.ci.lower 
##            1236.000          102520.377               0.090               0.087 
##      rmsea.ci.upper        rmsea.pvalue                 rmr          rmr_nomean 
##               0.093               0.000               0.291               0.291 
##                srmr        srmr_bentler srmr_bentler_nomean                crmr 
##               0.143               0.143               0.143               0.148 
##         crmr_nomean          srmr_mplus   srmr_mplus_nomean               cn_05 
##               0.148               0.143               0.143             129.727 
##               cn_01                 gfi                agfi                pgfi 
##             137.009               0.815               0.781               0.689 
##                 mfi                ecvi 
##               0.329               2.525
#dput(names(fitmeasures(fit.g)))
fit.indices <- c("npar", "chisq", "df", "pvalue", "cfi", "rmsea", "rmsea.ci.lower", "rmsea.ci.upper", "srmr")

# we compare the models by inspecting certain indices
round(fitmeasures(fit.g)[fit.indices],    3)
##           npar          chisq             df         pvalue            cfi 
##         50.000       5411.707        275.000          0.000          0.436 
##          rmsea rmsea.ci.lower rmsea.ci.upper           srmr 
##          0.123          0.120          0.126          0.114
round(fitmeasures(fit.5f.o)[fit.indices], 3)
##           npar          chisq             df         pvalue            cfi 
##         50.000       3021.448        275.000          0.000          0.698 
##          rmsea rmsea.ci.lower rmsea.ci.upper           srmr 
##          0.090          0.087          0.093          0.143
round(fitmeasures(fit.5f.c)[fit.indices], 3)
##           npar          chisq             df         pvalue            cfi 
##         60.000       2230.852        265.000          0.000          0.784 
##          rmsea rmsea.ci.lower rmsea.ci.upper           srmr 
##          0.077          0.075          0.080          0.077
# model comparison using anova()
anova(fit.5f.o, fit.5f.c)
## Chi-Squared Difference Test
## 
##           Df    AIC    BIC  Chisq Chisq diff Df diff Pr(>Chisq)    
## fit.5f.c 265 101653 101960 2230.9                                  
## fit.5f.o 275 102423 102679 3021.4      790.6      10  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1