# Software for drawing bayesian networks (graphical models)

I am searching for [free] software that can produce nice looking graphical models, e.g.

Any suggestions would be appreciated.

-
You mean drawing pictures like this you linked or drawing ready models from some other software? If the latter, from which? –  mbq Oct 9 '11 at 17:57
Drawing pictures liked the one I linked –  C. Reed Oct 9 '11 at 18:30
It was created manually in Inkscape, so you can try doing the same. –  mbq Oct 9 '11 at 20:06
That's awesome - the picture you provide is one I drew for Wikipedia in 2008, and I found this question when I was figuring out how to redraw it in 2012. You provide a PNG, but it was originally an SVG. Back then, I used Inkscape and it was terrible - I had to hand edit the SVG to add in the greek letters, because it couldn't handle it back then (maybe it still can't). I don't recommend it for anyone. I'm going to give the tikz approach a shot. –  Bkkbrad Jul 13 '12 at 1:05
When I said I don't recommend it for anyone, I meant I don't recommend Inkscape for anyone trying to draw multiple consistent plate diagrams. –  Bkkbrad Jul 13 '12 at 1:11
show 2 more comments

I currently have a similar problem (drawing multiple path diagrams for my dissertation), and so I was examining many of the options listed here already to draw similar diagrams. Many of the listed resources for drawing such vector graphics (such as in microsoft office or google drawings) can produce really nice path diagrams, with fairly minimal effort. But, part of the reason I was unsatisfied with such programs is that I needed to produce many diagrams, with only fairly minor changes between each diagram (e.g. add another node, change a label). The point and click vector graphics tools aren't well suited for this, and take more effort than need be to make such minor changes. Also it becomes difficult to maintain a template between many drawings. So, I decided to examine options to produce such graphics programattically.

Graphviz, as was already mentioned by thias, came really close to having all the bells and whistles I wanted for my graphics (as well as quite simple code to produce them), but it fell short for my needs in two ways; 1) mathematical fonts are lacking (e.g. I'm not sure if you can label a node with the $\beta$ symbol in Graphviz, 2) curved lines are hard to draw (see this post on drawing path diagrams using Graphviz on @Stask's website). Because of these limitations I have currently settled (very happily) on using the Tikz/pgf drawing library in Latex. An example is below of my attempt at reproducing your graphic (the biggest pain was the labels in the lower right corners of the boxes!);

\documentclass[11pt]{report}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 10mm, thick, draw =black!80, node distance = 16mm]
\tikzstyle{connect}=[-latex, thick]
\tikzstyle{box}=[rectangle, draw=black!100]
\node[main, fill = white!100] (alpha) [label=below:$\alpha$] { };
\node[main] (theta) [right=of alpha,label=below:$\theta$] { };
\node[main] (z) [right=of theta,label=below:z] {};
\node[main] (beta) [above=of z,label=below:$\beta$] { };
\node[main, fill = black!10] (w) [right=of z,label=below:w] { };
\path (alpha) edge [connect] (theta)
(theta) edge [connect] (z)
(z) edge [connect] (w)
(beta) edge [connect] (w);
\node[rectangle, inner sep=0mm, fit= (z) (w),label=below right:N, xshift=13mm] {};
\node[rectangle, inner sep=4.4mm,draw=black!100, fit= (z) (w)] {};
\node[rectangle, inner sep=4.6mm, fit= (z) (w),label=below right:M, xshift=12.5mm] {};
\node[rectangle, inner sep=9mm, draw=black!100, fit = (theta) (z) (w)] {};
\end{tikzpicture}
\end{figure}
\end{document}
%note - compiled with pdflatex


Now, I am already writing up my dissertation in Latex, so if you just want the image without having to compile a whole Latex document it is slightly inconveniant, but there are some fairly minor workarounds to produce an image more directly (see this question over on stackoverflow). There are a host of other benifits to using Tikz for such a project though

• Extensive documentation. The pgf manual holds your hand through making some similar diagrams. And once you get your feet wet...
• A huge library of examples is there to demonstrate how to produce a huge variety of graphics.
• And finally, the Tex stack exchange site is a good place to ask any questions about Tikz. They have some wizzes over there making some pretty fancy graphics (check out their blog for some examples).

At this time I have not considered some of the libraries for drawing the diagrams in the statistical package R directly from the specified models, but in the future I may consider them to a greater extent. There are some nice examples from the qgraph library for a proof of concept of what can be accomplished in R.

-
For those interested in drawing path diagrams for SEM (or for some more ideas about what can be accomplished in Microsoft Office products), I would suggest you check out Jeremy Mile's ppt file of path diagrams (at the bottom of the referenced webpage). –  Andy W Oct 12 '11 at 12:31
Great response, it's a bit of a learning curve, but like anything TeX, I think it'll pay off in the long run. Thanks! –  C. Reed Oct 16 '11 at 18:49
(+1) Very nice, thanks for sharing! –  chl Jan 22 '12 at 19:22

Inkscape is essentially a free version of Adobe Illustrator, and is a very strong program for doing vector graphics, like the picture you posted. It also plays rather nicely with most statistical packages for doing final edits/annotations/etc. to graphs - R, SAS, etc. can output a graph as a PDF or other vector format (like .eps), and then you can bring it in to Inkscape to mess about with colors, symbols, axis labels etc.

-

You could try GraphViz.

This allows you to specify the graph in a text-file and it will be drawn automatically (avoiding overlapping arrows and so on). Go here (pdf) for a minimal example and a manual.

-

Laura Dietz has written a very nice library for tikz that allows you to draw Bayesian Networks.

-

Dia is a free open source program for drawing diagrams. I find it useful and it's not too difficult to get started.

-

If you have a particular interest in using LaTeX, the LaTeXDraw program has some nice functionality for creating flow charts with embedded latex code.

It imports / exports PSTricks code and SVG, and can also export svg, pdf, eps, jpg, png, etc. It runs in Linux, Mac OS X, and Windows.

-

You could try Google Docs Draw. It looks like it will do what you want for free, right in your browser.

-
I have tried it, but (IMHO) it lacks Inkscape's flexibility. –  suncoolsu Oct 10 '11 at 0:22