Rmd

Die Konfirmatorische FA liefert Anpassungsindices die Aussagen darüber machen, wie gut das Modell (welche Items bilden welche Faktoren) zu den vorliegenden Daten passt. Hier ein paar Hinweise zu diesen Indices.

\(\chi^2\) und Sig.: Hat vor allem bei großen Stichproben hohe Power, d. h. die Unterschiede zwischen der realen Covarianzmatrix und der aufgrund des Modells reproduzierten Covarianzmatrix werden sig., obwohl sie praktisch unbedeutend sein können. Daher andere Fit-Parameter.

Daumenregeln: Badness of fit index RMSEA:

  • RMSEA < 0.05 gute Modellpassung
  • 0.05 < RMSEA < 0.08 adäquate/mäßige Modellpassung
  • RMSEA > 0.08 schlechte Modellpassung

Üblicherweise wird das 90%-Konfidenzintervall für den RMSEA angegeben! Sog. „Test of close fit“:

  • Nullhypothese: RMSEA ≤ 0.05 Nullhypothese kann beibehalten werden, wenn die untere Intervallgrenze des 90%-Konfidenzintervalls kleiner als 0.05 ist.
  • andere Quellen (video-tutorial) setzen die Untergrenze des Intervalls etwas höher an (0.07 wird als ok bezeichnet)

Goodness of fit indices:

  • Tucker-Lewis NNFI,
  • Bentler CFI Daumenregel: sollten größer als .9 sein

Beispiel Emotionale Intelligenz als CFA mit library(lavaan)

Ansatz: Passt das zwei Faktor Modell (EA Emotional Attention) (EC Emotional Clarity) zu einem gegebenen Datensatz?

Die beiden Skalen ‘emotionale Selbstaufmerksamkeit’ (EA Emotional Attention) sowie ‘Klarheit über eigene Gefühle’ (EC Emotional Clarity) sind theoretisch angenommen und über entsprechende Formulierungen sprachlich umgesetzt. Alle ungeraden Items erfassen ‘emotionale Selbstaufmerksamkeit’ (EA), alle geraden Items ‘Klarheit über eigene Gefühle’ (EC).

Die Items sind:

  • i1 EA Ich denke über meine Gefühle nach.
  • i2 EC Ich kann meine Gefühle benennen.
  • i3 EA Ich schenke meinen Gefühlen Aufmerksamkeit.
  • i4 EC Ich bin mir im unklaren darüber, was ich fühle.
  • i5 EA Ich beschäftige mich mit meinen Gefühlen.
  • i6 EC Ich habe Schwierigkeiten, meine Gefühle zu beschreiben.
  • i7 EA Ich denke darüber nach, wie ich mich fühle.
  • i8 EC Ich weiß, was ich fühle.
  • i9 EA Ich beobachte meine Gefühle.
  • i10 EC Ich habe Schwierigkeiten, meinen Gefühlen einen Namen zu geben.
  • i11 EA Ich ache darauf, wie ich mich fühle.
  • i12 EC Ich bin mir unsicher, was ich eigentlich fühle.

Die Items sind skaliert von 1 bis 4 (fast nie/manchmal/oft/fast immer)

# get data
ddf <- read.delim("https://md.psych.bio.uni-goettingen.de/mv/data/virt/v_ei.txt")
head(ddf)
##   i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12
## 1  4  3  4  2  3  1  4  3  3   1   3   3
## 2  4  3  3  1  4  1  4  4  4   1   3   2
## 3  4  3  4  2  4  2  4  2  4   1   3   3
## 4  3  3  2  2  1  2  4  3  1   2   2   3
## 5  4  4  4  4  4  1  4  4  4   2   3   1
## 6  2  4  3  2  4  2  2  3  3   2   3   2
# get cov matrix
t.cov <- cov(ddf)
# and correlation matrix
#cor(ddf)
require(lavaan)
## Lade nötiges Paket: lavaan
## This is lavaan 0.6-11
## lavaan is FREE software! Please report any bugs.
m.ei <- '
  EA =~ i1 + i3 + i5 + i7 + i9 + i11
  EC =~ i2 + i4 + i6 + i8 + i10 + i12
'
# fit the an orthogonal model
fit.o <- cfa(m.ei, data=ddf, orthogonal=T)

# fit a model that allows correlation of factors
fit.c <- cfa(m.ei, data=ddf, orthogonal=F)

