Diese Musterlösung wurde erstellt von Peter Hähner (Ruhr-Universität Bochum).
(c) Luhmann: R für Einsteiger, 5. Aufl., Beltz, 2020
Setzen Sie ein Arbeitsverzeichnis oder legen Sie ein entsprechendes R-Projekt an (Kap. 23).
Laden Sie dann die Datei erstis.RData.
load("erstis.RData")
Laden Sie die benötigten Pakete (ggf. müssen Sie diese vorab noch installieren).
library(lavaan)
library(semPlot)
Prüfen Sie, ob der Zusammenhang zwischen Lebenszufriedenheit (lz.1; abhängige Variable) und Neurotizismus (neuro) und Extraversion (extra) (Prädiktoren) jeweils durch die Stimmung (gs.1) vermittelt wird. Wählen Sie ein angemessenes Verfahren zur Prüfung des Mediationseffekts und fordern Sie auch standardisierte Koeffizienten an.
# Modell spezifizieren
aufgabe.1 <- ' # a Pfade
gs.1 ~ a1*neuro + a2*extra
# b und c Pfade
lz.1 ~ b*gs.1 + c1*neuro + c2*extra
# Indirekte Effekte
indNeuro := a1*b
indExtra := a2*b
# Totale Effekte
totalNeuro := a1*b + c1
totalExtra := a2*b + c2'
# Modell schätzen
aufgabe.1.fit <- sem(aufgabe.1, data = erstis, se = "bootstrap")
# Unstandardisierte und standardisierte Koeffizienten ausgeben lassen
summary(aufgabe.1.fit, standardized = TRUE)
## lavaan 0.6-5 ended normally after 33 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 7
##
## Used Total
## Number of observations 187 191
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Parameter Estimates:
##
## Standard errors Bootstrap
## Number of requested bootstrap draws 1000
## Number of successful bootstrap draws 1000
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## gs.1 ~
## neuro (a1) -0.245 0.061 -4.034 0.000 -0.245 -0.298
## extra (a2) 0.179 0.071 2.514 0.012 0.179 0.188
## lz.1 ~
## gs.1 (b) 5.377 0.569 9.455 0.000 5.377 0.586
## neuro (c1) -0.602 0.470 -1.280 0.200 -0.602 -0.080
## extra (c2) 0.836 0.496 1.686 0.092 0.836 0.096
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .gs.1 0.331 0.033 9.934 0.000 0.331 0.879
## .lz.1 18.844 1.985 9.494 0.000 18.844 0.594
##
## Defined Parameters:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## indNeuro -1.318 0.342 -3.856 0.000 -1.318 -0.174
## indExtra 0.961 0.391 2.459 0.014 0.961 0.110
## totalNeuro -1.920 0.560 -3.426 0.001 -1.920 -0.254
## totalExtra 1.796 0.639 2.811 0.005 1.796 0.206
# Konfidenzintervall für indirekte Effekte ausgeben lassen
parameterEstimates(aufgabe.1.fit, ci = TRUE, boot.ci.type = "bca.simple")
## lhs op rhs label est se z pvalue ci.lower
## 1 gs.1 ~ neuro a1 -0.245 0.061 -4.034 0.000 -0.373
## 2 gs.1 ~ extra a2 0.179 0.071 2.514 0.012 0.034
## 3 lz.1 ~ gs.1 b 5.377 0.569 9.455 0.000 4.338
## 4 lz.1 ~ neuro c1 -0.602 0.470 -1.280 0.200 -1.574
## 5 lz.1 ~ extra c2 0.836 0.496 1.686 0.092 -0.242
## 6 gs.1 ~~ gs.1 0.331 0.033 9.934 0.000 0.273
## 7 lz.1 ~~ lz.1 18.844 1.985 9.494 0.000 15.602
## 8 neuro ~~ neuro 0.556 0.000 NA NA 0.556
## 9 neuro ~~ extra 0.014 0.000 NA NA 0.014
## 10 extra ~~ extra 0.415 0.000 NA NA 0.415
## 11 indNeuro := a1*b indNeuro -1.318 0.342 -3.856 0.000 -2.030
## 12 indExtra := a2*b indExtra 0.961 0.391 2.459 0.014 0.184
## 13 totalNeuro := a1*b+c1 totalNeuro -1.920 0.560 -3.426 0.001 -2.977
## 14 totalExtra := a2*b+c2 totalExtra 1.796 0.639 2.811 0.005 0.440
## ci.upper
## 1 -0.127
## 2 0.313
## 3 6.553
## 4 0.314
## 5 1.688
## 6 0.410
## 7 23.749
## 8 0.556
## 9 0.014
## 10 0.415
## 11 -0.692
## 12 1.751
## 13 -0.763
## 14 2.959
Beide indirekte Effekte sind signifikant, da der Wert 0 jeweils nicht im Konfidenzintervall enthalten ist.
Die Items stim1, stim4, stim8 und stim11 sollen jeweils die gute vs. schlechte Stimmung messen, wobei stim4 und stim11 negativ formuliert sind. Prüfen Sie, ob ein zweifaktorielles Modell, in dem die positiven und negativen Items auf unterschiedlichen Faktoren laden, besser passt als ein einfaktorielles Modell.
# Einfaktorielles Modell spezifizieren und schätzen
aufgabe.2a <- 'stimmung =~ stim1 + stim4 + stim8 + stim11'
aufgabe.2a.fit <- cfa(aufgabe.2a, data = erstis)
# Zweifaktorielles Modell spezifizieren und schätzen
aufgabe.2b <- 'neg.Faktor =~ stim4 + stim11
pos.Faktor =~ stim1 + stim8'
aufgabe.2b.fit <- cfa(aufgabe.2b, data = erstis)
# Fit-Statistiken und Modellparameter anfordern
summary(aufgabe.2a.fit, fit = TRUE)
## lavaan 0.6-5 ended normally after 17 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 8
##
## Used Total
## Number of observations 188 191
##
## Model Test User Model:
##
## Test statistic 17.284
## Degrees of freedom 2
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 227.047
## Degrees of freedom 6
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.931
## Tucker-Lewis Index (TLI) 0.793
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -778.390
## Loglikelihood unrestricted model (H1) -769.748
##
## Akaike (AIC) 1572.780
## Bayesian (BIC) 1598.672
## Sample-size adjusted Bayesian (BIC) 1573.332
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.202
## 90 Percent confidence interval - lower 0.121
## 90 Percent confidence interval - upper 0.294
## P-value RMSEA <= 0.05 0.002
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.059
##
## Parameter Estimates:
##
## Information Expected
## Information saturated (h1) model Structured
## Standard errors Standard
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## stimmung =~
## stim1 1.000
## stim4 -0.558 0.080 -6.958 0.000
## stim8 0.887 0.098 9.019 0.000
## stim11 -0.652 0.090 -7.280 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .stim1 0.269 0.052 5.208 0.000
## .stim4 0.341 0.039 8.696 0.000
## .stim8 0.226 0.042 5.450 0.000
## .stim11 0.407 0.048 8.546 0.000
## stimmung 0.491 0.085 5.760 0.000
summary(aufgabe.2b.fit, fit = TRUE)
## lavaan 0.6-5 ended normally after 22 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 9
##
## Used Total
## Number of observations 188 191
##
## Model Test User Model:
##
## Test statistic 1.758
## Degrees of freedom 1
## P-value (Chi-square) 0.185
##
## Model Test Baseline Model:
##
## Test statistic 227.047
## Degrees of freedom 6
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.997
## Tucker-Lewis Index (TLI) 0.979
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -770.627
## Loglikelihood unrestricted model (H1) -769.748
##
## Akaike (AIC) 1559.254
## Bayesian (BIC) 1588.382
## Sample-size adjusted Bayesian (BIC) 1559.875
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.064
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.217
## P-value RMSEA <= 0.05 0.283
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.013
##
## Parameter Estimates:
##
## Information Expected
## Information saturated (h1) model Structured
## Standard errors Standard
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## neg.Faktor =~
## stim4 1.000
## stim11 1.180 0.187 6.302 0.000
## pos.Faktor =~
## stim1 1.000
## stim8 0.886 0.108 8.176 0.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## neg.Faktor ~~
## pos.Faktor -0.253 0.047 -5.350 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .stim4 0.263 0.042 6.222 0.000
## .stim11 0.295 0.054 5.412 0.000
## .stim1 0.249 0.059 4.201 0.000
## .stim8 0.212 0.047 4.490 0.000
## neg.Faktor 0.231 0.054 4.275 0.000
## pos.Faktor 0.511 0.091 5.596 0.000
# Modellvergleich
anova(aufgabe.2b.fit, aufgabe.2a.fit)
## Chi-Squared Difference Test
##
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## aufgabe.2b.fit 1 1559.2 1588.4 1.7584
## aufgabe.2a.fit 2 1572.8 1598.7 17.2843 15.526 1 8.138e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Das zweifaktorielle Modell passt signifikant besser als das einfaktorielle Modell (χ2(1) = 15.53, p < .001).
Schätzen Sie ein Strukturgleichungsmodell, in dem die abhängige latente Variable lz (Lebenszufriedenheit, gemessen durch lz13 , lz14 und lz15) durch die unabhängigen latenten Variablen gut (gute Stimmung, gemessen durch stim1 und stim8), wach (wache Stimmung, gemessen durch stim2 und stim10) sowie ruhig (ruhige Stimmung, gemessen durch stim6 und stim12) vorhergesagt wird. Stellen Sie das Strukturgleichungsmodell auch grafisch dar.
# Modell spezifizieren
aufgabe.3 <- ' # Messmodelle
lz =~ lz13 + lz14 + lz15
gut =~ stim1 + stim8
wach =~ stim2 + stim10
ruhig =~ stim6 + stim12
#Strukturmodell
lz ~ gut + wach + ruhig'
# Modell schätzen
aufgabe.3.fit <- sem(aufgabe.3, data = erstis)
# Fit-Statistiken und Modellparameter anfordern
summary(aufgabe.3.fit, fit = TRUE, standardized = TRUE)
## lavaan 0.6-5 ended normally after 39 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 24
##
## Used Total
## Number of observations 187 191
##
## Model Test User Model:
##
## Test statistic 31.097
## Degrees of freedom 21
## P-value (Chi-square) 0.072
##
## Model Test Baseline Model:
##
## Test statistic 729.133
## Degrees of freedom 36
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.985
## Tucker-Lewis Index (TLI) 0.975
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -2085.792
## Loglikelihood unrestricted model (H1) -2070.243
##
## Akaike (AIC) 4219.584
## Bayesian (BIC) 4297.131
## Sample-size adjusted Bayesian (BIC) 4221.113
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.051
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.086
## P-value RMSEA <= 0.05 0.451
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.039
##
## Parameter Estimates:
##
## Information Expected
## Information saturated (h1) model Structured
## Standard errors Standard
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## lz =~
## lz13 1.000 1.164 0.855
## lz14 0.871 0.074 11.706 0.000 1.014 0.772
## lz15 0.877 0.069 12.627 0.000 1.021 0.822
## gut =~
## stim1 1.000 0.680 0.779
## stim8 0.979 0.091 10.803 0.000 0.666 0.850
## wach =~
## stim2 1.000 0.675 0.695
## stim10 0.858 0.148 5.777 0.000 0.579 0.637
## ruhig =~
## stim6 1.000 0.600 0.599
## stim12 1.549 0.265 5.848 0.000 0.930 0.975
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## lz ~
## gut 1.510 0.226 6.695 0.000 0.881 0.881
## wach -0.542 0.256 -2.121 0.034 -0.315 -0.315
## ruhig 0.372 0.188 1.981 0.048 0.192 0.192
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## gut ~~
## wach 0.281 0.058 4.832 0.000 0.611 0.611
## ruhig 0.213 0.053 4.015 0.000 0.521 0.521
## wach ~~
## ruhig 0.239 0.061 3.939 0.000 0.590 0.590
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .lz13 0.500 0.085 5.899 0.000 0.500 0.269
## .lz14 0.699 0.091 7.648 0.000 0.699 0.405
## .lz15 0.501 0.074 6.750 0.000 0.501 0.325
## .stim1 0.300 0.044 6.882 0.000 0.300 0.393
## .stim8 0.170 0.034 4.970 0.000 0.170 0.277
## .stim2 0.488 0.088 5.558 0.000 0.488 0.517
## .stim10 0.491 0.073 6.696 0.000 0.491 0.594
## .stim6 0.643 0.084 7.681 0.000 0.643 0.641
## .stim12 0.045 0.122 0.369 0.712 0.045 0.050
## .lz 0.436 0.115 3.777 0.000 0.321 0.321
## gut 0.462 0.079 5.878 0.000 1.000 1.000
## wach 0.456 0.110 4.139 0.000 1.000 1.000
## ruhig 0.360 0.095 3.813 0.000 1.000 1.000
# Grafische Darstellung (mit standardisierten Koeffizienten)
semPaths(aufgabe.3.fit, whatLabels = "standardized")