Open cjvanlissa opened 1 year ago
@maugavilla this is a real headscratcher for me... do you have ideas?
I think a possible solution is to fix the $values
slot of the S
model matrix for the exogeneours variables to the observed variance in the data.
Because right now their variance is not included at all when fixed.x=T
, but we need to include it, but as a fixed value.
Not sure where to add it into the as.ram()
parser, but something like this
` dat <- iris colnames(dat) <- c("SepalLength","SepalWidth", "PetalLength","PetalWidth","Species")
mod <- as_ram("SepalLength ~ aPetalLength SepalLength ~~bSepalLength", fixed.x = T) mod
mod$S$values["PetalLength","PetalLength"] <- var(dat$PetalLength)
res <- run_mx(mod, data = dat) summary(res)`
Hope this makes sense
I've implemented a fix that does this, but only for the variance of observed variables. Not sure if that is correct, what do you think?
I think this makes sense, and matches how lavaan handles is in several parts. For example, I get the same estimates, number of parameters, df. But the logLik is different. Which makes me think that lavaan ignores the X side of the equations for the logLik estimation. While OpenMx still includes them, leading to the discrepancy in fit but on model parameters
` library(tidySEM)
dat <- iris colnames(dat) <- c("SepalLength","SepalWidth", "PetalLength","PetalWidth","Species")
mod <- as_ram("SepalLength ~ aPetalLength SepalLength ~~bSepalLength", fixed.x = T) mod mod$S
res <- run_mx(mod, data = dat) summary(res)
library(lavaan)
ss <- sem("SepalLength ~ aPetalLength SepalLength ~~bSepalLength", data=dat, meanstructure=T, fixed.x=T) summary(ss, fit.measures=T) parameterestimates(ss, ci=T)
logLik(res) logLik(ss) `
Any thoughts about what the consequences of this are for different types of models, and whether we should do anything about this?
We would need to adjust the fit measures in OpenMx to ignore the x side. Which I dont think we can, or would be easy. I would suggest to add a warning, when fixed.x =T, saying tha fit indices might be unreliable in OpenMx
The top example does not work, the bottom one does - but it is inconvenient to specify the variance of exogenous variables by hand: