Illustrating CFAs – Graphviz

So after yesterdays post you probably ran this fancy new confirmatory factor analysis (CFA) – showed your friends all the cool fit stats and… nothing.

As important as doing things right is being able to let others know that. For CFA the method of choice to illustrate the connections between variables are path diagrams these are best generated using graphviz.

The example above is generated by the following code:

digraph HSCFA {

Factor_1 -> y1 [weight=1000, label="0.80"];

Factor_1 -> y2 [weight=1000, label="0.80"];

Factor_1 -> y3 [weight=1000, label="0.80"];

Factor_1 -> y4 [weight=1000, label="0.80"];

Factor_2 -> y5 [weight=1000, label="0.80"];

Factor_2 -> y6 [weight=1000, label="0.80"];

Factor_2 -> y7 [weight=1000, label="0.80"];

Factor_2 -> y8 [weight=1000, label="0.80"];

Factor_1->Factor_2 [dir=both"];

y1 [shape=box,group="obsvar"];

y2 [shape=box,group="obsvar"];

y3 [shape=box,group="obsvar"];

y4 [shape=box,group="obsvar"];

y5 [shape=box,group="obsvar"];

y6 [shape=box,group="obsvar"];

y7 [shape=box,group="obsvar"];

y8 [shape=box,group="obsvar"];

{ rank = same; y1; y2; y3; y4; y5; y6; y7; y8}

{ rank = same; Factor_2; Factor_1; }

{ rank = max; d1; d2; d3; d4; d5; d6; d7; d8}

d1 -> y1;

d1 [shape=plaintext,label=""];

d2 -> y2;

d2 [shape=plaintext,label=""];

d3 -> y3;

d3 [shape=plaintext,label=""];

d4 -> y4;

d4 [shape=plaintext,label=""];

d5 -> y5;

d5 [shape=plaintext,label=""];

d6 -> y6;

d6 [shape=plaintext,label=""];

d7 -> y7;

d7 [shape=plaintext,label=""];

d8 -> y8;

d8 [shape=plaintext,label=""];


This looks like a lot to draw such a simple diagram, but please believe me not having to adjust these item labels or try to generate a file with a decent resolution that you can sent your publisher, can also take you a day or two…
More complex exmples can be found here.

If you are using the sem package to fit the SEM, you can generate the code for graphviz that will plot the model with standardized estimates detailed in this post.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>