# display summary output
summary(fit.o, fit.measures=TRUE)
## lavaan 0.6-11 ended normally after 27 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        24
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                69.883
##   Degrees of freedom                                54
##   P-value (Chi-square)                           0.072
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.952
##   Tucker-Lewis Index (TLI)                       0.942
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1440.660
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                2929.320
##   Bayesian (BIC)                              2991.844
##   Sample-size adjusted Bayesian (BIC)         2916.046
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.054
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.088
##   P-value RMSEA <= 0.05                          0.403
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.111
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA =~                                               
##     i1                1.000                           
##     i3                0.918    0.234    3.932    0.000
##     i5                0.773    0.230    3.358    0.001
##     i7                0.465    0.209    2.230    0.026
##     i9                0.976    0.246    3.961    0.000
##     i11               0.705    0.192    3.675    0.000
##   EC =~                                               
##     i2                1.000                           
##     i4               -0.914    0.131   -6.981    0.000
##     i6               -0.940    0.131   -7.154    0.000
##     i8                0.987    0.142    6.970    0.000
##     i10              -1.030    0.135   -7.649    0.000
##     i12              -0.868    0.126   -6.904    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA ~~                                               
##     EC                0.000                           
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.550    0.102    5.377    0.000
##    .i3                0.481    0.088    5.438    0.000
##    .i5                0.677    0.108    6.260    0.000
##    .i7                0.776    0.114    6.817    0.000
##    .i9                0.518    0.097    5.359    0.000
##    .i11               0.398    0.067    5.917    0.000
##    .i2                0.384    0.069    5.597    0.000
##    .i4                0.454    0.075    6.034    0.000
##    .i6                0.437    0.074    5.931    0.000
##    .i8                0.532    0.088    6.040    0.000
##    .i10               0.394    0.071    5.547    0.000
##    .i12               0.426    0.070    6.076    0.000
##     EA                0.306    0.114    2.684    0.007
##     EC                0.550    0.127    4.313    0.000
summary(fit.c, fit.measures=TRUE)
## lavaan 0.6-11 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        25
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                61.027
##   Degrees of freedom                                53
##   P-value (Chi-square)                           0.210
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.976
##   Tucker-Lewis Index (TLI)                       0.970
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1436.232
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                2922.463
##   Bayesian (BIC)                              2987.593
##   Sample-size adjusted Bayesian (BIC)         2908.636
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.039
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.077
##   P-value RMSEA <= 0.05                          0.642
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.055
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA =~                                               
##     i1                1.000                           
##     i3                0.927    0.234    3.963    0.000
##     i5                0.799    0.233    3.428    0.001
##     i7                0.492    0.211    2.328    0.020
##     i9                0.996    0.248    4.017    0.000
##     i11               0.715    0.193    3.704    0.000
##   EC =~                                               
##     i2                1.000                           
##     i4               -0.904    0.130   -6.949    0.000
##     i6               -0.932    0.130   -7.151    0.000
##     i8                0.995    0.140    7.090    0.000
##     i10              -1.029    0.133   -7.713    0.000
##     i12              -0.861    0.125   -6.897    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA ~~                                               
##     EC                0.151    0.060    2.513    0.012
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.560    0.101    5.549    0.000
##    .i3                0.484    0.087    5.559    0.000
##    .i5                0.670    0.107    6.268    0.000
##    .i7                0.770    0.113    6.808    0.000
##    .i9                0.516    0.095    5.431    0.000
##    .i11               0.398    0.067    5.984    0.000
##    .i2                0.381    0.068    5.602    0.000
##    .i4                0.462    0.076    6.086    0.000
##    .i6                0.441    0.074    5.973    0.000
##    .i8                0.520    0.087    6.009    0.000
##    .i10               0.391    0.070    5.555    0.000
##    .i12               0.430    0.070    6.113    0.000
##     EA                0.297    0.111    2.674    0.007
##     EC                0.553    0.127    4.336    0.000
# get modification indices also
summary(fit.o, fit.measures = TRUE, modindices = TRUE)
## lavaan 0.6-11 ended normally after 27 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        24
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                69.883
##   Degrees of freedom                                54
##   P-value (Chi-square)                           0.072
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.952
##   Tucker-Lewis Index (TLI)                       0.942
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1440.660
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                2929.320
##   Bayesian (BIC)                              2991.844
##   Sample-size adjusted Bayesian (BIC)         2916.046
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.054
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.088
##   P-value RMSEA <= 0.05                          0.403
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.111
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA =~                                               
##     i1                1.000                           
##     i3                0.918    0.234    3.932    0.000
##     i5                0.773    0.230    3.358    0.001
##     i7                0.465    0.209    2.230    0.026
##     i9                0.976    0.246    3.961    0.000
##     i11               0.705    0.192    3.675    0.000
##   EC =~                                               
##     i2                1.000                           
##     i4               -0.914    0.131   -6.981    0.000
##     i6               -0.940    0.131   -7.154    0.000
##     i8                0.987    0.142    6.970    0.000
##     i10              -1.030    0.135   -7.649    0.000
##     i12              -0.868    0.126   -6.904    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA ~~                                               
##     EC                0.000                           
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.550    0.102    5.377    0.000
##    .i3                0.481    0.088    5.438    0.000
##    .i5                0.677    0.108    6.260    0.000
##    .i7                0.776    0.114    6.817    0.000
##    .i9                0.518    0.097    5.359    0.000
##    .i11               0.398    0.067    5.917    0.000
##    .i2                0.384    0.069    5.597    0.000
##    .i4                0.454    0.075    6.034    0.000
##    .i6                0.437    0.074    5.931    0.000
##    .i8                0.532    0.088    6.040    0.000
##    .i10               0.394    0.071    5.547    0.000
##    .i12               0.426    0.070    6.076    0.000
##     EA                0.306    0.114    2.684    0.007
##     EC                0.550    0.127    4.313    0.000
## 
## Modification Indices:
## 
##     lhs op rhs    mi    epc sepc.lv sepc.all sepc.nox
## 27   EA ~~  EC 8.407  0.151   0.369    0.369    0.369
## 28   EA =~  i2 0.693  0.122   0.068    0.070    0.070
## 29   EA =~  i4 0.336  0.090   0.050    0.052    0.052
## 30   EA =~  i6 0.002  0.007   0.004    0.004    0.004
## 31   EA =~  i8 4.259  0.346   0.192    0.186    0.186
## 32   EA =~ i10 0.627 -0.118  -0.065   -0.066   -0.066
## 33   EA =~ i12 0.195  0.066   0.037    0.040    0.040
## 34   EC =~  i1 0.136  0.043   0.032    0.035    0.035
## 35   EC =~  i3 0.367  0.066   0.049    0.057    0.057
## 36   EC =~  i5 0.824  0.112   0.083    0.090    0.090
## 37   EC =~  i7 0.966  0.126   0.094    0.102    0.102
## 38   EC =~  i9 1.042  0.116   0.086    0.096    0.096
## 39   EC =~ i11 0.341  0.056   0.042    0.056    0.056
## 40   i1 ~~  i3 0.006 -0.006  -0.006   -0.012   -0.012
## 41   i1 ~~  i5 3.456 -0.148  -0.148   -0.243   -0.243
## 42   i1 ~~  i7 0.055  0.018   0.018    0.028    0.028
## 43   i1 ~~  i9 3.151  0.149   0.149    0.278    0.278
## 44   i1 ~~ i11 0.087 -0.019  -0.019   -0.041   -0.041
## 45   i1 ~~  i2 0.733  0.047   0.047    0.103    0.103
## 46   i1 ~~  i4 0.569  0.044   0.044    0.088    0.088
## 47   i1 ~~  i6 5.979 -0.141  -0.141   -0.288   -0.288
## 48   i1 ~~  i8 0.670 -0.052  -0.052   -0.096   -0.096
## 49   i1 ~~ i10 2.326  0.086   0.086    0.185    0.185
## 50   i1 ~~ i12 0.036 -0.011  -0.011   -0.022   -0.022
## 51   i3 ~~  i5 0.261  0.038   0.038    0.066    0.066
## 52   i3 ~~  i7 0.316 -0.041  -0.041   -0.066   -0.066
## 53   i3 ~~  i9 0.209 -0.035  -0.035   -0.071   -0.071
## 54   i3 ~~ i11 0.188  0.026   0.026    0.060    0.060
## 55   i3 ~~  i2 0.157 -0.021  -0.021   -0.048   -0.048
## 56   i3 ~~  i4 0.560  0.041   0.041    0.087    0.087
## 57   i3 ~~  i6 0.178  0.023   0.023    0.050    0.050
## 58   i3 ~~  i8 1.210  0.065   0.065    0.128    0.128
## 59   i3 ~~ i10 4.178 -0.107  -0.107   -0.247   -0.247
## 60   i3 ~~ i12 1.584  0.066   0.066    0.146    0.146
## 61   i5 ~~  i7 0.359  0.047   0.047    0.065    0.065
## 62   i5 ~~  i9 0.060 -0.019  -0.019   -0.032   -0.032
## 63   i5 ~~ i11 2.180  0.093   0.093    0.179    0.179
## 64   i5 ~~  i2 0.230  0.028   0.028    0.055    0.055
## 65   i5 ~~  i4 0.055 -0.014  -0.014   -0.026   -0.026
## 66   i5 ~~  i6 2.314  0.093   0.093    0.171    0.171
## 67   i5 ~~  i8 5.745  0.160   0.160    0.267    0.267
## 68   i5 ~~ i10 0.235  0.029   0.029    0.056    0.056
## 69   i5 ~~ i12 0.016  0.008   0.008    0.014    0.014
## 70   i7 ~~  i9 0.001  0.003   0.003    0.004    0.004
## 71   i7 ~~ i11 0.037 -0.012  -0.012   -0.022   -0.022
## 72   i7 ~~  i2 2.317  0.093   0.093    0.170    0.170
## 73   i7 ~~  i4 0.082 -0.018  -0.018   -0.031   -0.031
## 74   i7 ~~  i6 1.179  0.069   0.069    0.118    0.118
## 75   i7 ~~  i8 0.517  0.050   0.050    0.078    0.078
## 76   i7 ~~ i10 0.163 -0.025  -0.025   -0.045   -0.045
## 77   i7 ~~ i12 1.304  0.071   0.071    0.123    0.123
## 78   i9 ~~ i11 1.495 -0.078  -0.078   -0.171   -0.171
## 79   i9 ~~  i2 0.000  0.000   0.000    0.001    0.001
## 80   i9 ~~  i4 0.067  0.015   0.015    0.030    0.030
## 81   i9 ~~  i6 0.586 -0.043  -0.043   -0.090   -0.090
## 82   i9 ~~  i8 0.046  0.013   0.013    0.025    0.025
## 83   i9 ~~ i10 0.037 -0.011  -0.011   -0.023   -0.023
## 84   i9 ~~ i12 0.001 -0.002  -0.002   -0.004   -0.004
## 85  i11 ~~  i2 0.267 -0.024  -0.024   -0.061   -0.061
## 86  i11 ~~  i4 0.765 -0.042  -0.042   -0.099   -0.099
## 87  i11 ~~  i6 2.248  0.071   0.071    0.172    0.172
## 88  i11 ~~  i8 0.000  0.000   0.000    0.000    0.000
## 89  i11 ~~ i10 0.309 -0.026  -0.026   -0.065   -0.065
## 90  i11 ~~ i12 1.516 -0.057  -0.057   -0.139   -0.139
## 91   i2 ~~  i4 3.914  0.108   0.108    0.260    0.260
## 92   i2 ~~  i6 1.208  0.060   0.060    0.147    0.147
## 93   i2 ~~  i8 0.465  0.040   0.040    0.089    0.089
## 94   i2 ~~ i10 0.503 -0.039  -0.039   -0.101   -0.101
## 95   i2 ~~ i12 2.769 -0.088  -0.088   -0.217   -0.217
## 96   i4 ~~  i6 8.883  0.166   0.166    0.373    0.373
## 97   i4 ~~  i8 1.727  0.079   0.079    0.162    0.162
## 98   i4 ~~ i10 0.226 -0.027  -0.027   -0.063   -0.063
## 99   i4 ~~ i12 0.982  0.053   0.053    0.121    0.121
## 100  i6 ~~  i8 1.314  0.069   0.069    0.143    0.143
## 101  i6 ~~ i10 0.550  0.041   0.041    0.100    0.100
## 102  i6 ~~ i12 2.153 -0.079  -0.079   -0.182   -0.182
## 103  i8 ~~ i10 0.674 -0.050  -0.050   -0.108   -0.108
## 104  i8 ~~ i12 0.679 -0.048  -0.048   -0.101   -0.101
## 105 i10 ~~ i12 3.658 -0.103  -0.103   -0.251   -0.251
summary(fit.c, fit.measures = TRUE, modindices = TRUE)
## lavaan 0.6-11 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        25
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                61.027
##   Degrees of freedom                                53
##   P-value (Chi-square)                           0.210
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.976
##   Tucker-Lewis Index (TLI)                       0.970
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1436.232
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                2922.463
##   Bayesian (BIC)                              2987.593
##   Sample-size adjusted Bayesian (BIC)         2908.636
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.039
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.077
##   P-value RMSEA <= 0.05                          0.642
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.055
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA =~                                               
##     i1                1.000                           
##     i3                0.927    0.234    3.963    0.000
##     i5                0.799    0.233    3.428    0.001
##     i7                0.492    0.211    2.328    0.020
##     i9                0.996    0.248    4.017    0.000
##     i11               0.715    0.193    3.704    0.000
##   EC =~                                               
##     i2                1.000                           
##     i4               -0.904    0.130   -6.949    0.000
##     i6               -0.932    0.130   -7.151    0.000
##     i8                0.995    0.140    7.090    0.000
##     i10              -1.029    0.133   -7.713    0.000
##     i12              -0.861    0.125   -6.897    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA ~~                                               
##     EC                0.151    0.060    2.513    0.012
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.560    0.101    5.549    0.000
##    .i3                0.484    0.087    5.559    0.000
##    .i5                0.670    0.107    6.268    0.000
##    .i7                0.770    0.113    6.808    0.000
##    .i9                0.516    0.095    5.431    0.000
##    .i11               0.398    0.067    5.984    0.000
##    .i2                0.381    0.068    5.602    0.000
##    .i4                0.462    0.076    6.086    0.000
##    .i6                0.441    0.074    5.973    0.000
##    .i8                0.520    0.087    6.009    0.000
##    .i10               0.391    0.070    5.555    0.000
##    .i12               0.430    0.070    6.113    0.000
##     EA                0.297    0.111    2.674    0.007
##     EC                0.553    0.127    4.336    0.000
## 
## Modification Indices:
## 
##     lhs op rhs    mi    epc sepc.lv sepc.all sepc.nox
## 28   EA =~  i2 0.103  0.054   0.030    0.031    0.031
## 29   EA =~  i4 1.074  0.185   0.101    0.105    0.105
## 30   EA =~  i6 0.299  0.096   0.053    0.055    0.055
## 31   EA =~  i8 3.110  0.336   0.183    0.177    0.177
## 32   EA =~ i10 0.071 -0.046  -0.025   -0.025   -0.025
## 33   EA =~ i12 0.829  0.157   0.085    0.093    0.093
## 34   EC =~  i1 0.254 -0.070  -0.052   -0.056   -0.056
## 35   EC =~  i3 0.049 -0.029  -0.021   -0.025   -0.025
## 36   EC =~  i5 0.138  0.053   0.039    0.042    0.042
## 37   EC =~  i7 0.512  0.103   0.077    0.084    0.084
## 38   EC =~  i9 0.034  0.025   0.019    0.021    0.021
## 39   EC =~ i11 0.012 -0.012  -0.009   -0.012   -0.012
## 40   i1 ~~  i3 0.010  0.008   0.008    0.015    0.015
## 41   i1 ~~  i5 3.273 -0.141  -0.141   -0.230   -0.230
## 42   i1 ~~  i7 0.028  0.013   0.013    0.020    0.020
## 43   i1 ~~  i9 3.099  0.140   0.140    0.260    0.260
## 44   i1 ~~ i11 0.030 -0.011  -0.011   -0.023   -0.023
## 45   i1 ~~  i2 0.512  0.040   0.040    0.086    0.086
## 46   i1 ~~  i4 0.788  0.052   0.052    0.103    0.103
## 47   i1 ~~  i6 5.159 -0.132  -0.132   -0.265   -0.265
## 48   i1 ~~  i8 0.782 -0.056  -0.056   -0.103   -0.103
## 49   i1 ~~ i10 2.712  0.093   0.093    0.198    0.198
## 50   i1 ~~ i12 0.002 -0.003  -0.003   -0.006   -0.006
## 51   i3 ~~  i5 0.200  0.032   0.032    0.057    0.057
## 52   i3 ~~  i7 0.413 -0.046  -0.046   -0.075   -0.075
## 53   i3 ~~  i9 0.177 -0.031  -0.031   -0.062   -0.062
## 54   i3 ~~ i11 0.215  0.027   0.027    0.062    0.062
## 55   i3 ~~  i2 0.306 -0.028  -0.028   -0.066   -0.066
## 56   i3 ~~  i4 0.804  0.049   0.049    0.104    0.104
## 57   i3 ~~  i6 0.300  0.030   0.030    0.064    0.064
## 58   i3 ~~  i8 1.020  0.059   0.059    0.118    0.118
## 59   i3 ~~ i10 3.523 -0.098  -0.098   -0.226   -0.226
## 60   i3 ~~ i12 1.933  0.073   0.073    0.161    0.161
## 61   i5 ~~  i7 0.255  0.040   0.040    0.055    0.055
## 62   i5 ~~  i9 0.127 -0.027  -0.027   -0.046   -0.046
## 63   i5 ~~ i11 1.974  0.087   0.087    0.169    0.169
## 64   i5 ~~  i2 0.136  0.021   0.021    0.043    0.043
## 65   i5 ~~  i4 0.018 -0.008  -0.008   -0.015   -0.015
## 66   i5 ~~  i6 2.570  0.098   0.098    0.180    0.180
## 67   i5 ~~  i8 5.538  0.155   0.155    0.263    0.263
## 68   i5 ~~ i10 0.370  0.036   0.036    0.070    0.070
## 69   i5 ~~ i12 0.049  0.013   0.013    0.024    0.024
## 70   i7 ~~  i9 0.007 -0.006  -0.006   -0.010   -0.010
## 71   i7 ~~ i11 0.073 -0.017  -0.017   -0.030   -0.030
## 72   i7 ~~  i2 2.172  0.089   0.089    0.165    0.165
## 73   i7 ~~  i4 0.059 -0.016  -0.016   -0.026   -0.026
## 74   i7 ~~  i6 1.253  0.071   0.071    0.122    0.122
## 75   i7 ~~  i8 0.450  0.046   0.046    0.073    0.073
## 76   i7 ~~ i10 0.118 -0.021  -0.021   -0.039   -0.039
## 77   i7 ~~ i12 1.391  0.073   0.073    0.127    0.127
## 78   i9 ~~ i11 1.462 -0.075  -0.075   -0.165   -0.165
## 79   i9 ~~  i2 0.020 -0.008  -0.008   -0.017   -0.017
## 80   i9 ~~  i4 0.160  0.023   0.023    0.047    0.047
## 81   i9 ~~  i6 0.417 -0.036  -0.036   -0.076   -0.076
## 82   i9 ~~  i8 0.014  0.007   0.007    0.014    0.014
## 83   i9 ~~ i10 0.002 -0.002  -0.002   -0.005   -0.005
## 84   i9 ~~ i12 0.010  0.006   0.006    0.012    0.012
## 85  i11 ~~  i2 0.402 -0.029  -0.029   -0.074   -0.074
## 86  i11 ~~  i4 0.553 -0.036  -0.036   -0.084   -0.084
## 87  i11 ~~  i6 2.494  0.075   0.075    0.180    0.180
## 88  i11 ~~  i8 0.005 -0.004  -0.004   -0.008   -0.008
## 89  i11 ~~ i10 0.191 -0.020  -0.020   -0.051   -0.051
## 90  i11 ~~ i12 1.235 -0.052  -0.052   -0.125   -0.125
## 91   i2 ~~  i4 3.462  0.101   0.101    0.242    0.242
## 92   i2 ~~  i6 1.109  0.057   0.057    0.139    0.139
## 93   i2 ~~  i8 0.218  0.027   0.027    0.061    0.061
## 94   i2 ~~ i10 0.363 -0.033  -0.033   -0.086   -0.086
## 95   i2 ~~ i12 2.844 -0.088  -0.088   -0.218   -0.218
## 96   i4 ~~  i6 9.440  0.171   0.171    0.379    0.379
## 97   i4 ~~  i8 1.816  0.081   0.081    0.165    0.165
## 98   i4 ~~ i10 0.136 -0.021  -0.021   -0.048   -0.048
## 99   i4 ~~ i12 1.272  0.061   0.061    0.136    0.136
## 100  i6 ~~  i8 1.527  0.074   0.074    0.154    0.154
## 101  i6 ~~ i10 0.604  0.043   0.043    0.104    0.104
## 102  i6 ~~ i12 1.710 -0.070  -0.070   -0.161   -0.161
## 103  i8 ~~ i10 0.372 -0.036  -0.036   -0.081   -0.081
## 104  i8 ~~ i12 0.568 -0.044  -0.044   -0.092   -0.092
## 105 i10 ~~ i12 3.428 -0.099  -0.099   -0.241   -0.241
# get standardized indices
standardizedSolution(fit.o) 
##    lhs op rhs est.std    se       z pvalue ci.lower ci.upper
## 1   EA =~  i1   0.598 0.091   6.553  0.000    0.419    0.777
## 2   EA =~  i3   0.591 0.092   6.444  0.000    0.411    0.771
## 3   EA =~  i5   0.461 0.101   4.565  0.000    0.263    0.659
## 4   EA =~  i7   0.281 0.112   2.503  0.012    0.061    0.500
## 5   EA =~  i9   0.600 0.091   6.584  0.000    0.421    0.779
## 6   EA =~ i11   0.526 0.096   5.458  0.000    0.337    0.715
## 7   EC =~  i2   0.767 0.050  15.202  0.000    0.668    0.866
## 8   EC =~  i4  -0.709 0.058 -12.191  0.000   -0.823   -0.595
## 9   EC =~  i6  -0.726 0.056 -12.946  0.000   -0.835   -0.616
## 10  EC =~  i8   0.708 0.058  12.142  0.000    0.594    0.823
## 11  EC =~ i10  -0.772 0.050 -15.519  0.000   -0.870   -0.675
## 12  EC =~ i12  -0.702 0.059 -11.873  0.000   -0.818   -0.586
## 13  i1 ~~  i1   0.642 0.109   5.882  0.000    0.428    0.856
## 14  i3 ~~  i3   0.651 0.108   5.998  0.000    0.438    0.863
## 15  i5 ~~  i5   0.787 0.093   8.442  0.000    0.604    0.970
## 16  i7 ~~  i7   0.921 0.063  14.639  0.000    0.798    1.045
## 17  i9 ~~  i9   0.640 0.109   5.849  0.000    0.425    0.854
## 18 i11 ~~ i11   0.723 0.101   7.138  0.000    0.525    0.922
## 19  i2 ~~  i2   0.411 0.077   5.310  0.000    0.259    0.563
## 20  i4 ~~  i4   0.497 0.083   6.020  0.000    0.335    0.659
## 21  i6 ~~  i6   0.474 0.081   5.823  0.000    0.314    0.633
## 22  i8 ~~  i8   0.498 0.083   6.033  0.000    0.337    0.660
## 23 i10 ~~ i10   0.403 0.077   5.243  0.000    0.253    0.554
## 24 i12 ~~ i12   0.507 0.083   6.108  0.000    0.344    0.670
## 25  EA ~~  EA   1.000 0.000      NA     NA    1.000    1.000
## 26  EC ~~  EC   1.000 0.000      NA     NA    1.000    1.000
## 27  EA ~~  EC   0.000 0.000      NA     NA    0.000    0.000
standardizedSolution(fit.c) 
##    lhs op rhs est.std    se       z pvalue ci.lower ci.upper
## 1   EA =~  i1   0.589 0.090   6.533  0.000    0.412    0.765
## 2   EA =~  i3   0.587 0.090   6.513  0.000    0.411    0.764
## 3   EA =~  i5   0.469 0.099   4.733  0.000    0.275    0.664
## 4   EA =~  i7   0.292 0.111   2.643  0.008    0.075    0.509
## 5   EA =~  i9   0.603 0.089   6.770  0.000    0.428    0.777
## 6   EA =~ i11   0.525 0.095   5.530  0.000    0.339    0.711
## 7   EC =~  i2   0.769 0.050  15.398  0.000    0.672    0.867
## 8   EC =~  i4  -0.703 0.059 -11.958  0.000   -0.818   -0.588
## 9   EC =~  i6  -0.722 0.056 -12.813  0.000   -0.832   -0.612
## 10  EC =~  i8   0.716 0.057  12.545  0.000    0.604    0.828
## 11  EC =~ i10  -0.774 0.049 -15.702  0.000   -0.871   -0.678
## 12  EC =~ i12  -0.698 0.059 -11.750  0.000   -0.815   -0.582
## 13  i1 ~~  i1   0.654 0.106   6.163  0.000    0.446    0.861
## 14  i3 ~~  i3   0.655 0.106   6.182  0.000    0.447    0.863
## 15  i5 ~~  i5   0.780 0.093   8.370  0.000    0.597    0.962
## 16  i7 ~~  i7   0.915 0.065  14.159  0.000    0.788    1.041
## 17  i9 ~~  i9   0.637 0.107   5.930  0.000    0.426    0.847
## 18 i11 ~~ i11   0.724 0.100   7.263  0.000    0.529    0.920
## 19  i2 ~~  i2   0.408 0.077   5.304  0.000    0.257    0.559
## 20  i4 ~~  i4   0.505 0.083   6.111  0.000    0.343    0.668
## 21  i6 ~~  i6   0.479 0.081   5.885  0.000    0.319    0.638
## 22  i8 ~~  i8   0.487 0.082   5.953  0.000    0.327    0.647
## 23 i10 ~~ i10   0.400 0.076   5.242  0.000    0.251    0.550
## 24 i12 ~~ i12   0.512 0.083   6.169  0.000    0.349    0.675
## 25  EA ~~  EA   1.000 0.000      NA     NA    1.000    1.000
## 26  EC ~~  EC   1.000 0.000      NA     NA    1.000    1.000
## 27  EA ~~  EC   0.372 0.114   3.261  0.001    0.149    0.596
# model test
anova(fit.o, fit.c)
## Chi-Squared Difference Test
## 
##       Df    AIC    BIC  Chisq Chisq diff Df diff Pr(>Chisq)   
## fit.c 53 2922.5 2987.6 61.027                                 
## fit.o 54 2929.3 2991.8 69.883     8.8564       1   0.002921 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# qgraph is missing - to fix
# we plot the solution using library(semPlot)
# require(semPlot)
# path plot with unstandardized estimates
# semPlot::semPaths(fit.o, 'est')
# semPlot::semPaths(fit.c, 'est')
# path plot with standardized estimates
# semPaths(fit.o, 'est', 'std')
# semPaths(fit.c, 'est', 'std')

semPlot::semPaths(fit.c, "std")

Aufruf des gefitteten Modells fit gibt nur den globalen Signifikanztest aus, ob die reproduzierte und die originale Covarianzmatrizen signifikant unterschiedlich sind. Bei sehr hohem n werden auch sehr kleine Unterschiede signifikant. Im Beispiel wird die Covarianzmatrix wird sehr gut reproduziert - die Unterschiede könnten auch Zufallsunterschiede sein.

Summary des Modells summary(fit) gibt noch die Koeffizienten mit aus (unstandardisiert). Die standardisierten Koeffizienten, die auch in der Grafik verwendet werden, erhält man über den Befehl standardizedSolution(fit). Für alle Indikatoren wird das Ladungsgewicht ausgegeben, das aussagt, wieviel Varianz der Variablen durch den Faktor erklärt wird (entspricht der Kommunalität). Dieser Anteil wird auf Signifikanz geprüft.

Das Flag fit.measures in summary(fit, fit.measures=TRUE) fordert ausführlichere Details zur Modellanpassung an.

Neben dem exakten Übereinstimmungstest auch ein Test auf annähernde Übereinstimmung berechnet, der auf dem sog. “root mean square error of approximation” beruht. Faustregel: Der Wert des Koeffizienten RMSEA sollte kleiner als 0.05 sein, wenn die Modellanpassung noch als halbwegs befriedigend gelten soll.

CFI ist mit .976 fast sehr gut (.980 wäre sehr gut).

RMSEA mit 0.039 ebenfalls gut (der Wert sollte kleiner .05 sein, idealerweise auch der Wert des oberen Konfidenzintervalls, der hier 0.077 ist)

Für einen guten Modellfit sprechen:

CFI > .90 (Der CFI vergleicht das spezifizierte Modell mit dem theoretisch schlechtesten Modell) RMSEA < 0,05 (Der RMSEA zeigt an, wie gut sich die Daten mit Hilfe des spezifizierten Modell reproduzieren lassen. Je kleiner die Abweichungen, desto besser) RMSR < 0,10 (ähnlich wie der RMSEA, berücksichtigt jedoch nicht die Stichprobengröße für die Bewertung der Abweichung)

Obige Modellspezifikation fixiert automatisch die erste Ladung eines Faktors auf 1.0 und lässt die Varianz des Faktors als zu schätzenden Parameter frei. Der Nachteil ist, dass dadurch die Signifikanz der ersten Ladung pro Faktor nicht getestet werden kann. Statt dessen kann mit der Option “std.lv=T” festgelegt werden, dass die Varianzen der Faktoren auf 1.0 fixiert werden und auch die ersten Ladungen der Faktoren freie (d.h. zu schätzende) Parameter sind (geht nur, wenn die latenten Variablen nicht abhängige Variablen sind): m1_fit = sem(model1, data=ddf, std.lv=T) summary(m1_fit, standardized=TRUE)

