Learn R Programming

gadjid (version 0.1.0)

shd: Structural Hamming Distance between two DAG / CPDAG adjacency matrices

Description

Computes the structural Hamming distance between the true g_true PDAG and an estimated g_guess PDAG.

Usage

shd(g_true, g_guess)

Value

2-element vector of type double
c(normalized error in [0,1], total number of errors)

Arguments

g_true

Adjacency matrix of the true partially directed acyclic graph

g_guess

Adjacency matrix of the guess partially directed acyclic graph

Details

For details see Henckel, Würtzen, Weichwald (2024) tools:::Rd_expr_doi("doi:10.48550/arXiv.2402.08616")
The source code is available at github.com/CausalDisco/gadjid

Graph inputs are accepted as adjacency matrices of type double. An adjacency matrix for a PDAG may only contain 0s, 1s and 2s. PDAG are validated for acyclicity.

A 1 in row r and column c codes a directed edge and a 1 in row c and column r codes a directed edge in reverse direction; a 2 in row r and column c codes an undirected edge ‘r – c’ (an additional 2 in row c and column r is ignored; one of the two entries is sufficient to code an undirected edge).

Examples

Run this code
full <- rbind(c(0, 1, 1, 1),
              c(0, 0, 1, 1),
              c(0, 0, 0, 1),
              c(0, 0, 0, 0))
chain <- rbind(c(0, 1, 0, 0),
               c(0, 0, 1, 0),
               c(0, 0, 0, 1),
               c(0, 0, 0, 0))
identical(shd(full, chain), c(3/6, 3))

Run the code above in your browser using DataLab