Skip to contents

Bayesian graphical causal models in R. Specify a causal DAG, fit each node with a Gaussian process, and estimate interventional effects with full posterior uncertainty.

remotes::install_github(“causalabs/kagu-r”)

Overview

Kagu fits Bayesian graphical causal models (GCMs). You describe a system as a directed acyclic graph (DAG) of which variables cause which, and Kagu fits each node as an independent Gaussian process of its parents. Causal questions (total effects, conditional effects, dose-response curves) are answered by propagating interventions through that fitted graph, so different questions are queries against the same fitted model.

How it works

The system is represented as structural equations X_i = f_i(Pa(X_i), ε_i). Each f_i is a mechanism fitted as an independent Bayesian model, so the joint distribution factorises over nodes: P(X_1, …, X_n) = ∏ P(X_i | Pa(X_i)).

Effects are computed via the do-operator: fix the treatment node at x (severing its incoming edges), propagate forward through the DAG in topological order, and compare E[Y | do(X = x)] against E[Y | do(X = x')]. Because each node’s mechanism is a Gaussian process, non-linearities and interactions between parents are picked up automatically, without being specified in the model formula.

A worked example

library(kagu)

model <- KaguModel$new(
  dag = list(
    age = c(), sex = c(),
    sociality    = "age",
    food_sharing = "sociality",
    condition    = c("age", "sex", "sociality", "food_sharing")
  )
)
model$fit(data)

# Extract causal effect distributions
model$effects("sociality", "condition")$summary()

Learn more