Basis: Quelle
require(sem)
## Loading required package: sem
#write.table(validation.data, "cfa_validation.txt", sep="\t", quote=F, row.names=F)
# read ddf data
ddf <- read.delim("http://r.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 V7 V8
## V1 0.810010 0.03812 0.28889 0.1671 0.10086 0.26371 0.2951 -0.007116
## V2 0.038119 0.36574 0.12949 0.1371 0.14269 0.10477 0.1389 0.196329
## V3 0.288891 0.12949 0.89089 0.4654 0.17451 0.26857 0.3426 0.072311
## V4 0.167082 0.13711 0.46540 0.7767 0.20303 0.21428 0.4296 0.103830
## V5 0.100860 0.14269 0.17451 0.2030 0.41785 0.19835 0.1824 0.144845
## V6 0.263705 0.10477 0.26857 0.2143 0.19835 0.94205 0.5905 0.059782
## V7 0.295124 0.13890 0.34264 0.4296 0.18238 0.59049 1.7996 0.207596
## V8 -0.007116 0.19633 0.07231 0.1038 0.14484 0.05978 0.2076 0.530663
## V9 0.534090 0.05011 0.23595 0.1571 0.11579 0.25930 0.3494 0.030756
## V10 0.202370 0.08195 0.23064 0.1942 0.03243 0.19942 0.3249 0.040493
## V11 0.168817 0.10347 0.24510 0.1873 0.15084 0.48933 0.5229 0.083517
## V12 0.234709 0.03599 0.22090 0.1674 0.06477 0.25764 0.4874 0.041063
## V13 0.249516 0.07752 0.36171 0.3281 0.17108 0.39053 0.4860 0.098364
## V14 0.269145 0.13390 0.32290 0.1978 0.10248 0.26904 0.3650 0.087809
## V15 0.224207 0.08233 0.37105 0.3195 0.12944 0.21764 0.3187 0.110166
## V16 0.256616 0.11586 0.23844 0.2255 0.15531 0.69556 0.7339 0.093999
## V17 -0.018277 0.14340 0.10044 0.1538 0.23826 0.12747 0.3091 0.320743
## V18 0.024355 0.19496 0.09674 0.1030 0.25311 0.13979 0.2540 0.334281
## V9 V10 V11 V12 V13 V14 V15 V16
## V1 0.53409 0.20237 0.16882 0.23471 0.24952 0.26914 0.22421 0.2566
## V2 0.05011 0.08195 0.10347 0.03599 0.07752 0.13390 0.08233 0.1159
## V3 0.23595 0.23064 0.24510 0.22090 0.36171 0.32290 0.37105 0.2384
## V4 0.15707 0.19420 0.18731 0.16744 0.32806 0.19779 0.31947 0.2255
## V5 0.11579 0.03243 0.15084 0.06477 0.17108 0.10248 0.12944 0.1553
## V6 0.25930 0.19942 0.48933 0.25764 0.39053 0.26904 0.21764 0.6956
## V7 0.34936 0.32490 0.52294 0.48743 0.48598 0.36501 0.31865 0.7339
## V8 0.03076 0.04049 0.08352 0.04106 0.09836 0.08781 0.11017 0.0940
## V9 0.80054 0.25315 0.23392 0.24481 0.22933 0.23261 0.14560 0.2231
## V10 0.25315 0.71470 0.30168 0.30866 0.22332 0.23562 0.22918 0.1932
## V11 0.23392 0.30168 1.01681 0.41357 0.40483 0.25620 0.25496 0.6007
## V12 0.24481 0.30866 0.41357 0.93162 0.36238 0.31977 0.29038 0.3263
## V13 0.22933 0.22332 0.40483 0.36238 0.90647 0.41902 0.42440 0.4172
## V14 0.23261 0.23562 0.25620 0.31977 0.41902 0.68725 0.29507 0.3572
## V15 0.14560 0.22918 0.25496 0.29038 0.42440 0.29507 0.81205 0.2830
## V16 0.22308 0.19320 0.60069 0.32632 0.41716 0.35717 0.28297 1.1835
## V17 0.01292 0.05667 0.14630 0.03940 0.09322 0.08623 0.16901 0.2275
## V18 0.04649 0.03497 0.17363 0.01073 0.12878 0.11906 0.18931 0.1964
## V17 V18
## V1 -0.01828 0.02436
## V2 0.14340 0.19496
## V3 0.10044 0.09674
## V4 0.15376 0.10297
## V5 0.23826 0.25311
## V6 0.12747 0.13979
## V7 0.30910 0.25402
## V8 0.32074 0.33428
## V9 0.01292 0.04649
## V10 0.05667 0.03497
## V11 0.14630 0.17363
## V12 0.03940 0.01073
## V13 0.09322 0.12878
## V14 0.08623 0.11906
## V15 0.16901 0.18931
## V16 0.22747 0.19640
## V17 0.71437 0.52820
## V18 0.52820 0.94710
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.3 Df = 133 Pr(>Chisq) = 5.854e-54
## RMSEA index = 0.1026 90% CI: (NA, NA)
##
## Normalized Residuals
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -2.510 -0.432 0.028 0.663 1.470 9.790
##
## R-square for Endogenous Variables
## V12 V9 V14 V13 V3 V1 V15 V10 V17 V18
## 0.3193 0.2699 0.4813 0.4904 0.3310 0.3021 0.3544 0.2525 0.6333 0.5825
## V8 V2 V5 V16 V6 V11 V7
## 0.4169 0.2248 0.3106 0.6653 0.5932 0.4485 0.3899
##
## Parameter Estimates
## Estimate Std Error z value Pr(>|z|)
## ability0 0.5454 0.05496 9.925 3.256e-23 V12 <--- ABILITY
## ability1 0.4648 0.05172 8.988 2.520e-19 V9 <--- ABILITY
## ability2 0.5751 0.04485 12.823 1.216e-37 V14 <--- ABILITY
## ability3 0.6667 0.05136 12.982 1.547e-38 V13 <--- ABILITY
## ability4 0.5430 0.05355 10.141 3.638e-24 V3 <--- ABILITY
## ability5 0.4947 0.05152 9.602 7.806e-22 V1 <--- ABILITY
## ability6 0.5365 0.05075 10.570 4.099e-26 V15 <--- ABILITY
## ability7 0.4248 0.04912 8.647 5.284e-18 V10 <--- ABILITY
## values0 0.6726 0.04487 14.990 8.553e-51 V17 <--- VALUES
## values1 0.7428 0.05225 14.215 7.348e-46 V18 <--- VALUES
## values2 0.4703 0.04077 11.535 8.792e-31 V8 <--- VALUES
## values3 0.2867 0.03579 8.011 1.135e-15 V2 <--- VALUES
## values4 0.3602 0.03732 9.653 4.771e-22 V5 <--- VALUES
## identity0 0.8874 0.05543 16.008 1.130e-57 V16 <--- IDENTITY
## identity1 0.7475 0.05049 14.806 1.337e-49 V6 <--- IDENTITY
## identity2 0.6753 0.05482 12.318 7.218e-35 V11 <--- IDENTITY
## identity3 0.8376 0.07429 11.274 1.755e-29 V7 <--- IDENTITY
## error1 0.5653 0.04987 11.336 8.705e-30 V1 <--> V1
## error2 0.2835 0.02445 11.596 4.327e-31 V2 <--> V2
## error3 0.5960 0.05328 11.187 4.712e-29 V3 <--> V3
## error4 0.7767 0.06279 12.369 3.831e-35 V4 <--> V4
## error5 0.2881 0.02582 11.157 6.582e-29 V5 <--> V5
## error6 0.3832 0.04263 8.989 2.485e-19 V6 <--> V6
## error7 1.0980 0.10041 10.935 7.821e-28 V7 <--> V7
## error8 0.3094 0.02970 10.418 2.061e-25 V8 <--> V8
## error9 0.5845 0.05088 11.488 1.521e-30 V9 <--> V9
## error10 0.5343 0.04620 11.564 6.248e-31 V10 <--> V10
## error11 0.5608 0.05325 10.531 6.220e-26 V11 <--> V11
## error12 0.6341 0.05637 11.249 2.346e-29 V12 <--> V12
## error13 0.4619 0.04592 10.058 8.435e-24 V13 <--> V13
## error14 0.3565 0.03515 10.142 3.611e-24 V14 <--> V14
## error15 0.5242 0.04741 11.057 2.037e-28 V15 <--> V15
## error16 0.3961 0.05074 7.807 5.834e-15 V16 <--> V16
## error17 0.2620 0.03471 7.546 4.476e-14 V17 <--> V17
## error18 0.3954 0.04697 8.419 3.797e-17 V18 <--> V18
## cov1 0.2758 0.06547 4.212 2.527e-05 VALUES <--> ABILITY
## cov2 0.6920 0.04302 16.088 3.104e-58 IDENTITY <--> ABILITY
## cov3 0.3574 0.06217 5.749 8.981e-09 IDENTITY <--> VALUES
##
## Iterations = 30
detach(ddf)
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:
Die Items sind skaliert von 1 bis 4 (fast nie/manchmal/oft/fast immer)
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
Chisquare-Wert 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:
Badness of fit indices: RSMA Daumenregeln: – 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
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("http://r.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
# 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.42 Df = 53 Pr(>Chisq) = 0.2256
## AIC = 110.4
## BIC = -183.7
##
## Normalized Residuals
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.9740 -0.1790 0.0727 0.1670 0.4530 1.8600
##
## R-square for Endogenous Variables
## i1 i3 i5 i7 i9 i11 i2 i4 i6 i8
## 0.3464 0.3450 0.2204 0.0854 0.3634 0.2757 0.5921 0.4945 0.5212 0.5130
## i10 i12
## 0.5996 0.4878
##
## Parameter Estimates
## Estimate Std Error z value Pr(>|z|)
## ea1 0.5474 0.10288 5.321 1.033e-07 i1 <--- EA
## ea2 0.5077 0.09563 5.309 1.101e-07 i3 <--- EA
## ea3 0.4376 0.10540 4.152 3.303e-05 i5 <--- EA
## ea4 0.2694 0.10740 2.509 1.212e-02 i7 <--- EA
## ea5 0.5452 0.09983 5.462 4.715e-08 i9 <--- EA
## ea6 0.3914 0.08339 4.693 2.687e-06 i11 <--- EA
## ec1 -0.7472 0.08660 -8.629 6.201e-18 i2 <--- EC
## ec2 0.6754 0.08863 7.620 2.530e-14 i4 <--- EC
## ec3 0.6967 0.08823 7.896 2.879e-15 i6 <--- EC
## ec4 -0.7438 0.09521 -7.812 5.647e-15 i8 <--- EC
## ec5 0.7690 0.08833 8.707 3.130e-18 i10 <--- EC
## ec6 0.6435 0.08522 7.550 4.338e-14 i12 <--- EC
## error1 0.5654 0.10240 5.521 3.363e-08 i1 <--> i1
## error2 0.3847 0.06901 5.574 2.492e-08 i2 <--> i2
## error3 0.4893 0.08847 5.531 3.190e-08 i3 <--> i3
## error4 0.4662 0.07699 6.056 1.399e-09 i4 <--> i4
## error5 0.6772 0.10860 6.236 4.486e-10 i5 <--> i5
## error6 0.4458 0.07501 5.943 2.790e-09 i6 <--> i6
## error7 0.7778 0.11482 6.774 1.251e-11 i7 <--> i7
## error8 0.5251 0.08782 5.979 2.243e-09 i8 <--> i8
## error9 0.5208 0.09638 5.404 6.525e-08 i9 <--> i9
## error10 0.3949 0.07144 5.527 3.256e-08 i10 <--> i10
## error11 0.4024 0.06758 5.954 2.618e-09 i11 <--> i11
## error12 0.4348 0.07149 6.082 1.186e-09 i12 <--> i12
## cov1 -0.3722 0.11472 -3.245 1.176e-03 EC <--> EA
##
## Iterations = 18
summary(cfa.ei.output.good, fit.indices=c("RMSEA", "NNFI", "CFI"))
##
## Model Chisquare = 60.42 Df = 53 Pr(>Chisq) = 0.2256
## RMSEA index = 0.0376 90% CI: (NA, 0.07661)
## Tucker-Lewis NNFI = 0.9718
## Bentler CFI = 0.9774
##
## Normalized Residuals
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.9740 -0.1790 0.0727 0.1670 0.4530 1.8600
##
## R-square for Endogenous Variables
## i1 i3 i5 i7 i9 i11 i2 i4 i6 i8
## 0.3464 0.3450 0.2204 0.0854 0.3634 0.2757 0.5921 0.4945 0.5212 0.5130
## i10 i12
## 0.5996 0.4878
##
## Parameter Estimates
## Estimate Std Error z value Pr(>|z|)
## ea1 0.5474 0.10288 5.321 1.033e-07 i1 <--- EA
## ea2 0.5077 0.09563 5.309 1.101e-07 i3 <--- EA
## ea3 0.4376 0.10540 4.152 3.303e-05 i5 <--- EA
## ea4 0.2694 0.10740 2.509 1.212e-02 i7 <--- EA
## ea5 0.5452 0.09983 5.462 4.715e-08 i9 <--- EA
## ea6 0.3914 0.08339 4.693 2.687e-06 i11 <--- EA
## ec1 -0.7472 0.08660 -8.629 6.201e-18 i2 <--- EC
## ec2 0.6754 0.08863 7.620 2.530e-14 i4 <--- EC
## ec3 0.6967 0.08823 7.896 2.879e-15 i6 <--- EC
## ec4 -0.7438 0.09521 -7.812 5.647e-15 i8 <--- EC
## ec5 0.7690 0.08833 8.707 3.130e-18 i10 <--- EC
## ec6 0.6435 0.08522 7.550 4.338e-14 i12 <--- EC
## error1 0.5654 0.10240 5.521 3.363e-08 i1 <--> i1
## error2 0.3847 0.06901 5.574 2.492e-08 i2 <--> i2
## error3 0.4893 0.08847 5.531 3.190e-08 i3 <--> i3
## error4 0.4662 0.07699 6.056 1.399e-09 i4 <--> i4
## error5 0.6772 0.10860 6.236 4.486e-10 i5 <--> i5
## error6 0.4458 0.07501 5.943 2.790e-09 i6 <--> i6
## error7 0.7778 0.11482 6.774 1.251e-11 i7 <--> i7
## error8 0.5251 0.08782 5.979 2.243e-09 i8 <--> i8
## error9 0.5208 0.09638 5.404 6.525e-08 i9 <--> i9
## error10 0.3949 0.07144 5.527 3.256e-08 i10 <--> i10
## error11 0.4024 0.06758 5.954 2.618e-09 i11 <--> i11
## error12 0.4348 0.07149 6.082 1.186e-09 i12 <--> i12
## cov1 -0.3722 0.11472 -3.245 1.176e-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.42 Df = 53 Pr(>Chisq) = 0.2256
## Goodness-of-fit index = 0.9133
## Adjusted goodness-of-fit index = 0.8724
## RMSEA index = 0.0376 90% CI: (NA, 0.07661)
## Bentler-Bonett NFI = 0.8466
## Tucker-Lewis NNFI = 0.9718
## Bentler CFI = 0.9774
## Bentler RNI = 0.9774
## Bollen IFI = 0.9782
## SRMR = 0.05505
## AIC = 110.4
## AICc = 77.98
## BIC = -183.7
## CAIC = -236.7
##
## Normalized Residuals
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.9740 -0.1790 0.0727 0.1670 0.4530 1.8600
##
## R-square for Endogenous Variables
## i1 i3 i5 i7 i9 i11 i2 i4 i6 i8
## 0.3464 0.3450 0.2204 0.0854 0.3634 0.2757 0.5921 0.4945 0.5212 0.5130
## i10 i12
## 0.5996 0.4878
##
## Parameter Estimates
## Estimate Std Error z value Pr(>|z|)
## ea1 0.5474 0.10288 5.321 1.033e-07 i1 <--- EA
## ea2 0.5077 0.09563 5.309 1.101e-07 i3 <--- EA
## ea3 0.4376 0.10540 4.152 3.303e-05 i5 <--- EA
## ea4 0.2694 0.10740 2.509 1.212e-02 i7 <--- EA
## ea5 0.5452 0.09983 5.462 4.715e-08 i9 <--- EA
## ea6 0.3914 0.08339 4.693 2.687e-06 i11 <--- EA
## ec1 -0.7472 0.08660 -8.629 6.201e-18 i2 <--- EC
## ec2 0.6754 0.08863 7.620 2.530e-14 i4 <--- EC
## ec3 0.6967 0.08823 7.896 2.879e-15 i6 <--- EC
## ec4 -0.7438 0.09521 -7.812 5.647e-15 i8 <--- EC
## ec5 0.7690 0.08833 8.707 3.130e-18 i10 <--- EC
## ec6 0.6435 0.08522 7.550 4.338e-14 i12 <--- EC
## error1 0.5654 0.10240 5.521 3.363e-08 i1 <--> i1
## error2 0.3847 0.06901 5.574 2.492e-08 i2 <--> i2
## error3 0.4893 0.08847 5.531 3.190e-08 i3 <--> i3
## error4 0.4662 0.07699 6.056 1.399e-09 i4 <--> i4
## error5 0.6772 0.10860 6.236 4.486e-10 i5 <--> i5
## error6 0.4458 0.07501 5.943 2.790e-09 i6 <--> i6
## error7 0.7778 0.11482 6.774 1.251e-11 i7 <--> i7
## error8 0.5251 0.08782 5.979 2.243e-09 i8 <--> i8
## error9 0.5208 0.09638 5.404 6.525e-08 i9 <--> i9
## error10 0.3949 0.07144 5.527 3.256e-08 i10 <--> i10
## error11 0.4024 0.06758 5.954 2.618e-09 i11 <--> i11
## error12 0.4348 0.07149 6.082 1.186e-09 i12 <--> i12
## cov1 -0.3722 0.11472 -3.245 1.176e-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.9 Df = 53 Pr(>Chisq) = 1.026e-06
## Goodness-of-fit index = 0.816
## Adjusted goodness-of-fit index = 0.7292
## RMSEA index = 0.1104 90% CI: (0.08332, 0.1375)
## Bentler-Bonett NFI = 0.7032
## Tucker-Lewis NNFI = 0.7573
## Bentler CFI = 0.8051
## Bentler RNI = 0.8051
## Bollen IFI = 0.8125
## SRMR = 0.1088
## AIC = 166.9
## AICc = 134.5
## BIC = -127.2
## CAIC = -180.2
##
## Normalized Residuals
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.704 0.000 0.435 0.633 1.100 3.640
##
## R-square for Endogenous Variables
## i1 i2 i3 i4 i5 i6 i7 i8 i9 i10
## 0.0518 0.5895 0.0655 0.4649 0.0623 0.4861 0.0396 0.5188 0.0785 0.5886
## i11 i12
## 0.0521 0.4708
##
## Parameter Estimates
## Estimate Std Error z value Pr(>|z|)
## ea1 -0.2117 0.09777 -2.165 3.039e-02 i1 <--- EA
## ea2 -0.7456 0.08696 -8.574 9.995e-18 i2 <--- EA
## ea3 -0.2212 0.09053 -2.443 1.456e-02 i3 <--- EA
## ea4 0.6548 0.08937 7.327 2.349e-13 i4 <--- EA
## ea5 -0.2326 0.09770 -2.381 1.728e-02 i5 <--- EA
## ea6 0.6728 0.08920 7.542 4.623e-14 i6 <--- EA
## ec1 0.1836 0.09730 1.886 5.923e-02 i7 <--- EC
## ec2 0.7479 0.09493 7.878 3.314e-15 i8 <--- EC
## ec3 0.2535 0.09444 2.684 7.278e-03 i9 <--- EC
## ec4 -0.7619 0.08884 -8.576 9.788e-18 i10 <--- EC
## ec5 0.1701 0.07838 2.170 3.002e-02 i11 <--- EC
## ec6 -0.6322 0.08554 -7.390 1.469e-13 i12 <--- EC
## error1 0.8202 0.11739 6.988 2.797e-12 i1 <--> i1
## error2 0.3871 0.07004 5.527 3.259e-08 i2 <--> i2
## error3 0.6982 0.10011 6.974 3.084e-12 i3 <--> i3
## error4 0.4935 0.07972 6.191 5.992e-10 i4 <--> i4
## error5 0.8146 0.11675 6.977 3.014e-12 i5 <--> i5
## error6 0.4786 0.07837 6.107 1.017e-09 i6 <--> i6
## error7 0.8167 0.11669 6.999 2.577e-12 i7 <--> i7
## error8 0.5189 0.08693 5.969 2.385e-09 i8 <--> i8
## error9 0.7538 0.10831 6.960 3.409e-12 i9 <--> i9
## error10 0.4057 0.07299 5.559 2.715e-08 i10 <--> i10
## error11 0.5266 0.07537 6.987 2.811e-12 i11 <--> i11
## error12 0.4493 0.07276 6.174 6.639e-10 i12 <--> i12
## cov1 -1.0251 0.04276 -23.972 5.389e-127 EC <--> EA
##
## Iterations = 20
summary(cfa.ei.output.bad, fit.indices=c("RMSEA"))
##
## Model Chisquare = 116.9 Df = 53 Pr(>Chisq) = 1.026e-06
## RMSEA index = 0.1104 90% CI: (0.08332, 0.1375)
##
## Normalized Residuals
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.704 0.000 0.435 0.633 1.100 3.640
##
## R-square for Endogenous Variables
## i1 i2 i3 i4 i5 i6 i7 i8 i9 i10
## 0.0518 0.5895 0.0655 0.4649 0.0623 0.4861 0.0396 0.5188 0.0785 0.5886
## i11 i12
## 0.0521 0.4708
##
## Parameter Estimates
## Estimate Std Error z value Pr(>|z|)
## ea1 -0.2117 0.09777 -2.165 3.039e-02 i1 <--- EA
## ea2 -0.7456 0.08696 -8.574 9.995e-18 i2 <--- EA
## ea3 -0.2212 0.09053 -2.443 1.456e-02 i3 <--- EA
## ea4 0.6548 0.08937 7.327 2.349e-13 i4 <--- EA
## ea5 -0.2326 0.09770 -2.381 1.728e-02 i5 <--- EA
## ea6 0.6728 0.08920 7.542 4.623e-14 i6 <--- EA
## ec1 0.1836 0.09730 1.886 5.923e-02 i7 <--- EC
## ec2 0.7479 0.09493 7.878 3.314e-15 i8 <--- EC
## ec3 0.2535 0.09444 2.684 7.278e-03 i9 <--- EC
## ec4 -0.7619 0.08884 -8.576 9.788e-18 i10 <--- EC
## ec5 0.1701 0.07838 2.170 3.002e-02 i11 <--- EC
## ec6 -0.6322 0.08554 -7.390 1.469e-13 i12 <--- EC
## error1 0.8202 0.11739 6.988 2.797e-12 i1 <--> i1
## error2 0.3871 0.07004 5.527 3.259e-08 i2 <--> i2
## error3 0.6982 0.10011 6.974 3.084e-12 i3 <--> i3
## error4 0.4935 0.07972 6.191 5.992e-10 i4 <--> i4
## error5 0.8146 0.11675 6.977 3.014e-12 i5 <--> i5
## error6 0.4786 0.07837 6.107 1.017e-09 i6 <--> i6
## error7 0.8167 0.11669 6.999 2.577e-12 i7 <--> i7
## error8 0.5189 0.08693 5.969 2.385e-09 i8 <--> i8
## error9 0.7538 0.10831 6.960 3.409e-12 i9 <--> i9
## error10 0.4057 0.07299 5.559 2.715e-08 i10 <--> i10
## error11 0.5266 0.07537 6.987 2.811e-12 i11 <--> i11
## error12 0.4493 0.07276 6.174 6.639e-10 i12 <--> i12
## cov1 -1.0251 0.04276 -23.972 5.389e-127 EC <--> EA
##
## Iterations = 20
# get standardized coefficients of good model
stdCoef(cfa.ei.output.good)
## Std. Estimate
## 1 ea1 0.5886 i1 <--- EA
## 2 ea2 0.5874 i3 <--- EA
## 3 ea3 0.4695 i5 <--- EA
## 4 ea4 0.2922 i7 <--- EA
## 5 ea5 0.6028 i9 <--- EA
## 6 ea6 0.5251 i11 <--- EA
## 7 ec1 -0.7695 i2 <--- EC
## 8 ec2 0.7032 i4 <--- EC
## 9 ec3 0.7220 i6 <--- EC
## 10 ec4 -0.7163 i8 <--- EC
## 11 ec5 0.7744 i10 <--- EC
## 12 ec6 0.6984 i12 <--- EC
## 13 1.0000 EA <--> EA
## 14 1.0000 EC <--> EC
## 15 error1 0.6536 i1 <--> i1
## 16 error2 0.4079 i2 <--> i2
## 17 error3 0.6550 i3 <--> i3
## 18 error4 0.5055 i4 <--> i4
## 19 error5 0.7796 i5 <--> i5
## 20 error6 0.4788 i6 <--> i6
## 21 error7 0.9146 i7 <--> i7
## 22 error8 0.4870 i8 <--> i8
## 23 error9 0.6366 i9 <--> i9
## 24 error10 0.4004 i10 <--> i10
## 25 error11 0.7243 i11 <--> i11
## 26 error12 0.5122 i12 <--> i12
## 27 cov1 -0.3722 EC <--> EA
# compare the two models
cfa.ei.output.good
##
## Model Chisquare = 60.42 Df = 53
##
## ea1 ea2 ea3 ea4 ea5 ea6 ec1 ec2 ec3
## 0.5474 0.5077 0.4376 0.2694 0.5452 0.3914 -0.7472 0.6754 0.6967
## ec4 ec5 ec6 error1 error2 error3 error4 error5 error6
## -0.7438 0.7690 0.6435 0.5654 0.3847 0.4893 0.4662 0.6772 0.4458
## error7 error8 error9 error10 error11 error12 cov1
## 0.7778 0.5251 0.5208 0.3949 0.4024 0.4348 -0.3722
##
## Iterations = 18
cfa.ei.output.bad
##
## Model Chisquare = 116.9 Df = 53
##
## ea1 ea2 ea3 ea4 ea5 ea6 ec1 ec2 ec3
## -0.2117 -0.7456 -0.2212 0.6548 -0.2326 0.6728 0.1836 0.7479 0.2535
## ec4 ec5 ec6 error1 error2 error3 error4 error5 error6
## -0.7619 0.1701 -0.6322 0.8202 0.3871 0.6982 0.4935 0.8146 0.4786
## error7 error8 error9 error10 error11 error12 cov1
## 0.8167 0.5189 0.7538 0.4057 0.5266 0.4493 -1.0251
##
## Iterations = 20
# compare AIC and BIC
AIC(cfa.ei.output.good)
## [1] 110.4
AIC(cfa.ei.output.bad)
## [1] 166.9
BIC(cfa.ei.output.good)
## [1] -183.7
BIC(cfa.ei.output.bad)
## [1] -127.2
# this is included in the above mentioned documentation
# load the lavaan package (only needed once per session)
require(lavaan)
## Loading required package: lavaan
## This is lavaan 0.5-16
## lavaan is BETA software! Please report any bugs.
##
## Attaching package: 'lavaan'
##
## Die folgenden Objekte sind maskiert from 'package:sem':
##
## cfa, sem
# specify the model
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
# fit the model
fit <- cfa(HS.model, data=HolzingerSwineford1939)
# display summary output
summary(fit, fit.measures=TRUE)
## lavaan (0.5-16) converged normally after 35 iterations
##
## Number of observations 301
##
## Estimator ML
## Minimum Function Test Statistic 85.306
## Degrees of freedom 24
## P-value (Chi-square) 0.000
##
## Model test baseline model:
##
## Minimum Function 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
##
## Number of free parameters 21
## 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 0.071 0.114
## P-value RMSEA <= 0.05 0.001
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.065
##
## Parameter estimates:
##
## Information Expected
## Standard Errors Standard
##
## Estimate Std.err Z-value P(>|z|)
## Latent variables:
## 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:
## 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:
## x1 0.549 0.114
## x2 1.134 0.102
## x3 0.844 0.091
## x4 0.371 0.048
## x5 0.446 0.058
## x6 0.356 0.043
## x7 0.799 0.081
## x8 0.488 0.074
## x9 0.566 0.071
## visual 0.809 0.145
## textual 0.979 0.112
## speed 0.384 0.086
# get data
ddf <- read.delim("http://r.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
m.ei <- 'EA =~ i1 + i3 + i5 + i7 + i9 + i11
EC =~ i2 + i4 + i6 + i8 + i10 + i12'
# fit the model
fit <- cfa(m.ei, data=ddf)
# display summary output
summary(fit, fit.measures=TRUE)
## lavaan (0.5-16) converged normally after 30 iterations
##
## Number of observations 100
##
## Estimator ML
## Minimum Function Test Statistic 61.027
## Degrees of freedom 53
## P-value (Chi-square) 0.210
##
## Model test baseline model:
##
## Minimum Function 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
##
## Number of free parameters 25
## 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 0.000 0.077
## P-value RMSEA <= 0.05 0.642
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.055
##
## Parameter estimates:
##
## Information Expected
## Standard Errors Standard
##
## Estimate Std.err Z-value P(>|z|)
## Latent variables:
## 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:
## EA ~~
## EC 0.151 0.060 2.513 0.012
##
## Variances:
## i1 0.560 0.101
## i3 0.484 0.087
## i5 0.670 0.107
## i7 0.770 0.113
## i9 0.516 0.095
## i11 0.398 0.067
## i2 0.381 0.068
## i4 0.462 0.076
## i6 0.441 0.074
## i8 0.520 0.087
## i10 0.391 0.070
## i12 0.430 0.070
## EA 0.297 0.111
## EC 0.553 0.127
# compare it to the bad model
m.ei.bad <- 'EA =~ i1 + i2 + i3 + i4 + i5 + i6
EC =~ i7 + i8 + i9 + i10 + i11 + i12'
# fit the model
fit.bad <- cfa(m.ei.bad, data=ddf)
## Warning: lavaan WARNING: covariance matrix of latent variables is not
## positive definite; use inspect(fit,"cov.lv") to investigate.
# display summary output
summary(fit.bad, fit.measures=TRUE)
## lavaan (0.5-16) converged normally after 72 iterations
##
## Number of observations 100
##
## Estimator ML
## Minimum Function Test Statistic 118.091
## Degrees of freedom 53
## P-value (Chi-square) 0.000
##
## Model test baseline model:
##
## Minimum Function 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
##
## Number of free parameters 25
## 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 0.084 0.138
## P-value RMSEA <= 0.05 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.109
##
## Parameter estimates:
##
## Information Expected
## Standard Errors Standard
##
## Estimate Std.err Z-value P(>|z|)
## Latent variables:
## EA =~
## 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
## EC =~
## 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:
## EA ~~
## EC 0.039 0.028 1.416 0.157
##
## Variances:
## i1 0.812 0.116
## i2 0.383 0.069
## i3 0.691 0.099
## i4 0.489 0.079
## i5 0.806 0.115
## i6 0.474 0.077
## i7 0.809 0.115
## i8 0.514 0.086
## i9 0.746 0.107
## i10 0.402 0.072
## i11 0.521 0.074
## i12 0.445 0.072
## EA 0.044 0.041
## EC 0.033 0.035
Daten nicht erhältlich. Daher nur ein paar Bemerkungen
Basis: Quelle
pca <- princomp(factor.data) summary(pca) loadings(pca) plot(pca, type=“lines”) biplot(pca)
eigen.values <- eigen(cor(factor.data)) plot(eigen.values$values, type=“both”)
efa <- fatanal(factor.data, 3, rotation=“promax”) loadings(efa)
library(sem) cov.matrix <- cof(na.omit(factor.data))
cov.matrix
cfa.validation <- specifyModel()
Bemerkungen zu Fit-Indices mit ihrer Definition.
UCLA Video Tutorial
Field (2012, p. 112) Kapitel 3: R Environment