In this post, I made an SEM model and showed the results in a table.
It’s a great feature of SEM that you can sketch your ideas about how the world works, and being able to get such a sketch back out of OpenMx is very helpful.
Importantly, a figure can help readers understand what you’ve done, and it is a great help to verify for yourself that you’ve drawn the model you think you have drawn.
So… how do you get presentation-quality figures out of OpenMx?
I’ll assume you’ve got a model already run, and it’s called
In out-of-the-box OpenMx, you can say
As they say on 2-minute R: “Boom! You just made a figure!”
Sure: but where is it? Well, its a text file called
cool.dotsitting in the directory getwd() points to.
To turn it into a graphic, we have to open it in an application that understands how to read .dot or “graphviz” syntax.
First, download an application that can read .dot. On windows, that includes Vizio. On mac, it includesOmnigraffle.
An application I like, especially early on in developing a model, is GraphViz. Believe it or not, this is yet another amazing product of Bell Laboratories (as if S (and therefore R), C, Unix, Cosmic Background radiation, and the transistor to name just a few were not enough) !
That done, this code should pop up the file in Graphviz for you (you might need to make Graphviz the default application for .dot (esp. if you have word on your system))
system(paste("open ", getwd(), "/cool.dot", sep=""));
The builtin function doesn’t open the file automatically, and, importantly, doesn’t include path values or allow you to standardize them.
I wrote this function which does these things.
It also defaults to creating a file based on the
umxGraph_RAM(model) # default call opens standardized model in editor, with 2 decimal places of accuracy.
# some extra parameters
umxGraph_RAM(model, std = T, dotFilename = "name", pathLabels = "both", precision = 3)
# set the dotFilename to NA to get the syntax back
umxGraph_RAM(model, std = T, dotFilename = NA, pathLabels = "both", precision = 3)
You can grab it here