I wasn't sure whether this was more appropriate to ask here or CrossValidated as I'm specifically asking about using R / lavaan
...
I'm not sure if I've completely misunderstood how violations of assumptions are checked. I understand that we can obtain diagnostic plots for linear models with:
model <- lm(data$outcome ~ data$predictor)
plot(model, which = c(1:6))
But I'm having trouble figuring out how I should do this for a mediation model fitted like so:
model <- 'outcome ~ c*predictor + b*mediator
mediator ~ a*predictor
indirect_effect := a*b
total_effect := c + (a*b)
'
model.fit <- lavaan::sem(
model = model,
data = data,
missing = "FIML",
estimator = "ML")
Then if I try obtaining plots in the same way (plot(model.fit, which = c(1:6))
), I get Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'
.
Also, to check for violations of assumptions for Pearson's correlation, would we do so by looking at the structure of each variable individually, or by making a linear model (lm(data$outcome ~ data$predictor)
), or using the correlation itself (cor.test(data$var1, data$var2)
) in some way?