Strukturgleichungsmodelle mit R lavaan
3. Moderationsanalyse - latente Interaktionen

Arndt Regorz, Dipl. Kfm. & MSc. Psychologie, 29.11.2022

Dieses ist eine Begleitseite zum Video-Tutorial über die Prüfung einer latenten Interaktion mit dem Verfahren des Double Mean Centering.



(Hinweis: Mit Anklicken des Videos wird ein Angebot des Anbieters YouTube genutzt.)


R-Code aus dem Video-Tutorial

Hier ist der gesamte Code aus dem Video-Tutorial:

library(lavaan)
library(semTools)

head(mydata)

# Fit testen (noch ohne Interaktion)

# Messmodell (step 1)

test_model <- '
# Ladungen
iv =~ IV1 + IV2 + IV3
mod =~ MOD1 + MOD2 + MOD3
dv =~ DV1 + DV2 + DV3
'

test_fit <- cfa(test_model, data = mydata, estimator="MLM")

summary(test_fit, fit.measures = TRUE, standardized=TRUE)

mi <- modificationindices(test_fit)
mi[mi$mi>10,]

# Strukturmodell (step 2; hier nicht nötig, da saturiert)

test_model2 <- '
# Ladungen
iv =~ IV1 + IV2 + IV3
mod =~ MOD1 + MOD2 + MOD3
dv =~ DV1 + DV2 + DV3

dv ~ iv + mod
'

test_fit2 <- sem(test_model2, data = mydata, estimator="MLM")

summary(test_fit2, fit.measures = TRUE, standardized=TRUE)

mi <- modificationindices(test_fit)
mi[mi$mi>10,]

# Double Mean Centering

mydata_dmc <- indProd (mydata , var1 = c("IV1", "IV2", "IV3"),
var2 = c("MOD1", "MOD2", "MOD3"),
match = FALSE , meanC = TRUE ,
residualC = FALSE , doubleMC = TRUE)

head(mydata_dmc)

# Modellschätzung mit latenter Interaktion

int_model <- '
# Ladungen
iv =~ IV1 + IV2 + IV3
mod =~ MOD1 + MOD2 + MOD3
dv =~ DV1 + DV2 + DV3
int =~ IV1.MOD1 + IV1.MOD2 + IV1.MOD3 + IV2.MOD1 + IV2.MOD2 +
IV2.MOD3 + IV3.MOD1 + IV3.MOD2 + IV3.MOD3

# Regression
dv ~ iv + mod + int

# Fehlerkovarianzen
IV1.MOD1 ~~ IV1.MOD2 + IV1.MOD3 + IV2.MOD1 + IV3.MOD1
IV1.MOD2 ~~ IV1.MOD3 + IV2.MOD2 + IV3.MOD2
IV1.MOD3 ~~ IV2.MOD3 + IV3.MOD3
IV2.MOD1 ~~ IV2.MOD2 + IV2.MOD3 + IV3.MOD1
IV2.MOD2 ~~ IV2.MOD3 + IV3.MOD2
IV2.MOD3 ~~ IV3.MOD3
IV3.MOD1 ~~ IV3.MOD2 + IV3.MOD3
IV3.MOD2 ~~ IV3.MOD3
'

int_fit <- sem(int_model, data = mydata_dmc, estimator="MLM")

summary(int_fit, fit.measures = TRUE, standardized=TRUE)

# Simple Slopes

probe <- probe2WayMC(int_fit, c("iv", "mod", "int"), "dv", "mod",
c(-sqrt(1.462),0, sqrt(1.462)))
probe

plotProbe(probe, c(-3,3))

# Double mean centering per Hand

mydata2 <- latent_interaction_SEM_full

# Step 1: Mean Centering der Indikatoren (1. Mean Centering)

attach(mydata2)
mydata2$IV1c <- scale(IV1, scale = FALSE)
mydata2$IV2c <- scale(IV2, scale = FALSE)
mydata2$IV3c <- scale(IV3, scale = FALSE)
mydata2$MOD1c <- scale(MOD1, scale = FALSE)
mydata2$MOD2c <- scale(MOD2, scale = FALSE)
mydata2$MOD3c <- scale(MOD3, scale = FALSE)
detach(mydata2)

# Step 2: Produktvariablen

attach(mydata2)
mydata2$I1M1 <- IV1c * MOD1c
mydata2$I1M2 <- IV1c * MOD2c
mydata2$I1M3 <- IV1c * MOD3c
mydata2$I2M1 <- IV2c * MOD1c
mydata2$I2M2 <- IV2c * MOD2c
mydata2$I2M3 <- IV2c * MOD3c
mydata2$I3M1 <- IV3c * MOD1c
mydata2$I3M2 <- IV3c * MOD2c
mydata2$I3M3 <- IV3c * MOD3c
detach(mydata2)

# Step 3: Mean Centering der Produktvariablen (2. Mean Centering)

attach(mydata2)
mydata2$I1M1c <- scale(I1M1, scale = FALSE)
mydata2$I1M2c <- scale(I1M2, scale = FALSE)
mydata2$I1M3c <- scale(I1M3, scale = FALSE)
mydata2$I2M1c <- scale(I2M1, scale = FALSE)
mydata2$I2M2c <- scale(I2M2, scale = FALSE)
mydata2$I2M3c <- scale(I2M3, scale = FALSE)
mydata2$I3M1c <- scale(I3M1, scale = FALSE)
mydata2$I3M2c <- scale(I3M2, scale = FALSE)
mydata2$I3M3c <- scale(I3M3, scale = FALSE)
detach(mydata2)

head(mydata2)