You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the existence of lavPredictY() we can easily write a function lavResidualsY() to get residuals of observed variables.
lavResidualsY <- function(object,
ynames = lavNames(object, "ov.nox"),
xnames = lavNames(object, "ov.x")){
pred <- lavPredictY(object,
ynames = ynames,
xnames = xnames) |>
as.data.frame()
d <- inspect(object, "data") |>
as.data.frame()
r <- lapply(names(pred), function(x){
pred[[x]] - d[[x]]
})
res <- do.call(cbind, r) |>
as.data.frame()
names(res) <- names(pred)
res
}
mod <- "
rich ~ cover + firesev
firesev ~ age
"
f <- sem(mod, data = piecewiseSEM::keeley)
#let's get residuals and then do a test for MV normality
r <- lavResidualsY(f)
mvnormtest::mshapiro.test(t(r))
This should also work with LV models, but might take a bit more - e.g.,
Given the existence of
lavPredictY()
we can easily write a functionlavResidualsY()
to get residuals of observed variables.This should also work with LV models, but might take a bit more - e.g.,
The text was updated successfully, but these errors were encountered: