You are here

Remove path from an existed model

3 posts / 0 new
Last post
Veronica_echo's picture
Offline
Joined: 02/23/2018 - 01:57
Remove path from an existed model

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

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)
AdminRobK's picture
Offline
Joined: 01/24/2014 - 12:15
remove=TRUE or path labels
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)
)

That should work.

Is there any more convinience way to remove path?

If you want to remove an entire mxPath() statement, you can pass the statement back to mxModel(), along with argument remove=TRUE to mxModel(), and the MxModel object itself as first argument to mxModel(). Alternately, you could give all of your paths labels (via the labels argument to mxPath()), and fix specific paths to zero via omxSetParameters().

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
umxRAM and umxModify

Easiest/least error-prone thing to drop a latent in cases like this is often just build a new model. However...

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)