Vergleich eines ‘guten’ und eines ‘schlechten’ Modells mit lavaan()

Idee: Die ‘richtige’ Zuordnung der Items zu den Faktoren wird verglichen mit einer ‘schlechten’, d. h. die ersten 6 Items und die zweiten 6 werden als je ein Faktor definiert.

Hierdurch können wir gut erkennen, wie sich die einzelnen Indices zueinander verhalten.

# get data
ddf <- read.delim("https://md.psych.bio.uni-goettingen.de/mv/data/virt/v_ei.txt")
head(ddf)
##   i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12
## 1  4  3  4  2  3  1  4  3  3   1   3   3
## 2  4  3  3  1  4  1  4  4  4   1   3   2
## 3  4  3  4  2  4  2  4  2  4   1   3   3
## 4  3  3  2  2  1  2  4  3  1   2   2   3
## 5  4  4  4  4  4  1  4  4  4   2   3   1
## 6  2  4  3  2  4  2  2  3  3   2   3   2
require(lavaan)
# get cov matrix
#cov(ddf)
# and correlation matrix
#cor(ddf)

m.ei.good <- '
# EA Emotional Attention
EA =~ i1 + i3 + i5 + i7 + i9 + i11
# EC Emotional Clarity
EC =~ i2 + i4 + i6 + i8 + i10 + i12
'

# fit orthogonal good model
fit.g.o <- cfa(m.ei.good, data=ddf, orthogonal=T)
summary(fit.g.o, fit.measures=TRUE)
## lavaan 0.6-11 ended normally after 27 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        24
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                69.883
##   Degrees of freedom                                54
##   P-value (Chi-square)                           0.072
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.952
##   Tucker-Lewis Index (TLI)                       0.942
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1440.660
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                2929.320
##   Bayesian (BIC)                              2991.844
##   Sample-size adjusted Bayesian (BIC)         2916.046
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.054
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.088
##   P-value RMSEA <= 0.05                          0.403
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.111
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA =~                                               
##     i1                1.000                           
##     i3                0.918    0.234    3.932    0.000
##     i5                0.773    0.230    3.358    0.001
##     i7                0.465    0.209    2.230    0.026
##     i9                0.976    0.246    3.961    0.000
##     i11               0.705    0.192    3.675    0.000
##   EC =~                                               
##     i2                1.000                           
##     i4               -0.914    0.131   -6.981    0.000
##     i6               -0.940    0.131   -7.154    0.000
##     i8                0.987    0.142    6.970    0.000
##     i10              -1.030    0.135   -7.649    0.000
##     i12              -0.868    0.126   -6.904    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA ~~                                               
##     EC                0.000                           
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.550    0.102    5.377    0.000
##    .i3                0.481    0.088    5.438    0.000
##    .i5                0.677    0.108    6.260    0.000
##    .i7                0.776    0.114    6.817    0.000
##    .i9                0.518    0.097    5.359    0.000
##    .i11               0.398    0.067    5.917    0.000
##    .i2                0.384    0.069    5.597    0.000
##    .i4                0.454    0.075    6.034    0.000
##    .i6                0.437    0.074    5.931    0.000
##    .i8                0.532    0.088    6.040    0.000
##    .i10               0.394    0.071    5.547    0.000
##    .i12               0.426    0.070    6.076    0.000
##     EA                0.306    0.114    2.684    0.007
##     EC                0.550    0.127    4.313    0.000
# fit good model with correlation between factors
fit.g.c <- cfa(m.ei.good, data=ddf, orthogonal=F)
summary(fit.g.c, fit.measures=TRUE)
## lavaan 0.6-11 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        25
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                61.027
##   Degrees of freedom                                53
##   P-value (Chi-square)                           0.210
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.976
##   Tucker-Lewis Index (TLI)                       0.970
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1436.232
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                2922.463
##   Bayesian (BIC)                              2987.593
##   Sample-size adjusted Bayesian (BIC)         2908.636
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.039
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.077
##   P-value RMSEA <= 0.05                          0.642
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.055
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA =~                                               
##     i1                1.000                           
##     i3                0.927    0.234    3.963    0.000
##     i5                0.799    0.233    3.428    0.001
##     i7                0.492    0.211    2.328    0.020
##     i9                0.996    0.248    4.017    0.000
##     i11               0.715    0.193    3.704    0.000
##   EC =~                                               
##     i2                1.000                           
##     i4               -0.904    0.130   -6.949    0.000
##     i6               -0.932    0.130   -7.151    0.000
##     i8                0.995    0.140    7.090    0.000
##     i10              -1.029    0.133   -7.713    0.000
##     i12              -0.861    0.125   -6.897    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   EA ~~                                               
##     EC                0.151    0.060    2.513    0.012
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.560    0.101    5.549    0.000
##    .i3                0.484    0.087    5.559    0.000
##    .i5                0.670    0.107    6.268    0.000
##    .i7                0.770    0.113    6.808    0.000
##    .i9                0.516    0.095    5.431    0.000
##    .i11               0.398    0.067    5.984    0.000
##    .i2                0.381    0.068    5.602    0.000
##    .i4                0.462    0.076    6.086    0.000
##    .i6                0.441    0.074    5.973    0.000
##    .i8                0.520    0.087    6.009    0.000
##    .i10               0.391    0.070    5.555    0.000
##    .i12               0.430    0.070    6.113    0.000
##     EA                0.297    0.111    2.674    0.007
##     EC                0.553    0.127    4.336    0.000
# compare good model with bad model
m.ei.bad <- '
  # item 1 to 6, diesregarding the content
  f1 =~ i1 + i2 + i3 + i4 + i5 + i6
  # item 7 to 12, diesregarding the content
  f2 =~ i7 + i8 + i9 + i10 + i11 + i12
'

# fit orthogonal bad model
fit.b.o <- cfa(m.ei.bad, data=ddf, orthogonal=T)
summary(fit.b.o, fit.measures=TRUE)
## lavaan 0.6-11 ended normally after 65 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        24
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                               209.926
##   Degrees of freedom                                54
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.530
##   Tucker-Lewis Index (TLI)                       0.426
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1510.682
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                3069.363
##   Bayesian (BIC)                              3131.887
##   Sample-size adjusted Bayesian (BIC)         3056.089
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.170
##   90 Percent confidence interval - lower         0.146
##   90 Percent confidence interval - upper         0.194
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.230
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   f1 =~                                               
##     i1                1.000                           
##     i2                2.799    1.329    2.105    0.035
##     i3                0.634    0.516    1.229    0.219
##     i4               -3.216    1.505   -2.138    0.033
##     i5                0.605    0.538    1.125    0.261
##     i6               -3.628    1.694   -2.142    0.032
##   f2 =~                                               
##     i7                1.000                           
##     i8                4.523    2.533    1.786    0.074
##     i9                1.368    0.918    1.491    0.136
##     i10              -3.841    2.158   -1.780    0.075
##     i11               1.016    0.709    1.433    0.152
##     i12              -3.221    1.823   -1.767    0.077
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   f1 ~~                                               
##     f2                0.000                           
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.808    0.116    6.971    0.000
##    .i2                0.553    0.095    5.797    0.000
##    .i3                0.720    0.102    7.026    0.000
##    .i4                0.410    0.091    4.514    0.000
##    .i5                0.842    0.120    7.036    0.000
##    .i6                0.282    0.097    2.918    0.004
##    .i7                0.808    0.116    6.993    0.000
##    .i8                0.372    0.112    3.320    0.001
##    .i9                0.746    0.108    6.913    0.000
##    .i10               0.475    0.099    4.787    0.000
##    .i11               0.515    0.074    6.945    0.000
##    .i12               0.487    0.087    5.601    0.000
##     f1                0.049    0.045    1.088    0.277
##     f2                0.034    0.038    0.904    0.366
# fit bad model with correlation between factors
fit.b.c <- cfa(m.ei.bad, data=ddf, orthogonal=F)
## Warning in lav_object_post_check(object): lavaan WARNING: covariance matrix of latent variables
##                 is not positive definite;
##                 use lavInspect(fit, "cov.lv") to investigate.
summary(fit.b.c, fit.measures=TRUE)
## lavaan 0.6-11 ended normally after 72 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        25
##                                                       
##   Number of observations                           100
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                               118.091
##   Degrees of freedom                                53
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               397.852
##   Degrees of freedom                                66
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.804
##   Tucker-Lewis Index (TLI)                       0.756
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1464.764
##   Loglikelihood unrestricted model (H1)      -1405.718
##                                                       
##   Akaike (AIC)                                2979.527
##   Bayesian (BIC)                              3044.657
##   Sample-size adjusted Bayesian (BIC)         2965.700
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.111
##   90 Percent confidence interval - lower         0.084
##   90 Percent confidence interval - upper         0.138
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.109
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   f1 =~                                               
##     i1                1.000                           
##     i2                3.523    1.631    2.159    0.031
##     i3                1.045    0.633    1.651    0.099
##     i4               -3.094    1.449   -2.135    0.033
##     i5                1.099    0.674    1.631    0.103
##     i6               -3.178    1.486   -2.140    0.032
##   f2 =~                                               
##     i7                1.000                           
##     i8                4.075    2.172    1.876    0.061
##     i9                1.381    0.879    1.570    0.116
##     i10              -4.151    2.202   -1.885    0.059
##     i11               0.927    0.641    1.446    0.148
##     i12              -3.444    1.842   -1.869    0.062
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   f1 ~~                                               
##     f2                0.039    0.028    1.416    0.157
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .i1                0.812    0.116    7.023    0.000
##    .i2                0.383    0.069    5.555    0.000
##    .i3                0.691    0.099    7.009    0.000
##    .i4                0.489    0.079    6.222    0.000
##    .i5                0.806    0.115    7.012    0.000
##    .i6                0.474    0.077    6.137    0.000
##    .i7                0.809    0.115    7.034    0.000
##    .i8                0.514    0.086    5.999    0.000
##    .i9                0.746    0.107    6.995    0.000
##    .i10               0.402    0.072    5.587    0.000
##    .i11               0.521    0.074    7.022    0.000
##    .i12               0.445    0.072    6.206    0.000
##     f1                0.044    0.041    1.088    0.277
##     f2                0.033    0.035    0.948    0.343
anova(fit.g.o, fit.g.c, test="Chisq")
## Chi-Squared Difference Test
## 
##         Df    AIC    BIC  Chisq Chisq diff Df diff Pr(>Chisq)   
## fit.g.c 53 2922.5 2987.6 61.027                                 
## fit.g.o 54 2929.3 2991.8 69.883     8.8564       1   0.002921 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(fit.b.o, fit.b.c, test="Chisq")
## Chi-Squared Difference Test
## 
##         Df    AIC    BIC  Chisq Chisq diff Df diff Pr(>Chisq)    
## fit.b.c 53 2979.5 3044.7 118.09                                  
## fit.b.o 54 3069.4 3131.9 209.93     91.836       1  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(fit.g.o, fit.b.o, test="Chisq")
## Warning in lavTestLRT(object = object, ..., model.names = NAMES): lavaan
## WARNING: some models have the same degrees of freedom
## Chi-Squared Difference Test
## 
##         Df    AIC    BIC   Chisq Chisq diff Df diff Pr(>Chisq)
## fit.g.o 54 2929.3 2991.8  69.883                              
## fit.b.o 54 3069.4 3131.9 209.926     140.04       0
anova(fit.g.c, fit.b.c, test="Chisq")
## Warning in lavTestLRT(object = object, ..., model.names = NAMES): lavaan
## WARNING: some models have the same degrees of freedom
## Chi-Squared Difference Test
## 
##         Df    AIC    BIC   Chisq Chisq diff Df diff Pr(>Chisq)
## fit.g.c 53 2922.5 2987.6  61.027                              
## fit.b.c 53 2979.5 3044.7 118.091     57.064       0

