Layered Bayesian networks for cohort studies¶
layerbn learns a Bayesian network from cohort data within an order that you specify. You assign each variable to a layer, and arcs are only allowed from earlier layers to the same or later layers. layerbn reports which arcs the data support, how stable each arc is under resampling, and how much each variable is associated with the outcome. The study is described in a spreadsheet; no programming is required.

Why layers
With layers¶
Variables are grouped in ordered layers, for example background, exposures, baseline measures and outcome. An arc can only point to the same layer or a later one. The assumptions are fixed before the analysis and can be reported in the methods section.
Without layers¶
Unconstrained structure learning estimates the direction of each arc from the data. It can produce an arc from an outcome at follow-up to age at baseline. Such a direction is an artefact of the algorithm and is not interpretable.
Workflow
Each analysis consists of three steps.
Define the order¶
List the variables in variables.xlsx and assign each to a layer. The workbook uses dropdown lists to prevent typing errors.
Learn the network¶
layerbn run learns the network within the order and repeats the analysis on bootstrap
resamples to estimate the stability of each arc.
Review the results¶
report.html contains all figures and tables, a description of how to read each, a draft
methods paragraph and an interactive explorer.
Output
Figures are saved as PNG and as PDF with editable text, and tables as CSV and Excel. The report combines them in a single HTML file.
-

Network. One row per layer, from top to bottom. Each variable shows its distribution, and each arc is labelled with its stability. Details →
-

Arc stability. The percentage of bootstrap resamples in which each arc is learned. Details →
-

Information about a target. The mutual information of each variable with the outcome, and the paths that connect them. Details →
-

Profiles. The probability of the outcome in groups that you define, with bootstrap intervals. Details →
-

Sweep. The probability of the outcome across the range of one variable. Details →
-

Design. The layers and variables, drawn before any model is fitted. Details →
Try the example¶
python -m pip install "https://github.com/umcu/layerbn/archive/refs/heads/main.zip"
layerbn init my-study # creates a project folder with simulated data
cd my-study
layerbn run --fast # takes about 20 seconds
Open results/report.html in a browser. If you have not used a terminal before, see
Start here for step-by-step instructions for Windows and macOS.
Documentation
-
Getting started
Install layerbn and run the example study.
-
Analysing your own data
The six steps from a data file to a report.
-
Interpreting results
What each figure and table shows, and its limitations.
-
Reference
All columns, settings, commands and functions.
Interpretation
The network shows associations that the data support, arranged in the assumed order. It does not estimate causal effects. See Interpreting the network.
Developed by the Vascular Cognitive Impairment research group at UMC Utrecht. Networks are fitted with pyAgrum. Released under the MIT licence. How to cite.