Learn R Programming

caugi

Causal Graph Interface (for R) — a fast and flexible toolbox for building, coercing and analyzing causal graphs.

What is caugi?

caugi (pronounced “corgi”) stands for Causal Graph Interface. It is a causality-first graph package that focuses on performance and flexibility. If you are developing scripts or algorithms in the field of causality or if you are learning about causal graphs for the first time, caugi is made for you.

Installation

You can install the development version of caugi from GitHub with:

pak::pak("frederikfabriciusbjerre/caugi")

or directly from CRAN with:

install.packages("caugi")

Installing Rust

Rust is required for caugi to work. If you don’t have Rust installed, visit rustup.rs for installation instructions appropriate for your platform.

Alternatively, you may install Rust from your OS package manager.

The basic object: caugi

A caugi graph object is the bread and butter of the caugi package. It is easy to create, query, and modify.

library(caugi)

You can create simple graphs as well as a number of predefined graph classes. Currently, we support "UNKNOWN", "DAG", "PDAG", "ADMG", and "UG". We plan on supporting several other causal graph types in future releases, such as "PAG", "MAG", and "SWIG".

# a tiny DAG
cg <- caugi(
  A %-->% B + C,
  B %-->% D,
  C %-->% D,
  class = "DAG"
)

plot(cg)

Edge operators

The available edges in caugi are listed below:

  • %-->% (directed)
  • %---% (undirected)
  • %<->% (bidirected)
  • %o->% (partially directed)
  • %o--% (partially undirected)
  • %o-o% (partial)

You can register more types with register_caugi_edge(), if you find that you need a more expressive set of edges. For example, if you want to represent a directed edge in the reverse direction, you can do so like this:

register_caugi_edge(
  glyph = "<--",
  tail_mark = "arrow",
  head_mark = "tail",
  class = "directed",
  symmetric = FALSE
)

caugi(A %-->% B, B %<--% C, class = "DAG")
#> <caugi object; 3 nodes, 2 edges; simple: TRUE; session=0x000001a2318f5e90>
#>   graph_class: DAG
#>   nodes: A, B, C
#>   edges: A-->B, B<--C

# reset the registry to default with original edges
reset_caugi_registry()

We expect this feature to be needing further polishing in future releases, and we would love your input if you use this feature!

Querying and metrics

caugi provides a number of functions to query and analyze caugi objects. Some of the available functions are:

  • Relational queries, such as parents(), ancestors(), neighbors(), and more.
  • Structural queries, such as is_acyclic(), is_cpdag(), and more.
  • Graph manipulations, such as add_edges(), remove_nodes(), and more.
  • Graph metrics, such as shd() and aid().

How it works

caugi graphs are represented in a compact Compressed Sparse Row (CSR) format in Rust. caugi works with a front-loading philosophy. Since the caugi graph is stored in a CSR format, mutations of the graph is computationally expensive compared to other graph storage systems, but it allows for very fast querying. Additionally to the storage format of the graph itself, caugi also stores additional information about node relations in such a way that it allows for faster queries without blowing up the object too much.

To accommodate for the cost of mutations, caugi graphs are built lazily, but you can force a build by using the function build().

Why?

It’s fast, dawg

Copy Link

Version

Install

install.packages('caugi')

Monthly Downloads

3,426

Version

1.1.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Frederik Fabricius-Bjerre

Last Published

March 20th, 2026

Functions in caugi (1.1.0)

as_bnlearn

Convert a caugi to a bnlearn network
as_adjacency

Convert a caugi to an adjacency matrix
anteriors

Get anteriors of nodes in a caugi
add-caugi_plot-caugi_plot

Compose Plots Horizontally
aid

Adjustment Identification Distance
all_adjustment_sets_admg

Get all valid adjustment sets in an ADMG
all_backdoor_sets

Get all backdoor sets up to a certain size.
caugi-package

caugi (Causal Graph Interface)
caugi_default_options

Default options for caugi
as_igraph

Convert a caugi to an igraph object
as_dagitty

Convert a caugi to a dagitty graph
as_caugi

Convert to a caugi
build

Build the caugi graph
caugi_deserialize

Deserialize caugi Graph from JSON String
caugi_dot

S7 Class for DOT Export
caugi

Create a caugi from edge expressions.
caugi_export

S7 Base Class for Caugi Exports
caugi_layout

Compute Graph Layout
caugi_graphml

S7 Class for GraphML Export
caugi_layout_bipartite

Bipartite Graph Layout
caugi_layout_tiered

Tiered Graph Layout
caugi_layout_fruchterman_reingold

Fruchterman-Reingold Force-Directed Layout
caugi_layout_kamada_kawai

Kamada-Kawai Stress Minimization Layout
caugi_mermaid

S7 Class for Mermaid Export
caugi_layout_sugiyama

Sugiyama Hierarchical Layout
caugi_plot

S7 Class for caugi Plot
caugi_options

Get or set global options for caugi
dag_from_pdag

Extend a PDAG to a DAG using the Dor-Tarsi Algorithm
caugi_serialize

Serialize caugi Graph to JSON String
compare_proxy.caugi::caugi

Proxy for waldo comparison of caugi objects
condition_marginalize

Marginalize and/or condition on variables in an ancestral graph (AG)
descendants

