Skip to content

Graphviz

Graphviz is a great program to make directional graphs, which structural equation/path models are! It uses syntax instead of point-and-click objects, though, and the syntax is not necessarily intuitive.

Here are some examples
Example 1

// For Graphviz // the "//" indicate comments
digraph DifferentPathModels { //starts a new graphic with name "DiferentPathModels" 
size ="12,5"; // size of graphic
node [shape="box"] // sets default shape for variables ("nodes") to square 
subgraph cluster_0{ //makes a subgraph ("cluster") within the graph
X0->Y0 [label=" a"];  //makes node "X0" and "Y0" and puts an arrow ("edge") connecting them with the label "a"
ey0 -> Y0
X0->X0 [dir=both]; //makes an arrow with two arrowheads going to/from node "X0" for the variance in RAM models
ey0->ey0 [dir=both];
ey0 [shape=circle, label="ey"] // makes the "ey0" node a circle and labels it "ey"
Y0 [label="Y"];
X0 [label="X"];
{rank = max; ey0} // makes sure the "eye" node is at the bottom of the figure
} //ends cluster 0
subgraph cluster_1{
X1->Y1 [label=" a"];
ey1 -> Y1
ey1 [shape=circle, label="ey"]
Y1 [label="Y"];
X1 [label="X"];
{rank = max; ey1}
}
subgraph cluster_2{
X2->Y2 [label=" a"];
ey2 -> Y2
ey2 [shape=none, label="ey"];\\makes a node with no shape, but leaves a label
Y2 [label="Y"];
X2 [label="X"];
{rank = max; ey2} 
}
subgraph cluster_3{
X3->Y3 [label=" a"];
ey3 -> Y3
ey3 [shape=none, label=""]; // makes a node with no shape and no label
X3 [shape=none, label="X"];
Y3 [shape=none, label="Y"];
{rank = max; ey3} 
}//ends cluster 3
}// ends entire figure

Example 2

digraph MR3PredWR {
size ="12,12";
//label = "Showing Wright's rules in Multiple Regression" ;
X10 -> Y0 [label="a", color="red"]; //colors the path red
X20 -> Y0 [label=" b" ];
X30 -> Y0 [label="c" ];
E0 -> Y0 [label=" z"];
X10:e -> X20:w  [dir=both, label="d"];
X10:n -> X30:n  [dir=both, label="e"];
X20:e -> X30:w  [dir=both, label="f",];
X10 [shape=box,group="predict", label="X₁", color=red];
X20 [shape=box,group="predict", label="X₂"];
X30 [shape=box,group="predict", label="X₃"];
Y0 [shape=box,group="outcome",label="Y", color=red];
E0 [shape=circle,group="Error", label="Error \n 1-R²"];
{rank = same; X10; X20; X30}
{rank = max; E0}
X11 -> Y1 [label="a" ];
X21 -> Y1 [label=" b" ];
X31 -> Y1 [label="c", color="red"];
E1 -> Y1 [label=" z"];
X11:e -> X21:w  [dir=both, label="d"];
X11:n -> X31:n  [dir=both, label="e", color="red"];
X21:e -> X31:w  [dir=both, label="f",];
X11 [shape=box,group="predict", label="X₁", color=red];
X21 [shape=box,group="predict", label="X₂"];
X31 [shape=box,group="predict", label="X₃"];
Y1 [shape=box,group="outcome", label="Y", color=red];
E1 [shape=circle,group="Error", label="Error \n 1-R²"];
{rank = same; X11; X21; X31}
{rank = max; E1}
X12 -> Y2 [label="a" ];
X22 -> Y2 [label=" b", color="red" ];
X32 -> Y2 [label="c" ];
E2 -> Y2 [label=" z"];
X12:e -> X22:w  [dir=both, label="d", color="red"];
X12:n -> X32:n  [dir=both, label="e"];
X22:e -> X32:w  [dir=both, label="f",];
X12 [shape=box,group="predict", label="X₁", color=red];
X22 [shape=box,group="predict", label="X₂"];
X32 [shape=box,group="predict", label="X₃"];
Y2 [shape=box,group="outcome",label="Y", color=red];
E2 [shape=circle,group="Error", label="Error \n 1-R²"];
{rank = same; X12; X22; X32}
{rank = max; E2}
}
Published inUncategorized