omxGraphviz help (making path diagrams)

Wiki home page

OpenMx can output path diagrams using the dot syntax. You can learn about this language for describing path diagrams at several online tutorials: An Introduction to GraphViz and dot - O'Reilly Media, Using GraphViz, a Brief Tutorial | Orient Lodge. The R for generating a path diagram from a model is straightforward:

	 omxGraphviz(model, dotFilename="")

(currently for RAM models only) If you leave parameter 2 blank, the dot file will be output into the R console. Here is a complete example:

require(OpenMx)
data(demoOneFactor)
manifests <- names(demoOneFactor)
latents <- c("G1")
model1 <- mxModel("One Factor", type="RAM",
	manifestVars = manifests,
	latentVars = latents,
	mxPath(from=latents, to=manifests),
	mxPath(from=manifests, arrows=2),
	mxPath(from=latents, arrows=2, free=F, values=1.0),
	mxData(cov(demoOneFactor), type="cov",numObs=500)
)
omxGraphviz(model1, "one-factor-generated.dot")

Rendering the output

dot output is in simple text file describing the latent and manifest variables (nodes) and their connections (edges) of a diagram. To visualize the diagram, this .dot script must be processed by an application such as Graphviz. This app does a nice job of rendering .dot. Other programmes that can open .dot include Omnigraffle. This site https://ashitani.jp/gv/ has an online renderer, which is handy for cut and paste: Paste this in to see a sex lim model: t1 [label="Pt1", shape=box] t2 [label="Pt2", shape=box] Af -> Am [dir=both, label="ag"] Cf -> Cm [dir=both, label="eta"] Af -> t1 [label="af"] Cf -> t1 [label="cf"] Ef -> t1 [label="ef"] Am -> t2 [label="am"] Cm -> t2 [label="cm"] Em -> t2 [label="em"] {rank=min; Af; Cf; Ef; Am; Cm; Em; }; {rank=max; t1; t2};

Comments

The example on this page:
omxGraphviz(model, dotFileName="")
should be
omxGraphviz(model, dotFilename="")
(i.e., "Name" written as "name"), otherwise R does not understand it.
Cheers,
- Kimmo