The ggplot2 plus syntax is a much better fit for what I was attempting. For model building, summing models makes more sense than piping them. And also, the code needed to implement this is much shorter. So for something like:
mb <- mxModel("bivariate Heterogeneity Path Specification",
type = "RAM",
manifestVars = c('X','Y')) +
mxPath( from=c('X','Y'), arrows=2, free=T, values=1, lbound=.01 ) +
mxPath( from="X", to="Y", arrows=2, free=T, values=.2, lbound=.01) +
mxPath( from="one", to=c("X", 'Y'), arrows=1, free=T, values=c(0.1,-0.1),
ubound=c(NA,0), lbound=c(0,NA))
mb <- mxGenerateData(mb, nrows = 1000, returnModel = T)
out <- mxRun(mb)
summary(out)
Or want to separate the data object from the model building part?
model <- twinData |>
dplyr::select(ht1, bmi1, zygosity) |>
mxData(type = "raw") |>
mxModel(name ="test", manifestVars = c("ht1", "bmi1"), type = "RAM") +
mxPath( from="one", to=c("ht1","bmi1"), arrows=1, free=TRUE, values=c(1,1) ) +
mxPath( from="ht1", to="bmi1", arrows=1, free=TRUE, values=1) +
mxPath( from=c("ht1","bmi1"), arrows=2, free=TRUE, values = c(1,1) )
run <- mxRun(model)
summary(run)
You just need to add a new function into the MxModel method:
`+.MxModel` <- function (e1, e2) {
mxModel(e1, e2)
}
Three lines!