Die Indices im Vergleich (good - bad):

 lavaan (0.5-18) converged normally after  30 iterations
 
   Number of observations                           100        100
 
   Estimator                                         ML
   Minimum Function Test Statistic               61.027    118.091
   Degrees of freedom                                53         53
   P-value (Chi-square)                           0.210      0.000
 
 Model test baseline model:
 
   Minimum Function Test Statistic              397.852     397.852
   Degrees of freedom                                66          66
   P-value                                        0.000       0.000
 
 User model versus baseline model:
 
   Comparative Fit Index (CFI)                    0.976       0.804
   Tucker-Lewis Index (TLI)                       0.970       0.756
 
 Loglikelihood and Information Criteria:
 
   Loglikelihood user model (H0)              -1436.232    -1464.764
   Loglikelihood unrestricted model (H1)      -1405.718    -1405.718
 
   Number of free parameters                         25           25
   Akaike (AIC)                                2922.463     2979.527
   Bayesian (BIC)                              2987.593     3044.657
   Sample-size adjusted Bayesian (BIC)         2908.636     2965.700
 
 Root Mean Square Error of Approximation:
 
   RMSEA                                          0.039        0.111
   90 Percent Confidence Interval          0.000  0.077  0.084 0.138
   P-value RMSEA <= 0.05                          0.642        0.000
 
 Standardized Root Mean Square Residual:
 
   SRMR                                           0.055        0.109
 

Beispiel Emotionale Intelligenz mit library(sem)

Spezifikation des Modells Die Zeilen der Modellspezifikation müssen unmittelbar aufeinander folgen. Es darf keine Leerzeile dazwischen sein. Eine Leerzeile signalisiert das Ende der Spezifikation des Pfadmodells.

EA und EC sind latente Variablen EA -> i1, ea1 drückt aus, dass die Ausprägung von i1 von der latenten Variable EA beeinflusst wird. Dabei ist EA -> i1 der eigentliche path, ea1 ist der Name des Pfades. EA <-> EA, NA, 1 EC <-> EC, NA, 1 oder EA <-> EA, var_ea EC <-> EC, var_ec definiert die Varianz der latenten Variablen

i1 <-> i1, error1 i2 <-> i2, error2 definiert bzw. deklariert die Varianz des Errors (disturbance parameter, error term)

EA <-> EC, cov1 deklariert einen Covarianz-Term. Notwendig, wenn eine oblique Struktur der Faktoren vermutet wird, also wenn Korrelationen zwischen den Faktoren zugelassen werden sollen.

Einschränkungen (constraints) definieren:

  • eine der beobachteten Variablen kann auf 1 gesetzt werden statt EA -> NA, 1 statt EA -> i1, ea1

  • die Varianzen der latenten Variablen können auf 1 gesetzt werden EA <-> EA, NA, 1 statt EA <-> EA, var_ea

Die standardisierten Koeffizienten des Modells bekommt man über den Befehl stdCoef(model) Die oben auf 1 gesetzten Varianzen der latenten Variablen sind dann 1.

Sollen unterschiedliche Varianzen der latenten Variablen geschätzt werden, kann man den Varianzen der latenten Variablen in der Modellspezifikation einen Namen geben an Stelle von NA, 1 und dafür den jeweils ersten Pfad der beobachteten Variablen in ihre latente Variable auf 1 setzen.

# get data
ddf <- read.delim("https://md.psych.bio.uni-goettingen.de/mv/data/virt/v_ei.txt")
head(ddf)
##   i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12
## 1  4  3  4  2  3  1  4  3  3   1   3   3
## 2  4  3  3  1  4  1  4  4  4   1   3   2
## 3  4  3  4  2  4  2  4  2  4   1   3   3
## 4  3  3  2  2  1  2  4  3  1   2   2   3
## 5  4  4  4  4  4  1  4  4  4   2   3   1
## 6  2  4  3  2  4  2  2  3  3   2   3   2
cov.ei <- cov(ddf)  ## covariance matrix to be used as the S argument in sem function

# we use library(sem)
require(sem)
## Lade nötiges Paket: sem
## 
## Attache Paket: 'sem'
## Die folgenden Objekte sind maskiert von 'package:lavaan':
## 
##     cfa, sem
# EA and EC are names for latent variables in the path model
# EA -> i1, ea1 draw a path from latent variable EA to i1, which is influenced by EA
cfa.ei.good <- specifyModel(file="sem_ei_good.txt")
## NOTE: it is generally simpler to use specifyEquations() or cfa()
##       see ?specifyEquations
# content of sem_ei_good.txt
# EA -> i1, ea1
# EA -> i3, ea2
# EA -> i5, ea3
# EA -> i7, ea4
# EA -> i9, ea5
# EA -> i11, ea6
# EC -> i2, ec1
# EC -> i4, ec2
# EC -> i6, ec3
# EC -> i8, ec4
# EC -> i10, ec5
# EC -> i12, ec6
# EA <-> EA, NA, 1
# EC <-> EC, NA, 1
# i1 <-> i1, error1
# i2 <-> i2, error2
# i3 <-> i3, error3
# i4 <-> i4, error4
# i5 <-> i5, error5
# i6 <-> i6, error6
# i7 <-> i7, error7
# i8 <-> i8, error8
# i9 <-> i9, error9
# i10 <-> i10, error10
# i11 <-> i11, error11
# i12 <-> i12, error12
# EA <-> EC, cov1
# 

# compare it to a 'bad' model: first 6 items vs last 6 items
cfa.ei.bad <- specifyModel(file="sem_ei_bad.txt")       
## NOTE: it is generally simpler to use specifyEquations() or cfa()
##       see ?specifyEquations
# content of sem_ei_bad.txt
# EA -> i1, ea1
# EA -> i2, ea2
# EA -> i3, ea3
# EA -> i4, ea4
# EA -> i5, ea5
# EA -> i6, ea6
# EC -> i7, ec1
# EC -> i8, ec2
# EC -> i9, ec3
# EC -> i10, ec4
# EC -> i11, ec5
# EC -> i12, ec6
# EA <-> EA, NA, 1
# EC <-> EC, NA, 1
# i1 <-> i1, error1
# i2 <-> i2, error2
# i3 <-> i3, error3
# i4 <-> i4, error4
# i5 <-> i5, error5
# i6 <-> i6, error6
# i7 <-> i7, error7
# i8 <-> i8, error8
# i9 <-> i9, error9
# i10 <-> i10, error10
# i11 <-> i11, error11
# i12 <-> i12, error12
# EA <-> EC, cov1
# 
# 
## nrow() function used to specify the number of observations.
cfa.ei.output.good <- sem(cfa.ei.good, cov.ei, nrow(ddf))

summary(cfa.ei.output.good)
## 
##  Model Chisquare =  60.41636   Df =  53 Pr(>Chisq) = 0.2256253
##  AIC =  110.4164
##  BIC =  -183.6577
## 
##  Normalized Residuals
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -0.97374 -0.17898  0.07269  0.16674  0.45324  1.85548 
## 
##  R-square for Endogenous Variables
##     i1     i3     i5     i7     i9    i11     i2     i4     i6     i8    i10 
## 0.3464 0.3450 0.2204 0.0854 0.3634 0.2757 0.5921 0.4945 0.5212 0.5130 0.5996 
##    i12 
## 0.4878 
## 
##  Parameter Estimates
##         Estimate   Std Error  z value   Pr(>|z|)                 
## ea1      0.5474174 0.10288177  5.320840 1.032895e-07 i1 <--- EA  
## ea2      0.5077084 0.09562707  5.309254 1.100749e-07 i3 <--- EA  
## ea3      0.4375633 0.10539800  4.151533 3.302549e-05 i5 <--- EA  
## ea4      0.2694231 0.10740247  2.508537 1.212322e-02 i7 <--- EA  
## ea5      0.5452292 0.09982697  5.461742 4.714849e-08 i9 <--- EA  
## ea6      0.3913831 0.08339001  4.693406 2.686940e-06 i11 <--- EA 
## ec1     -0.7472475 0.08659951 -8.628772 6.201404e-18 i2 <--- EC  
## ec2      0.6753677 0.08862688  7.620349 2.529910e-14 i4 <--- EC  
## ec3      0.6966804 0.08823181  7.896023 2.879428e-15 i6 <--- EC  
## ec4     -0.7437778 0.09521467 -7.811587 5.647213e-15 i8 <--- EC  
## ec5      0.7690216 0.08832599  8.706628 3.130479e-18 i10 <--- EC 
## ec6      0.6434796 0.08522406  7.550446 4.337709e-14 i12 <--- EC 
## error1   0.5653847 0.10239907  5.521385 3.363383e-08 i1 <--> i1  
## error2   0.3846516 0.06901060  5.573805 2.492348e-08 i2 <--> i2  
## error3   0.4893029 0.08847064  5.530681 3.189897e-08 i3 <--> i3  
## error4   0.4662017 0.07698670  6.055613 1.398836e-09 i4 <--> i4  
## error5   0.6772253 0.10859775  6.236089 4.486453e-10 i5 <--> i5  
## error6   0.4458486 0.07501455  5.943495 2.790090e-09 i6 <--> i6  
## error7   0.7778152 0.11482072  6.774171 1.251213e-11 i7 <--> i7  
## error8   0.5250775 0.08781776  5.979172 2.242741e-09 i8 <--> i8  
## error9   0.5208059 0.09637789  5.403790 6.524720e-08 i9 <--> i9  
## error10  0.3948685 0.07144268  5.527067 3.256293e-08 i10 <--> i10
## error11  0.4023748 0.06758147  5.953922 2.617916e-09 i11 <--> i11
## error12  0.4348229 0.07149183  6.082135 1.185929e-09 i12 <--> i12
## cov1    -0.3722188 0.11471502 -3.244726 1.175637e-03 EC <--> EA  
## 
##  Iterations =  18
summary(cfa.ei.output.good, fit.indices=c("RMSEA", "NNFI", "CFI"))
## 
##  Model Chisquare =  60.41636   Df =  53 Pr(>Chisq) = 0.2256253
##  RMSEA index =  0.03759586   90% CI: (NA, 0.07660595)
##  Tucker-Lewis NNFI =  0.9718322
##  Bentler CFI =  0.9773804
## 
##  Normalized Residuals
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -0.97374 -0.17898  0.07269  0.16674  0.45324  1.85548 
## 
##  R-square for Endogenous Variables
##     i1     i3     i5     i7     i9    i11     i2     i4     i6     i8    i10 
## 0.3464 0.3450 0.2204 0.0854 0.3634 0.2757 0.5921 0.4945 0.5212 0.5130 0.5996 
##    i12 
## 0.4878 
## 
##  Parameter Estimates
##         Estimate   Std Error  z value   Pr(>|z|)                 
## ea1      0.5474174 0.10288177  5.320840 1.032895e-07 i1 <--- EA  
## ea2      0.5077084 0.09562707  5.309254 1.100749e-07 i3 <--- EA  
## ea3      0.4375633 0.10539800  4.151533 3.302549e-05 i5 <--- EA  
## ea4      0.2694231 0.10740247  2.508537 1.212322e-02 i7 <--- EA  
## ea5      0.5452292 0.09982697  5.461742 4.714849e-08 i9 <--- EA  
## ea6      0.3913831 0.08339001  4.693406 2.686940e-06 i11 <--- EA 
## ec1     -0.7472475 0.08659951 -8.628772 6.201404e-18 i2 <--- EC  
## ec2      0.6753677 0.08862688  7.620349 2.529910e-14 i4 <--- EC  
## ec3      0.6966804 0.08823181  7.896023 2.879428e-15 i6 <--- EC  
## ec4     -0.7437778 0.09521467 -7.811587 5.647213e-15 i8 <--- EC  
## ec5      0.7690216 0.08832599  8.706628 3.130479e-18 i10 <--- EC 
## ec6      0.6434796 0.08522406  7.550446 4.337709e-14 i12 <--- EC 
## error1   0.5653847 0.10239907  5.521385 3.363383e-08 i1 <--> i1  
## error2   0.3846516 0.06901060  5.573805 2.492348e-08 i2 <--> i2  
## error3   0.4893029 0.08847064  5.530681 3.189897e-08 i3 <--> i3  
## error4   0.4662017 0.07698670  6.055613 1.398836e-09 i4 <--> i4  
## error5   0.6772253 0.10859775  6.236089 4.486453e-10 i5 <--> i5  
## error6   0.4458486 0.07501455  5.943495 2.790090e-09 i6 <--> i6  
## error7   0.7778152 0.11482072  6.774171 1.251213e-11 i7 <--> i7  
## error8   0.5250775 0.08781776  5.979172 2.242741e-09 i8 <--> i8  
## error9   0.5208059 0.09637789  5.403790 6.524720e-08 i9 <--> i9  
## error10  0.3948685 0.07144268  5.527067 3.256293e-08 i10 <--> i10
## error11  0.4023748 0.06758147  5.953922 2.617916e-09 i11 <--> i11
## error12  0.4348229 0.07149183  6.082135 1.185929e-09 i12 <--> i12
## cov1    -0.3722188 0.11471502 -3.244726 1.175637e-03 EC <--> EA  
## 
##  Iterations =  18
# summary output may be adapted using opt
opt <- options(fit.indices = c("GFI", "AGFI", "RMSEA", "NFI", "NNFI", "CFI", "RNI", "IFI", "SRMR", "AIC", "AICc", "BIC", "CAIC"))
summary(cfa.ei.output.good)
## 
##  Model Chisquare =  60.41636   Df =  53 Pr(>Chisq) = 0.2256253
##  Goodness-of-fit index =  0.9132819
##  Adjusted goodness-of-fit index =  0.8723771
##  RMSEA index =  0.03759586   90% CI: (NA, 0.07660595)
##  Bentler-Bonett NFI =  0.8466097
##  Tucker-Lewis NNFI =  0.9718322
##  Bentler CFI =  0.9773804
##  Bentler RNI =  0.9773804
##  Bollen IFI =  0.9782431
##  SRMR =  0.05505206
##  AIC =  110.4164
##  AICc =  77.98393
##  BIC =  -183.6577
##  CAIC =  -236.6577
## 
##  Normalized Residuals
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -0.97374 -0.17898  0.07269  0.16674  0.45324  1.85548 
## 
##  R-square for Endogenous Variables
##     i1     i3     i5     i7     i9    i11     i2     i4     i6     i8    i10 
## 0.3464 0.3450 0.2204 0.0854 0.3634 0.2757 0.5921 0.4945 0.5212 0.5130 0.5996 
##    i12 
## 0.4878 
## 
##  Parameter Estimates
##         Estimate   Std Error  z value   Pr(>|z|)                 
## ea1      0.5474174 0.10288177  5.320840 1.032895e-07 i1 <--- EA  
## ea2      0.5077084 0.09562707  5.309254 1.100749e-07 i3 <--- EA  
## ea3      0.4375633 0.10539800  4.151533 3.302549e-05 i5 <--- EA  
## ea4      0.2694231 0.10740247  2.508537 1.212322e-02 i7 <--- EA  
## ea5      0.5452292 0.09982697  5.461742 4.714849e-08 i9 <--- EA  
## ea6      0.3913831 0.08339001  4.693406 2.686940e-06 i11 <--- EA 
## ec1     -0.7472475 0.08659951 -8.628772 6.201404e-18 i2 <--- EC  
## ec2      0.6753677 0.08862688  7.620349 2.529910e-14 i4 <--- EC  
## ec3      0.6966804 0.08823181  7.896023 2.879428e-15 i6 <--- EC  
## ec4     -0.7437778 0.09521467 -7.811587 5.647213e-15 i8 <--- EC  
## ec5      0.7690216 0.08832599  8.706628 3.130479e-18 i10 <--- EC 
## ec6      0.6434796 0.08522406  7.550446 4.337709e-14 i12 <--- EC 
## error1   0.5653847 0.10239907  5.521385 3.363383e-08 i1 <--> i1  
## error2   0.3846516 0.06901060  5.573805 2.492348e-08 i2 <--> i2  
## error3   0.4893029 0.08847064  5.530681 3.189897e-08 i3 <--> i3  
## error4   0.4662017 0.07698670  6.055613 1.398836e-09 i4 <--> i4  
## error5   0.6772253 0.10859775  6.236089 4.486453e-10 i5 <--> i5  
## error6   0.4458486 0.07501455  5.943495 2.790090e-09 i6 <--> i6  
## error7   0.7778152 0.11482072  6.774171 1.251213e-11 i7 <--> i7  
## error8   0.5250775 0.08781776  5.979172 2.242741e-09 i8 <--> i8  
## error9   0.5208059 0.09637789  5.403790 6.524720e-08 i9 <--> i9  
## error10  0.3948685 0.07144268  5.527067 3.256293e-08 i10 <--> i10
## error11  0.4023748 0.06758147  5.953922 2.617916e-09 i11 <--> i11
## error12  0.4348229 0.07149183  6.082135 1.185929e-09 i12 <--> i12
## cov1    -0.3722188 0.11471502 -3.244726 1.175637e-03 EC <--> EA  
## 
##  Iterations =  18
## nrow() function used to specify the number of observations.
cfa.ei.output.bad <- sem(cfa.ei.bad, cov.ei, nrow(ddf))

summary(cfa.ei.output.bad)
## 
##  Model Chisquare =  116.9098   Df =  53 Pr(>Chisq) = 1.025578e-06
##  Goodness-of-fit index =  0.8160228
##  Adjusted goodness-of-fit index =  0.7292411
##  RMSEA index =  0.1103642   90% CI: (0.08332078, 0.1374512)
##  Bentler-Bonett NFI =  0.7031793
##  Tucker-Lewis NNFI =  0.7572667
##  Bentler CFI =  0.8050778
##  Bentler RNI =  0.8050778
##  Bollen IFI =  0.8125116
##  SRMR =  0.1087502
##  AIC =  166.9098
##  AICc =  134.4774
##  BIC =  -127.1642
##  CAIC =  -180.1642
## 
##  Normalized Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -0.7036  0.0000  0.4347  0.6330  1.0964  3.6355 
## 
##  R-square for Endogenous Variables
##     i1     i2     i3     i4     i5     i6     i7     i8     i9    i10    i11 
## 0.0518 0.5895 0.0655 0.4649 0.0623 0.4861 0.0396 0.5188 0.0785 0.5886 0.0521 
##    i12 
## 0.4708 
## 
##  Parameter Estimates
##         Estimate   Std Error  z value    Pr(>|z|)                  
## ea1     -0.2116710 0.09776987  -2.164992  3.038829e-02 i1 <--- EA  
## ea2     -0.7456124 0.08696205  -8.573998  9.995324e-18 i2 <--- EA  
## ea3     -0.2211681 0.09052516  -2.443167  1.455899e-02 i3 <--- EA  
## ea4      0.6548425 0.08937066   7.327265  2.348965e-13 i4 <--- EA  
## ea5     -0.2325893 0.09769995  -2.380649  1.728216e-02 i5 <--- EA  
## ea6      0.6727726 0.08920159   7.542160  4.622503e-14 i6 <--- EA  
## ec1      0.1835568 0.09730191   1.886467  5.923209e-02 i7 <--- EC  
## ec2      0.7479376 0.09493449   7.878460  3.314410e-15 i8 <--- EC  
## ec3      0.2534597 0.09443824   2.683867  7.277600e-03 i9 <--- EC  
## ec4     -0.7619196 0.08883893  -8.576416  9.787543e-18 i10 <--- EC 
## ec5      0.1700775 0.07838330   2.169818  3.002062e-02 i11 <--- EC 
## ec6     -0.6321568 0.08554256  -7.389968  1.468640e-13 i12 <--- EC 
## error1   0.8202460 0.11738694   6.987540  2.797470e-12 i1 <--> i1  
## error2   0.3870925 0.07003767   5.526918  3.259055e-08 i2 <--> i2  
## error3   0.6981555 0.10011064   6.973839  3.084075e-12 i3 <--> i3  
## error4   0.4935045 0.07971769   6.190652  5.991586e-10 i4 <--> i4  
## error5   0.8145891 0.11675208   6.977084  3.013686e-12 i5 <--> i5  
## error6   0.4785889 0.07837148   6.106672  1.017300e-09 i6 <--> i6  
## error7   0.8167110 0.11668896   6.999042  2.577180e-12 i7 <--> i7  
## error8   0.5188724 0.08692543   5.969167  2.384683e-09 i8 <--> i8  
## error9   0.7538390 0.10831432   6.959736  3.409114e-12 i9 <--> i9  
## error10  0.4057410 0.07298967   5.558883  2.715068e-08 i10 <--> i10
## error11  0.5266294 0.07537432   6.986854  2.811182e-12 i11 <--> i11
## error12  0.4492666 0.07276221   6.174450  6.639439e-10 i12 <--> i12
## cov1    -1.0251487 0.04276360 -23.972464 5.389011e-127 EC <--> EA  
## 
##  Iterations =  20
summary(cfa.ei.output.bad, fit.indices=c("RMSEA"))
## 
##  Model Chisquare =  116.9098   Df =  53 Pr(>Chisq) = 1.025578e-06
##  RMSEA index =  0.1103642   90% CI: (0.08332078, 0.1374512)
## 
##  Normalized Residuals
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -0.7036  0.0000  0.4347  0.6330  1.0964  3.6355 
## 
##  R-square for Endogenous Variables
##     i1     i2     i3     i4     i5     i6     i7     i8     i9    i10    i11 
## 0.0518 0.5895 0.0655 0.4649 0.0623 0.4861 0.0396 0.5188 0.0785 0.5886 0.0521 
##    i12 
## 0.4708 
## 
##  Parameter Estimates
##         Estimate   Std Error  z value    Pr(>|z|)                  
## ea1     -0.2116710 0.09776987  -2.164992  3.038829e-02 i1 <--- EA  
## ea2     -0.7456124 0.08696205  -8.573998  9.995324e-18 i2 <--- EA  
## ea3     -0.2211681 0.09052516  -2.443167  1.455899e-02 i3 <--- EA  
## ea4      0.6548425 0.08937066   7.327265  2.348965e-13 i4 <--- EA  
## ea5     -0.2325893 0.09769995  -2.380649  1.728216e-02 i5 <--- EA  
## ea6      0.6727726 0.08920159   7.542160  4.622503e-14 i6 <--- EA  
## ec1      0.1835568 0.09730191   1.886467  5.923209e-02 i7 <--- EC  
## ec2      0.7479376 0.09493449   7.878460  3.314410e-15 i8 <--- EC  
## ec3      0.2534597 0.09443824   2.683867  7.277600e-03 i9 <--- EC  
## ec4     -0.7619196 0.08883893  -8.576416  9.787543e-18 i10 <--- EC 
## ec5      0.1700775 0.07838330   2.169818  3.002062e-02 i11 <--- EC 
## ec6     -0.6321568 0.08554256  -7.389968  1.468640e-13 i12 <--- EC 
## error1   0.8202460 0.11738694   6.987540  2.797470e-12 i1 <--> i1  
## error2   0.3870925 0.07003767   5.526918  3.259055e-08 i2 <--> i2  
## error3   0.6981555 0.10011064   6.973839  3.084075e-12 i3 <--> i3  
## error4   0.4935045 0.07971769   6.190652  5.991586e-10 i4 <--> i4  
## error5   0.8145891 0.11675208   6.977084  3.013686e-12 i5 <--> i5  
## error6   0.4785889 0.07837148   6.106672  1.017300e-09 i6 <--> i6  
## error7   0.8167110 0.11668896   6.999042  2.577180e-12 i7 <--> i7  
## error8   0.5188724 0.08692543   5.969167  2.384683e-09 i8 <--> i8  
## error9   0.7538390 0.10831432   6.959736  3.409114e-12 i9 <--> i9  
## error10  0.4057410 0.07298967   5.558883  2.715068e-08 i10 <--> i10
## error11  0.5266294 0.07537432   6.986854  2.811182e-12 i11 <--> i11
## error12  0.4492666 0.07276221   6.174450  6.639439e-10 i12 <--> i12
## cov1    -1.0251487 0.04276360 -23.972464 5.389011e-127 EC <--> EA  
## 
##  Iterations =  20
# get standardized coefficients of good model
stdCoef(cfa.ei.output.good)
##            Std. Estimate             
## 1      ea1     0.5885697   i1 <--- EA
## 2      ea2     0.5873994   i3 <--- EA
## 3      ea3     0.4694715   i5 <--- EA
## 4      ea4     0.2921610   i7 <--- EA
## 5      ea5     0.6028108   i9 <--- EA
## 6      ea6     0.5250956  i11 <--- EA
## 7      ec1    -0.7694876   i2 <--- EC
## 8      ec2     0.7032321   i4 <--- EC
## 9      ec3     0.7219536   i6 <--- EC
## 10     ec4    -0.7162701   i8 <--- EC
## 11     ec5     0.7743588  i10 <--- EC
## 12     ec6     0.6984082  i12 <--- EC
## 13             1.0000000   EA <--> EA
## 14             1.0000000   EC <--> EC
## 15  error1     0.6535857   i1 <--> i1
## 16  error2     0.4078889   i2 <--> i2
## 17  error3     0.6549619   i3 <--> i3
## 18  error4     0.5054646   i4 <--> i4
## 19  error5     0.7795965   i5 <--> i5
## 20  error6     0.4787830   i6 <--> i6
## 21  error7     0.9146420   i7 <--> i7
## 22  error8     0.4869571   i8 <--> i8
## 23  error9     0.6366192   i9 <--> i9
## 24 error10     0.4003685 i10 <--> i10
## 25 error11     0.7242746 i11 <--> i11
## 26 error12     0.5122259 i12 <--> i12
## 27    cov1    -0.3722188   EC <--> EA
# compare the two models
cfa.ei.output.good
## 
##  Model Chisquare =  60.41636   Df =  53 
## 
##        ea1        ea2        ea3        ea4        ea5        ea6        ec1 
##  0.5474174  0.5077084  0.4375633  0.2694231  0.5452292  0.3913831 -0.7472475 
##        ec2        ec3        ec4        ec5        ec6     error1     error2 
##  0.6753677  0.6966804 -0.7437778  0.7690216  0.6434796  0.5653847  0.3846516 
##     error3     error4     error5     error6     error7     error8     error9 
##  0.4893029  0.4662017  0.6772253  0.4458486  0.7778152  0.5250775  0.5208059 
##    error10    error11    error12       cov1 
##  0.3948685  0.4023748  0.4348229 -0.3722188 
## 
##  Iterations =  18
cfa.ei.output.bad
## 
##  Model Chisquare =  116.9098   Df =  53 
## 
##        ea1        ea2        ea3        ea4        ea5        ea6        ec1 
## -0.2116710 -0.7456124 -0.2211681  0.6548425 -0.2325893  0.6727726  0.1835568 
##        ec2        ec3        ec4        ec5        ec6     error1     error2 
##  0.7479376  0.2534597 -0.7619196  0.1700775 -0.6321568  0.8202460  0.3870925 
##     error3     error4     error5     error6     error7     error8     error9 
##  0.6981555  0.4935045  0.8145891  0.4785889  0.8167110  0.5188724  0.7538390 
##    error10    error11    error12       cov1 
##  0.4057410  0.5266294  0.4492666 -1.0251487 
## 
##  Iterations =  20
# compare AIC and BIC
AIC(cfa.ei.output.good)
## [1] 110.4164
AIC(cfa.ei.output.bad)
## [1] 166.9098
BIC(cfa.ei.output.good)
## [1] -183.6577
BIC(cfa.ei.output.bad)
## [1] -127.1642

Vergleich der beiden Modelle nach Analyse mit SEM, good ist erster Wert, bad ist zweiter.

Maß good model bad model
Model Chisquare 60.41636 Df = 53 Pr(>Chisq) = 0.2256253 116.9098 Df = 53 Pr(>Chisq) = 1.025578e-06
Goodness-of-fit index 0.9132819 0.8160228
Adjusted goodness-of-fit index 0.8723771 0.7292411
RMSEA index 0.03759586 90% CI: (NA, 0.07660595) 0.1103642 90% CI: (0.08332078, 0.1374512)
AIC 110.4164 166.9098
BIC -183.6577 -127.1642
  • \(\chi^2\) Wert als Abweichungsmaß (reproduzierte Korrelationsmatrix von originaler) ist deutlich kleiner im good model und n. s.
  • Goodness-of-fit ist höher im good model
  • ebenso die adjusted goodness of fit
  • RMSEA, als eine Art Residualanalyse ist deutlich kleiner im good model und liegt unter der Daumenregel-Grenze von 0.05
  • AIC ist kleiner für good model. Je kleiner desto besser werden die Daten durch Modell erklärt
  • BIC ist ebenfalls kleiner für good model. Kleiner ist hier “negativer”. Es zählt nicht der Absolutwert.

Weiteres Beispiel

Quelle

Basis: Quelle

Inspired by the factor cookbook site

require(sem)
#write.table(validation.data, "cfa_validation.txt", sep="\t", quote=F, row.names=F)
# read ddf data
ddf <- read.delim("https://md.psych.bio.uni-goettingen.de/mv/data/div/cfa_validation.txt")
head(ddf)
##   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
## 1  5  5  5  5  6  6  4  5  5   5   5   4   5   4   5   5   5   5
## 2  4  5  5  3  6  6  1  5  4   5   6   6   5   5   4   6   5   6
## 3  2  6  3  4  5  5  1  6  2   3   5   3   4   4   4   4   6   6
## 4  4  6  6  6  6  6  5  6  6   6   6   6   6   6   6   6   6   6
## 5  5  6  5  5  6  6  3  5  4   5   5   5   5   5   5   5   5   5
## 6  6  6  2  4  6  5  2  6  6   6   5   5   5   5   2   5   6   5
cov.validation <- cov(ddf)  ## covariance matrix to be used as the S argument in sem function
cov.validation
##               V1         V2         V3        V4         V5         V6
## V1   0.810010432 0.03811927 0.28889102 0.1670818 0.10086011 0.26370526
## V2   0.038119265 0.36573631 0.12949479 0.1371059 0.14269443 0.10476677
## V3   0.288891018 0.12949479 0.89089012 0.4654042 0.17451193 0.26856997
## V4   0.167081816 0.13710587 0.46540419 0.7766920 0.20302953 0.21428115
## V5   0.100860105 0.14269443 0.17451193 0.2030295 0.41785357 0.19834579
## V6   0.263705265 0.10476677 0.26856997 0.2142812 0.19834579 0.94204935
## V7   0.295123587 0.13890486 0.34264227 0.4296215 0.18237849 0.59048668
## V8  -0.007116093 0.19632859 0.07231057 0.1038300 0.14484469 0.05978157
## V9   0.534090183 0.05010538 0.23594878 0.1570703 0.11578953 0.25930361
## V10  0.202369547 0.08195482 0.23064231 0.1942049 0.03243491 0.19942092
## V11  0.168816930 0.10346810 0.24510336 0.1873124 0.15084307 0.48932852
## V12  0.234708650 0.03599029 0.22090226 0.1674437 0.06477401 0.25763769
## V13  0.249515659 0.07751591 0.36171255 0.3280641 0.17108429 0.39052820
## V14  0.269144791 0.13390177 0.32290136 0.1977923 0.10247812 0.26903834
## V15  0.224207490 0.08232739 0.37105342 0.3194684 0.12943625 0.21763961
## V16  0.256615784 0.11585872 0.23844500 0.2255328 0.15530859 0.69555683
## V17 -0.018277235 0.14339699 0.10044496 0.1537598 0.23825871 0.12747227
## V18  0.024355453 0.19496072 0.09674054 0.1029678 0.25311362 0.13978838
##            V7           V8         V9        V10        V11        V12
## V1  0.2951236 -0.007116093 0.53409018 0.20236955 0.16881693 0.23470865
## V2  0.1389049  0.196328586 0.05010538 0.08195482 0.10346810 0.03599029
## V3  0.3426423  0.072310575 0.23594878 0.23064231 0.24510336 0.22090226
## V4  0.4296215  0.103830023 0.15707032 0.19420493 0.18731238 0.16744374
## V5  0.1823785  0.144844691 0.11578953 0.03243491 0.15084307 0.06477401
## V6  0.5904867  0.059781567 0.25930361 0.19942092 0.48932852 0.25763769
## V7  1.7996157  0.207596176 0.34935918 0.32489728 0.52293969 0.48742841
## V8  0.2075962  0.530662536 0.03075568 0.04049307 0.08351696 0.04106257
## V9  0.3493592  0.030755679 0.80054182 0.25314556 0.23391827 0.24480531
## V10 0.3248973  0.040493070 0.25314556 0.71469630 0.30167550 0.30865853
## V11 0.5229397  0.083516957 0.23391827 0.30167550 1.01681357 0.41356901
## V12 0.4874284  0.041062571 0.24480531 0.30865853 0.41356901 0.93161738
## V13 0.4859754  0.098363884 0.22933299 0.22331864 0.40483490 0.36238317
## V14 0.3650125  0.087809499 0.23261161 0.23562411 0.25619531 0.31977177
## V15 0.3186541  0.110166379 0.14560048 0.22918396 0.25496317 0.29037598
## V16 0.7338890  0.093999489 0.22307913 0.19320432 0.60068979 0.32631837
## V17 0.3090976  0.320743118 0.01292021 0.05667327 0.14630038 0.03940197
## V18 0.2540238  0.334280726 0.04649145 0.03496838 0.17363373 0.01073002
##            V13        V14        V15        V16         V17        V18
## V1  0.24951566 0.26914479 0.22420749 0.25661578 -0.01827723 0.02435545
## V2  0.07751591 0.13390177 0.08232739 0.11585872  0.14339699 0.19496072
## V3  0.36171255 0.32290136 0.37105342 0.23844500  0.10044496 0.09674054
## V4  0.32806412 0.19779225 0.31946840 0.22553278  0.15375977 0.10296779
## V5  0.17108429 0.10247812 0.12943625 0.15530859  0.23825871 0.25311362
## V6  0.39052820 0.26903834 0.21763961 0.69555683  0.12747227 0.13978838
## V7  0.48597539 0.36501245 0.31865406 0.73388900  0.30909763 0.25402376
## V8  0.09836388 0.08780950 0.11016638 0.09399949  0.32074312 0.33428073
## V9  0.22933299 0.23261161 0.14560048 0.22307913  0.01292021 0.04649145
## V10 0.22331864 0.23562411 0.22918396 0.19320432  0.05667327 0.03496838
## V11 0.40483490 0.25619531 0.25496317 0.60068979  0.14630038 0.17363373
## V12 0.36238317 0.31977177 0.29037598 0.32631837  0.03940197 0.01073002
## V13 0.90647421 0.41902450 0.42440016 0.41716165  0.09321709 0.12878159
## V14 0.41902450 0.68725384 0.29506504 0.35716719  0.08622874 0.11906283
## V15 0.42440016 0.29506504 0.81204892 0.28296715  0.16900588 0.18931362
## V16 0.41716165 0.35716719 0.28296715 1.18351749  0.22747014 0.19639778
## V17 0.09321709 0.08622874 0.16900588 0.22747014  0.71437163 0.52819825
## V18 0.12878159 0.11906283 0.18931362 0.19639778  0.52819825 0.94709502
attach(ddf)
## copy and paste this command separately into R before copying the model

