Remove path from an existed model
Posted on
Veronica_echo
Joined: 02/23/2018
Forums
Hi all,
I would like to remove one factor, say "IQ2", from a CFA (script is below). Does it work if I rewrite the model as
Is there any more convinience way to remove path?
I would like to remove one factor, say "IQ2", from a CFA (script is below). Does it work if I rewrite the model as
cfa2 <- mxModel(cfa, "one factor", mxPath(from = "Q2", to = "Q2", arrows=2, values = 0, free = F),
mxPath(from = "Q1", to = "Q2", arrows=2, values = 0, free = F),
mxPath(from = "Q1", to = observed, free = F, values = 0)
)
Is there any more convinience way to remove path?
Thanks in advance!
observed<-c("reading","writing","math","analytic")
latents<-c("Q1", "Q2")
cfa<-mxModel("two factors", type="RAM",
manifestVars=observed,
latentVars=latents,
mxPath(from=latents, to=observed,
free=c(F,T,T,T),values=c(1,1,1,1),labels=c("l1","l2","l3","l4")),
mxPath(from=observed, arrows=2,labels=c("d1","d2","d3","d4")),
mxPath(from=latents, arrows=2,connect = "unique.pairs", free = T, labels=c("p11", "p12", "p22")),
mxData(cov(intell[,1:4]),type="cov",numObs=100)
)
results<-mxRun(cfa)
remove=TRUE or path labels
That should work.
If you want to remove an entire
mxPath()
statement, you can pass the statement back tomxModel()
, along with argumentremove=TRUE
tomxModel()
, and the MxModel object itself as first argument tomxModel()
. Alternately, you could give all of your paths labels (via thelabels
argument tomxPath()
), and fix specific paths to zero viaomxSetParameters()
.Log in or register to post comments
umxRAM and umxModify
In umx, you could do:
observed = c("reading","writing","math","analytic")
m1 = umxRAM("twofactor",data = mxData(cov(intell[,1:4]),type="cov",numObs=100),
umxPath(c("Q1", "Q2"), to=observed, firstAt=1),
umxPath(var = c("Q1", "Q2")),
umxPath(var = observed),
umxPath(unique.bivariate = latents)
)
# fix all paths from Q2 to zero
m2 = umxModify(m1, regex = "Q2_to_.*", name = "noQ2", comparison = TRUE)
Log in or register to post comments