Skip to content

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.

Get started View an example report

A layered network learned from the simulated example

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.

Ordering variables →

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.

Checking and running →

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.

Reading the results →

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.

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.

    Start here

  • Analysing your own data

    The six steps from a data file to a report.

    Your own study

  • Interpreting results

    What each figure and table shows, and its limitations.

    Reading the results

  • Reference

    All columns, settings, commands and functions.

    Reference

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.