Get descendants of nodes in a caugi
d_separated

Are X and Y d-separated given Z?
caugi_verbs

Manipulate nodes and edges of a caugi
districts

Get districts (c-components) of an ADMG or AG
divide-caugi_plot-caugi_plot

Compose Plots Vertically
children

Get children of nodes in a caugi
.contains_edge

Does the expression contain an edge call?
.edge_spec

Edge specification infix operators
.caugi_fit_on_line

Fit items on a line
.edge_ops_get

Get edge operators
.combine_plus

Combine terms with '+'
.build_edges_from_session

Build edges data.table from session
.edge_constructor_idx

Edge constructor using indices.
.edge_type_from_anteriors

Infer edge type from anterior relationships
.collect_edges_nodes

Collect edges and nodes
.edge_constructor

Edge constructor
.glyph_of

Get glyph for an operator
.getter_output

Output object of getter queries
.get_nodes

Get nodes data.table from verb call.
.is_edge_call

Is it an edge call / expression?
.get_edges

Build edges data.table from verb call.
.expand_targets

Helper to expand the right-hand side of an edge specification
.flatten_edge_chain

Flatten a chained edge expression
.set_names

Set names to an object
.expand_nodes

Expand node expressions
.parse_edge_arg

Parse one caugi(...) argument
.glyph_map_get

Get edge operators
.resolve_idx0_get

Resolve node name or index to 0-based index.
.edge_units_to_dt

Turn edge units into a data.table of edges
.session_to_caugi

Convert a graph session to a caugi S7 object
.is_node_expr

Is it a node expr?
.nodes_to_indices

Convert node names to 0-based indices
.register_edge

Register a new edge operator
.not_m_separated_for_all_subsets

Check if nodes are NOT m-separated for all conditioning subsets
.node_constructor

Node constructor
edge_operators

Infix operators for edge specifications
.segment_units

Create an edge unit from lhs, op, rhs
exogenize

Exogenize a graph
.update_caugi

Update nodes and edges of a caugi
.sync_session_inplace

Update an existing session in place
export-classes

Export Format Classes
edges

Get edges of a caugi.
edge_types

Get the edge types of a caugi.
exogenous

Get all exogenous nodes in a caugi
format-caugi

Caugi Native Format Serialization
.split_plus

Expand target expressions with =
.validate_nodes_and_index

Validate nodes or index argument
is_ag

Is the caugi graph an AG?
format-mermaid

Mermaid Format Export
is_acyclic

Is the caugi acyclic?
format-dot

DOT Format Export and Import
is_admg

Is the caugi graph an ADMG?
generate_graph

Generate a caugi using Erdős-Rényi.
hd

Hamming Distance
format-graphml

GraphML Format Export and Import
is_caugi

Is it a caugi graph?
is_mpdag

Is the caugi graph an MPDAG?
is_edge_symmetric

Is the edge symmetric?
is_dag

Is the caugi graph a DAG?
is_ug

Is the caugi graph an UG?
is_mag

Is the caugi graph a MAG?
is_cpdag

Is the caugi graph a CPDAG?
is_simple

Is the caugi graph simple?
is_pdag

Is the caugi graph a PDAG?
is_empty_caugi

Is the caugi graph empty?
is_valid_adjustment_admg

Is a set a valid adjustment set in an ADMG?
is_valid_backdoor

Is a backdoor set valid?
minimal_d_separator

Compute a minimal d-separator
knit_print.caugi_export

Knit Print Method for caugi_export
m_separated

M-separation test for AGs and ADMGs
makeContent.caugi_edge_grob

Make Content for Custom Edge Grob
moralize

Moralize a DAG
length

Length of a caugi
latent_project

Project latent variables from a DAG to an ADMG
meek_closure

Apply Meek closure to a PDAG
markov_blanket

Get Markov blanket of nodes in a caugi
read_caugi

Read caugi Graph from File
plot

Create a caugi Graph Plot Object
nodes

Get nodes or edges of a caugi
read_graphml

Read GraphML File to caugi Graph
parents

Get parents of nodes in a caugi
posteriors

Get posteriors of nodes in a caugi
mutate_caugi

Mutate caugi class
neighbors

Get neighbors of nodes in a caugi
normalize_latent_structure

Normalize latent structure in a DAG
print

Print a caugi
registry

caugi edge registry
register_caugi_edge

Register a new edge type in the global registry.
skeleton

Get the skeleton of a graph
simulate_data

Simulate data from a caugi DAG.
to_graphml

Export caugi Graph to GraphML Format
to_dot

Export caugi Graph to DOT Format
same_nodes

Same nodes?
subgraph

Get the induced subgraph
topological_sort

Get a topological ordering of a DAG
spouses

Get spouses (bidirected neighbors) of nodes in an ADMG
write_dot

Write caugi Graph to DOT File
shd

Structural Hamming Distance
write_caugi

Write caugi Graph to File
to_mermaid

Export caugi Graph to Mermaid Format
write_graphml

Write caugi Graph to GraphML File
write_mermaid

Write caugi Graph to Mermaid File
adjustment_set

Compute an adjustment set
all.equal.caugi::caugi

Compare caugi objects for equality
ancestors

Get ancestors of nodes in a caugi