So I am trying to run an SEM with the code below: (Btw, I have zero background in R and I just read and watched videos on how to run it for my Phd. So Please bear with me with this question)
library(lavaan)
library(semPlot)
set.seed(123)
n <- 500
categorical_vars <- c("Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10", "Q11", "Q12", "Q13", "Q14", "Q15", "Q16")
other_vars <- c("IV", "DV1", "DV2", "DV3")
all_vars <- c(categorical_vars, other_vars)
DATA <- data.frame(matrix(sample(1:3, n * length(categorical_vars), replace = TRUE), nrow = n, ncol = length(categorical_vars)))
names(DATA) <- categorical_vars
DATA$IV <- sample(10:30, n, replace = TRUE)
DATA$DV1 <- sample(1:10, n, replace = TRUE)
DATA$DV2 <- sample(1:10, n, replace = TRUE)
DATA$DV3 <- sample(1:10, n, replace = TRUE)
Proposed_mod <-'
F1 =~ Q1 + Q2 + Q3 + Q4
F2 =~ Q5 + Q6 + Q7 + Q8
F3 =~ Q9 + Q10 + Q11 + Q12
F4 =~ Q13 + Q14 + Q15 + Q16
MED =~ 1*F1 + F2 + F3 + F4
PSYCH =~ DV1 + DV2 + DV3
MED ~ a*IV
PSYCH ~ b*MED
PSYCH ~ c*IV
ind := b*c
'
f1 <- sem(Proposed_mod,
data = DATA,
ordered = categorical_vars,
std.lv = TRUE,
estimator = "WLSMV")
summary(f1, standardized = TRUE, fit.measures = TRUE)
semPaths(f1,
what = "path",
whatLabels = "std",
layout = "tree2",
edge.label.cex = .5,
sizeMan = 3,
sizeLat = 5,
fade = FALSE,
thresholds = F,
color = list(lat = "lightblue", man = "white"))
Everything runs perfectly including the summary section where I get the usual fit acceptable fit indices. However, when I try to run the semPaths to visualize my SEM Model I get the error
dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent
I ran out of options already. Also, I tried to run the same code in the SEM funciton of JASP and I get the same error. Please help. Thanks