R Funktion selber schreiben -> Moderationsanalyse

I'm trying to create my first function in R to calculate moderation analysis. But now a problem accured I cannot solve :/ When I run my function, I don't get any output.. I also tried print() and return() with the same result. Any recommendations?

Moderation <- function(Mod, UV, AV) {
meanUV <- mean(UV, na.rm = TRUE)
sdUV <- sd(UV, na.rm = TRUE)
ZUV <-((UV - meanUV)/sdUV)

meanMod <- mean(Mod, na.rm = TRUE)
sdMod <- sd(Mod, na.rm = TRUE)
ZMod <- (Mod - meanMod)/sdMod

Interaktion <- ZUV*ZAV
Moderation.fit <- 'AV ~ ZUV + ZMod + Interaktion'
summary(sem(model = Moderation.fit, data = MyData, meanstructure = TRUE))

Moderation(MyData$SKK, MyData$ZDT2, MyData$HO4)

Thank you for your help!

Read more here: https://stackoverflow.com/questions/64955379/r-funktion-selber-schreiben-moderationsanalyse

Content Attribution

This content was originally published by Luma at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: