Visualising probabilistic graphical models

Also related models, such as Neural nets



A confounder

The diagrams I most often need are directed flow graphs, a formal mathematical cousin of the flowchart, which can represent graphical models and neural nets. The diagrams I need here are nearly-enough flowchart-like that I can sketch them with a flowchart tool if need be; but they are closely integrated with the equations of a particular statistical model, so I would like to incorporate them into the same system to avoid tedious and error-prone manual sync if possible. Further, there are a couple of things I would like handled which flowchart programs are bad at, such as plate-notation and handling of inline mathematical markup, and representing network topologies.

As always, I would like to export the resulting diagrams to a modern compatible vector format which means SVG, PDF. As a fallback I would accept other formats that can be converted to the above, such as Adobe Illustrator, EPS or xfig.

dagR

dagR does R

After initializing a new DAG using a command line, the researcher can evaluate what associations are introduced by adjusting for covariables. Potentially biasing paths from exposure to outcome can be identified (see eFig. 1, demonstrating harmful adjustment using an example DAG from Fleischer and Diez Roux). Functions to conveniently add or remove nodes and arcs are included, as is a function checking introduced associations and biasing paths for all possible adjustment sets […]. The graphics capabilities of R allow fairly straightforward programming of basic DAG drawing routines, while also supporting the interactive repositioning of nodes and arcs.

It additionally calculates adjustment sets and other useful functions of the graph.

TikZiT

TikZiT (HT Luis Riera Garcia for showing me this).

diagrammeR

DiagrammeR graph

DiagrammerR is a generic graph visualisation app for R which can incidentally do graphical models.

With the DiagrammeR package you can create, modify, analyze, and visualize network graph diagrams. The output can be incorporated into RMarkdown documents, integrated with Shiny web apps, converted to other graph formats, or exported as image files.

diagrams.net

diagrams.net (formerly draw.io) is a browser-based diagram editor. It is a generic diagramming tool but has lots of affordances for the specific needs of graphical models.

Mermaid

Another browser option. mermaid is a flowcharting tool which can be pressed into service for DAGs. Unique Value Proposition: code-driven diagrams with a syntax that aspires to be so basic that it is easier than point and click. Integrates with many markdown editors. Has an online editor, and a CLI.

It also has, if anything, too many VS Code integrations. Here are two.

Graphviz

The graphviz family is nearly good, in that it supports graphing various networks, including probabilistic DAGs. Inevitably, none of its fancy algorithms ever lay it out quite like I want. There is a macOS gui and a cross-platform (WX) gui called doteditor.

graphviz model with the fastdot theme

For some purposes, I would recommend dagitty over this; the syntax is similar, but dagitty additionally accepts specification by a structural equation model.

Daggity

daggity (Textor et al. 2017) is an option for the browser and also r. I’m not 100% sure how these two parts relate to each other. Documentation for the R version was hard to find—see here.

ggdag extends daggity to the ggplot ecosystem. The ggdag bias structure vignette shows of the useful explanation diagrams available in ggdag and is also a good introduction to selection bias and causal DAGs themselves

Shinydag provides a web interface to ggdag. Shinydag is tedious to install natively, especially with the poor documentation. It runs ok in docker.

docker run -d -p 3838:3838 --name shinydag gerkelab/shinydag:latest

Now Shinydag is waiting for you at 127.0.0.1:3838/shinyDAG. It is bit crashy and clunky. I’m not sure I prefer it to plain ggdag.

Cytoscape

Cytoscape

Cytoscape is an open source software platform for visualizing complex networks and integrating these with any type of attribute data. A lot of Apps are available for various kinds of problem domains, including bioinformatics, social network analysis, and semantic web.

Matplotlib

HOWTO diagramming convnets using matplotlib in python Or: daft-pgm:

Daft is a Python package that uses matplotlib to render pixel-perfect probabilistic graphical models for publication in a journal or on the internet. With a short Python script and an intuitive model-building syntax you can design directed (Bayesian Networks, directed acyclic graphs) and undirected (Markov random fields) models and save them in any formats that matplotlib supports (including PDF, PNG, EPS and SVG).

It’s OK at programmatic DAG rendering; it would be nice if it had some kind of semi-automatic layout algorithm.

yEd

yEd is a low-key nerdview diagrammer.

yEd supports a wide variety of diagram types. In addition to the illustrated types, (BPMN Diagrams, Flowcharts, Family Trees, Semantic Networks, Social Networks, UML Class Diagrams) yEd also supports organization charts, mind maps, swimlane diagrams, Entity Relationship diagrams, and many more.

Found via A blog by Jonas Kristoffer Lindeløv which talks through pluses and minuses:

yEd is purely graphical editing which is fast to work with and great for tweaking small details. A very handy yEd feature is its intelligent snapping to alignments and equal distances when positioning objects. Actually, I don’t understand why yEd almost never makes it to the “top 10 diagram/flowchart programs” lists.

A few things I learned: To make subscripts, you have to use HTML code.… it is not possible to do double-subscripts. Also, the double-edges node is made completely manually by placing an empty ellipse above another. […] A final limitation is that arrowhead sizes cannot be changed. You can, however, zoom. Therefore, your very first decision has to be the arrowhead size. Zoom so that it is appropriate and make your graphical model.

Netron

visualizes various NNs from various frameworks.

AFAICT the style here is useful for diagnostics but does not seem to match the more manicured style that I would use for a publication. Maybe I should look deeper.

flowchart.fun

flowchart.fun (source) is a flowcharting tool which can be pressed into service for DAGs. Documentation and project goals are sparse.

TETRAD

TETRAD, the graph inference software, will also graph structural equation models.

PlotNeuralNet

Seems to do what it says on the tin, especially if you what to make convnets look pretty: HarisIqbal88/PlotNeuralNet: Latex code for making neural networks diagrams.

tikz

Laura Dietz and Jaakko Luttinen made tikz macros for drawing Bayes nets in LaTeX, tikz-bayesnet.

References

Breitling, Lutz Philipp. 2010. dagR: A Suite of R Functions for Directed Acyclic Graphs.” Epidemiology 21 (4): 586.
Creed, Jordan, and Travis Gerke. 2018. Gerkelab/Shinydag: Initial Release.” Zenodo.
Greenland, Sander, Judea Pearl, and James M Robins. 1999. Causal Diagrams for Epidemiologic Research.” Epidemiology 10 (1): 37.
Textor, Johannes, Juliane Hardt, and Sven Knüppel. 2011. DAGitty: A Graphical Tool for Analyzing Causal Diagrams.” Epidemiology 22 (5): 745.
Textor, Johannes, Benito van der Zander, Mark S. Gilthorpe, Maciej Liśkiewicz, and George T.H. Ellison. 2017. Robust Causal Inference Using Directed Acyclic Graphs: The R Package ‘Dagitty’.” International Journal of Epidemiology, January, dyw341.

No comments yet. Why not leave one?

GitHub-flavored Markdown & a sane subset of HTML is supported.