cfa.validation <- sem::specifyModel(file="sem_model.txt")
## NOTE: it is generally simpler to use specifyEquations() or cfa()
##       see ?specifyEquations
# just for documentation reasons. specifyModel read from stdin and this conflicts with KnitR
# content of sem_model.txt is (without comment #)
# ABILITY -> V12, ability0
# ABILITY -> V9, ability1
# ABILITY -> V14, ability2
# ABILITY -> V13, ability3
# ABILITY -> V3, ability4
# ABILITY -> V1, ability5
# ABILITY -> V15, ability6
# ABILITY -> V10, ability7
# VALUES -> V17, values0
# VALUES ->V18, values1
# VALUES -> V8, values2
# VALUES -> V2, values3
# VALUES -> V5, values4
# IDENTITY -> V16, identity0
# IDENTITY -> V6, identity1
# IDENTITY -> V11, identity2
# IDENTITY -> V7, identity3
# ABILITY <-> ABILITY, NA, 1
# VALUES <-> VALUES, NA, 1
# IDENTITY <-> IDENTITY, NA, 1
# V1 <-> V1, error1
# V2 <-> V2, error2
# V3 <-> V3, error3
# V4 <-> V4, error4
# V5 <-> V5, error5
# V6 <-> V6, error6
# V7 <-> V7, error7
# V8 <-> V8, error8
# V9 <-> V9, error9
# V10 <-> V10, error10
# V11 <-> V11, error11
# V12 <-> V12, error12
# V13 <-> V13, error13
# V14 <-> V14, error14
# V15 <-> V15, error15
# V16 <-> V16, error16
# V17 <-> V17, error17
# V18 <-> V18, error18
# ABILITY <-> VALUES, cov1
# ABILITY <-> IDENTITY, cov2
# VALUES <-> IDENTITY, cov3
# 
## model specified using standardised factor variances. Analysis has also been run after setting the first item score for each factor to 1, with no difference
## line numbers for the model have been omitted for ease of copying and pasting into R

## nrow() function used to specify the number of observations.
cfa.validation.output <- sem::sem(cfa.validation, cov.validation, nrow(ddf))  

# more informations are to be obtained
# See the section "ML.methods" in sem.pdf 
?summary.objectiveML

#summary(X,fit.indices=c("RMSEA",...))
summary(cfa.validation.output, fit.indices=c("RMSEA"))
## 
##  Model Chisquare =  561.2528   Df =  133 Pr(>Chisq) = 5.854301e-54
##  RMSEA index =  0.1025802   90% CI: (NA, NA)
## 
##  Normalized Residuals
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -2.51237 -0.43183  0.02767  0.66295  1.47155  9.78711 
## 
##  R-square for Endogenous Variables
##    V12     V9    V14    V13     V3     V1    V15    V10    V17    V18     V8 
## 0.3193 0.2699 0.4813 0.4904 0.3310 0.3021 0.3544 0.2525 0.6333 0.5825 0.4169 
##     V2     V5    V16     V6    V11     V7 
## 0.2248 0.3106 0.6653 0.5932 0.4485 0.3899 
## 
##  Parameter Estimates
##           Estimate  Std Error  z value   Pr(>|z|)                          
## ability0  0.5454256 0.05495730  9.924534 3.256189e-23 V12 <--- ABILITY     
## ability1  0.4648402 0.05171841  8.987906 2.519863e-19 V9 <--- ABILITY      
## ability2  0.5751229 0.04485033 12.823158 1.216427e-37 V14 <--- ABILITY     
## ability3  0.6667419 0.05135888 12.982018 1.547491e-38 V13 <--- ABILITY     
## ability4  0.5430359 0.05354916 10.140887 3.637813e-24 V3 <--- ABILITY      
## ability5  0.4946864 0.05151662  9.602464 7.805609e-22 V1 <--- ABILITY      
## ability6  0.5364778 0.05075407 10.570143 4.098707e-26 V15 <--- ABILITY     
## ability7  0.4247777 0.04912394  8.647061 5.284253e-18 V10 <--- ABILITY     
## values0   0.6726096 0.04487096 14.989865 8.552626e-51 V17 <--- VALUES      
## values1   0.7427623 0.05225037 14.215445 7.348274e-46 V18 <--- VALUES      
## values2   0.4703353 0.04077475 11.534966 8.792193e-31 V8 <--- VALUES       
## values3   0.2867428 0.03579227  8.011306 1.134969e-15 V2 <--- VALUES       
## values4   0.3602499 0.03731974  9.653065 4.770800e-22 V5 <--- VALUES       
## identity0 0.8873503 0.05543298 16.007622 1.130485e-57 V16 <--- IDENTITY    
## identity1 0.7475428 0.05048877 14.806122 1.337368e-49 V6 <--- IDENTITY     
## identity2 0.6753142 0.05482191 12.318327 7.217620e-35 V11 <--- IDENTITY    
## identity3 0.8376139 0.07429317 11.274439 1.754934e-29 V7 <--- IDENTITY     
## error1    0.5652955 0.04986735 11.335985 8.704746e-30 V1 <--> V1           
## error2    0.2835150 0.02444977 11.595816 4.327216e-31 V2 <--> V2           
## error3    0.5960018 0.05327544 11.187177 4.711963e-29 V3 <--> V3           
## error4    0.7766920 0.06279183 12.369317 3.830654e-35 V4 <--> V4           
## error5    0.2880738 0.02581887 11.157491 6.582297e-29 V5 <--> V5           
## error6    0.3832292 0.04263115  8.989418 2.485441e-19 V6 <--> V6           
## error7    1.0980209 0.10041134 10.935227 7.820970e-28 V7 <--> V7           
## error8    0.3094475 0.02970430 10.417601 2.060859e-25 V8 <--> V8           
## error9    0.5844651 0.05087751 11.487691 1.521236e-30 V9 <--> V9           
## error10   0.5342599 0.04619898 11.564324 6.248167e-31 V10 <--> V10         
## error11   0.5607651 0.05324925 10.530948 6.220486e-26 V11 <--> V11         
## error12   0.6341278 0.05637253 11.248880 2.345511e-29 V12 <--> V12         
## error13   0.4619288 0.04592463 10.058410 8.434950e-24 V13 <--> V13         
## error14   0.3564872 0.03515096 10.141605 3.611160e-24 V14 <--> V14         
## error15   0.5242402 0.04741430 11.056583 2.037115e-28 V15 <--> V15         
## error16   0.3961271 0.05073686  7.807481 5.834244e-15 V16 <--> V16         
## error17   0.2619686 0.03471455  7.546364 4.475775e-14 V17 <--> V17         
## error18   0.3954005 0.04696524  8.419004 3.796997e-17 V18 <--> V18         
## cov1      0.2758005 0.06547343  4.212403 2.526678e-05 VALUES <--> ABILITY  
## cov2      0.6920402 0.04301632 16.087854 3.104127e-58 IDENTITY <--> ABILITY
## cov3      0.3573852 0.06216556  5.748926 8.981225e-09 IDENTITY <--> VALUES 
## 
##  Iterations =  30
detach(ddf)

CFA mit library(lavaan)

Quelle

# this is included in the above mentioned documentation
# load the lavaan package (only needed once per session)
require(lavaan)
# specify the model
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
# fit the model
fit <- lavaan::cfa(HS.model, data=HolzingerSwineford1939)
# display summary output
summary(fit, fit.measures=TRUE)
## lavaan 0.6-11 ended normally after 35 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        21
##                                                       
##   Number of observations                           301
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                85.306
##   Degrees of freedom                                24
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               918.852
##   Degrees of freedom                                36
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.931
##   Tucker-Lewis Index (TLI)                       0.896
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -3737.745
##   Loglikelihood unrestricted model (H1)      -3695.092
##                                                       
##   Akaike (AIC)                                7517.490
##   Bayesian (BIC)                              7595.339
##   Sample-size adjusted Bayesian (BIC)         7528.739
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.092
##   90 Percent confidence interval - lower         0.071
##   90 Percent confidence interval - upper         0.114
##   P-value RMSEA <= 0.05                          0.001
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.065
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   visual =~                                           
##     x1                1.000                           
##     x2                0.554    0.100    5.554    0.000
##     x3                0.729    0.109    6.685    0.000
##   textual =~                                          
##     x4                1.000                           
##     x5                1.113    0.065   17.014    0.000
##     x6                0.926    0.055   16.703    0.000
##   speed =~                                            
##     x7                1.000                           
##     x8                1.180    0.165    7.152    0.000
##     x9                1.082    0.151    7.155    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   visual ~~                                           
##     textual           0.408    0.074    5.552    0.000
##     speed             0.262    0.056    4.660    0.000
##   textual ~~                                          
##     speed             0.173    0.049    3.518    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .x1                0.549    0.114    4.833    0.000
##    .x2                1.134    0.102   11.146    0.000
##    .x3                0.844    0.091    9.317    0.000
##    .x4                0.371    0.048    7.779    0.000
##    .x5                0.446    0.058    7.642    0.000
##    .x6                0.356    0.043    8.277    0.000
##    .x7                0.799    0.081    9.823    0.000
##    .x8                0.488    0.074    6.573    0.000
##    .x9                0.566    0.071    8.003    0.000
##     visual            0.809    0.145    5.564    0.000
##     textual           0.979    0.112    8.737    0.000
##     speed             0.384    0.086    4.451    0.000

source

todo: adapt

require(lavaan)
model <- '
# latent variable definitions
factor_1 =~ y1 + y2 + y3 + y4
factor_2 =~ y5 + y6 + y7 + y8
# covariance between factor_1 and factor_2
factor_1 ~~ factor_2
# residual covariances
y1 ~~ y5
'
#fit <- cfa(model, data=ex_data)
#summary(fit)

# if we have a group variable and want a multiple-group confirmatory factor analysis to test for measurement invariance.
#measurement.invariance(model, data=ex_data, group ="school" )

Weitere Beispiele, Übungen / Exercises

Beispiel BFI (Big Five Inventory)

Beispiel BFI