Movatterモバイル変換


[0]ホーム

URL:


Title:Causal Graph Interface
Version:0.3.1
Description:Create, query, and modify causal graphs. 'caugi' (Causal Graph Interface) is a causality-first, high performance graph package that provides a simple interface to build, structure, and examine causal relationships.
License:MIT + file LICENSE
URL:https://frederikfabriciusbjerre.github.io/caugi/
BugReports:https://github.com/frederikfabriciusbjerre/caugi/issues
Depends:R (≥ 4.2)
Imports:data.table, fastmap, S7, stats, methods
Suggests:bnlearn, dagitty, devtools, ggm, graph, gRbase, igraph,knitr, MASS, Matrix, rextendr, rmarkdown, testthat
VignetteBuilder:knitr
Config/rextendr/version:0.4.2
Encoding:UTF-8
RoxygenNote:7.3.3
SystemRequirements:Cargo (Rust's package manager), rustc >= 1.80.0, xz
Config/Needs/website:rmarkdown
NeedsCompilation:yes
Packaged:2025-11-28 21:17:22 UTC; fabben
Author:Frederik Fabricius-Bjerre [aut, cre, cph], Johan LarssonORCID iD [aut], Michael SachsORCID iD [aut]
Maintainer:Frederik Fabricius-Bjerre <frederik@fabriciusbjerre.dk>
Repository:CRAN
Date/Publication:2025-12-04 12:00:02 UTC

caugi (Causal Graph Interface)

Description

Create, query, and modify causal graphs. 'caugi' (Causal Graph Interface) isa causality-first, high performance graph package that provides a simpleinterface to build, structure, and examine causal relationships.

Author(s)

Maintainer: Frederik Fabricius-Bjerrefrederik@fabriciusbjerre.dk [copyright holder]

Authors:

See Also

Useful links:


Fit items on a line

Description

Helper function to determine how many items can fit on a lineof given width, considering an indent.

Usage

.caugi_fit_on_line(items, width, indent)

Arguments

items

A character vector of item labels.

width

An integer specifying the total line width.

indent

An integer specifying the indent width.

Value

An integer indicating how many items fit on the line.


Create the state environment for acaugi (internal)

Description

Internal function to create the state environment for acaugi. This function is not intended to be used directly by users.

Usage

.cg_state(  nodes,  edges,  ptr,  built,  simple,  class,  name_index_map,  index_name_map)

Arguments

nodes

Adata.table of nodes with aname column.

edges

Adata.table of edges withfrom,edge, andto columns.

ptr

A pointer to the underlying Rust graph structure(orNULL if not built).

built

Logical; whether the graph has been built.

simple

Logical; whether the graph is simple(no parallel edges or self-loops).

class

Character; one of"UNKNOWN","DAG", or"PDAG".

name_index_map

Afastmap mapping node names to their zero indexedindices.

Value

An environment containing the graph state.


Collect edges and nodes

Description

Collect edges (via .parse_edge_arg) and explicitly declarednodes (no edges).

Usage

.collect_edges_nodes(calls)

Arguments

calls

A list of expressions from caugi(...)

Value

A list with two elements:


Combine terms with '+'

Description

Combine a list of terms into a single left-associative '+' call.

Usage

.combine_plus(terms)

Arguments

terms

A list of expressions to combine.

Value

A single expression combining the terms with '+'.


Does the expression contain an edge call?

Description

Recursively check if the expression contains any edge call.

Usage

.contains_edge(expr)

Arguments

expr

An expression to check

Value

TRUE if the expression contains an edge call, FALSE otherwise


Edge constructor

Description

Internal function to construct edges forcaugi objects.

Usage

.edge_constructor(from = character(), edge = character(), to = character())

Arguments

from

Character vector of source node names.

edge

Character vector of edge glyphs.

to

Character vector of target node names.

Value

Adata.table object with columnsfrom,edge, andto.


Edge constructor using indices.

Description

Internal function to construct edges forcaugi objects using indices.

Usage

.edge_constructor_idx(from_idx, edge, to_idx, node_names)

Arguments

from_idx

Integer vector of source node indices.

edge

Character vector of edge glyphs.

to_idx

Integer vector of target node indices.

node_names

Character vector of node names.

Value

Adata.table object with columnsfrom,edge, andto.


Get edge operators

Description

This function gets the default caugi edge operators

Usage

.edge_ops_get()

Value

The current edge operators of the caugi environment


Edge specification infix operators

Description

These infix operators are used to specify edges incaugi(). This function helps build infix operators.

Usage

.edge_spec(from_sym, to_expr, glyph)

Arguments

from_sym

A symbol representing the source node.

to_expr

An expression representing the target node(s).Can be a symbol, string, number,c(...), or a combination using+.

glyph

A string representing the edge glyph (e.g.,"-->","<->").

Value

Adata.table with columnsfrom,to, andedge.


Turn edge units into adata.table of edges

Description

Convert a list of edge units into adata.table with columnsfrom,edge, andto.

Usage

.edge_units_to_dt(units)

Arguments

units

A list of edge units, each withlhs,rhs, andglyph.

Value

Adata.table with columnsfrom,edge, andto.


Expand node expressions

Description

Expand node expressions: symbol, "B", c(...), +, (...)

Usage

.expand_nodes(expr, env = parent.frame())

Arguments

expr

An expression representing nodes.

Value

A character vector of node names.


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

Description

This function expands the right-hand side of an edgespecification into a character vector of target node names. It handlesvarious forms of input, including symbols, calls with+, calls withc(),and character literals.

Usage

.expand_targets(expr)

Arguments

expr

An expression representing the target node(s).

Value

A character vector of target node names.


Flatten a chained edge expression

Description

Given a chained edge expression,flatten it into its terms and operators.

Usage

.flatten_edge_chain(call_expr)

Arguments

call_expr

A call expression representing a chained edge.

Value

A list with two elements,terms andops.


Build edgesdata.table from verb call.

Description

Internal helper to build edgesdata.table from verb call.

Usage

.get_edges(from, edge, to, calls)

Arguments

from

Character vector of source node names.

edge

Character vector of edge types.

to

Character vector of target node names.

calls

List of calls from....

Value

Adata.table with columnsfrom,edge, andto.


Get nodesdata.table from verb call.

Description

Internal helper to build nodesdata.table from verb call.

Usage

.get_nodes(name, calls)

Arguments

name

Character vector of node names.

calls

List of calls from....

Value

Adata.table with columnname for node names.


Output object of getter queries

Description

Helper to format the output of getter queries.

Usage

.getter_output(cg, idx0, nodes)

Arguments

cg

Acaugi object.

idx0

A vector of zero-based node indices.

nodes

A vector of node names.

Value

A list of character vectors, each a set of node names.If only one node is requested, returns a character vector.


Get edge operators

Description

This function gets the default caugi edge glyphs

Usage

.glyph_map_get()

Value

The current edge glyphs of the caugi environment


Get glyph for an operator

Description

Get the glyph string for a given edge operator symbol.

Usage

.glyph_of(op_sym)

Arguments

op_sym

A symbol representing the edge operator (e.g.,⁠%-->%⁠).

Value

A string representing the edge glyph (e.g.,"-->").


Is it an edge call / expression?

Description

This function checks if the expression is an edge call

Usage

.is_edge_call(expr)

Arguments

expr

An expression to check

Value

TRUE if the expression is an edge call, FALSE otherwise


Is it a node expr?

Description

Check if the expression is a valid node expression:symbol, string, number, c(...), +, (...)

Usage

.is_node_expr(expr)

Arguments

expr

An expression to check

Value

TRUE if the expression is a valid node expression, FALSE otherwise


Mark acaugi asnot built.

Description

When acaugi is modified, it should be marked as notbuilt. This function sets thebuilt attribute toFALSE. Thereby, the Rustbackend and the R frontend does not match, and at one point, thecaugi will need to be rebuild for it to be queried.

Usage

.mark_not_built(cg)

Arguments

cg

Acaugi object.

Value

The samecaugi object, but with thebuilt attribute set toFALSE.


Node constructor

Description

A simple wrapper creating adata.table object with a single columnname.

Usage

.node_constructor(names = character(), sort = FALSE)

Arguments

names

Character vector of node names.

sort

Logical indicating whether to sort the node names.

Details

The reason this exists is so if changes should be made in the future, it iseasy to simply change this constructor, rather than changing the calls todata.table all over the place.

Value

Adata.table object with a single columnname.


Parse one caugi(...) argument

Description

Parse one caugi(...) argument into edge units

Usage

.parse_edge_arg(expr)

Arguments

expr

An expression representing an edge with nodes

Value

A list of edge units, each with lhs, rhs, and glyph.


Register a new edge operator

Description

Register a new edge operator for use incaugi().

Usage

.register_edge(glyph)

Arguments

glyph

A string representing the edge glyph (e.g.,"-->","<->").

Value

The operator name (e.g.,"%-->%"), invisibly.


Resolve node name or index to 0-based index.

Description

Internal helper function to resolve either a node name or anode index to a 0-based index..resolve_idx0_get usesget on thefastmap and expects a single value,while.resolve_idx0_mget usesmget and can return multiple values.

Usage

.resolve_idx0_get(nm_idx_map, node_name = NULL, node_index = NULL).resolve_idx0_mget(nm_idx_map, node_name = NULL, node_index = NULL)

Arguments

nm_idx_map

Afastmap mapping node names to 0-based indices fromacaugi.

node_name

Optional character vector of node names.

node_index

Optional numeric vector of 1-based node indices.

See Also

fastmap::fastmap


Create an edge unit from lhs, op, rhs

Description

Create an edge unit from lhs, op, rhs expressions.

Usage

.segment_units(lhs_term, op_chr, rhs_term)

Arguments

lhs_term

An expression for the left-hand side nodes.

op_chr

A string representing the edge operator glyph.

rhs_term

An expression for the right-hand side nodes.

Value

A list with elementslhs,rhs, andglyph.


Set names to an object

Description

Only made to avoid usingstats::setNames.

Usage

.set_names(object = nm, nm)

Arguments

object

An R object to which names are to be assigned.

nm

A character vector of names to assign to the object.

Value

The input object with the assigned names.


Expand target expressions with=

Description

Split any expression into top-level '+' terms (fully flattened).

Usage

.split_plus(expr)

Arguments

expr

An expression representing nodes.

Value

A character vector of node names.


Update nodes and edges of acaugi

Description

Internal helper to add or remove nodes/edges and mark graph asnot built.

Usage

.update_caugi(  cg,  nodes = NULL,  edges = NULL,  action = c("add", "remove"),  inplace = FALSE)

Arguments

cg

Acaugi object.

nodes

Adata.frame with columnname for node names to add/remove.

edges

Adata.frame with columnsfrom,edge,to for edges toadd/remove.

action

One of"add" or"remove".

inplace

Logical, whether to modify the graph inplace or not.

Value

The updatedcaugi object.


Convert a graph pointer to acaugi S7 object

Description

Convert a graph pointer from Rust to acaugi to aS7 object.

Usage

.view_to_caugi(ptr, node_names = NULL)

Arguments

ptr

A pointer to the underlying Rust graph structure.

node_names

Optional character vector of node names. IfNULL(default), nodes will be namedV1,V2, ...,Vn.

Value

Acaugi object representing the graph.


Compute an adjustment set

Description

Computes an adjustment set forX -> Y in a DAG.

Usage

adjustment_set(  cg,  X = NULL,  Y = NULL,  X_index = NULL,  Y_index = NULL,  type = c("optimal", "parents", "backdoor"))

Arguments

cg

Acaugi object.

X,Y

Node names.

X_index,Y_index

Optional numeric 1-based indices.

type

One of"parents","backdoor","optimal".Theoptimal option computes the O-set.

Details

Types supported:

Value

A character vector of node names representing the adjustment set.

See Also

Other adjustment:all_backdoor_sets(),d_separated(),is_valid_backdoor()

Examples

cg <- caugi(  C %-->% X,  X %-->% F,  X %-->% D,  A %-->% X,  A %-->% K,  K %-->% Y,  D %-->% Y,  D %-->% G,  Y %-->% H,  class = "DAG")adjustment_set(cg, "X", "Y", type = "parents") # C, Aadjustment_set(cg, "X", "Y", type = "backdoor") # C, Aadjustment_set(cg, "X", "Y", type = "optimal") # K

Adjustment Identification Distance

Description

Compute the Adjustment Identification Distance (AID) between twographs using thegadjid Rust package.

Usage

aid(truth, guess, type = c("oset", "ancestor", "parent"), normalized = TRUE)

Arguments

truth

Acaugi object.

guess

Acaugi object.

type

A character string specifying the type of AID to compute.Options are"oset" (default),"ancestor", and"parent".

normalized

Logical; ifTRUE, returns the normalized AID. IfFALSE,returns the count.

Value

A numeric representing the AID between the two graphs, ifnormalized = TRUE, or an integer count ifnormalized = FALSE.

See Also

Other metrics:hd(),shd()

Examples

set.seed(1)truth <- generate_graph(n = 100, m = 200, class = "DAG")guess <- generate_graph(n = 100, m = 200, class = "DAG")aid(truth, guess) # 0.0187

Get all backdoor sets up to a certain size.

Description

This function returns the backdoor sets up to sizemax_size,which per default is set to 10.

Usage

all_backdoor_sets(  cg,  X = NULL,  Y = NULL,  X_index = NULL,  Y_index = NULL,  minimal = TRUE,  max_size = 3L)

Arguments

cg

Acaugi.

X,Y

Single node name.

X_index,Y_index

Optional 1-based indices (exclusive with name args).

minimal

Logical; ifTRUE (default), only minimal sets are returned.

max_size

Integer; maximum size of sets to consider (default 3).

Value

A list of character vectors, each an adjustment set(possibly empty).

See Also

Other adjustment:adjustment_set(),d_separated(),is_valid_backdoor()

Examples

cg <- caugi(  C %-->% X,  X %-->% F,  X %-->% D,  A %-->% X,  A %-->% K,  K %-->% Y,  D %-->% Y,  D %-->% G,  Y %-->% H,  class = "DAG")all_backdoor_sets(cg, X = "X", Y = "Y", max_size = 3L, minimal = FALSE)#> [[1]]#> [1] "A"#>#> [[2]]#> [1] "K"#>#> [[3]]#> [1] "C" "A"#>#> [[4]]#> [1] "C" "K"#>#> [[5]]#> [1] "A" "K"#>#> [[6]]#> [1] "C" "A" "K"all_backdoor_sets(cg, X = "X", Y = "Y", max_size = 3L, minimal = TRUE)#> [[1]]#> [1] "A"#>#> [[2]]#> [1] "K"

Get ancestors of nodes in acaugi

Description

Get ancestors of nodes in acaugi

Usage

ancestors(cg, nodes = NULL, index = NULL)

Arguments

cg

Acaugi object.

nodes

A vector of node names, a vector of unquotednode names, or an expression combining these with+ andc().

index

A vector of node indexes.

Value

Either a character vector of node names (if a single node isrequested) or a list of character vectors (if multiple nodes are requested).

See Also

Other queries:children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")ancestors(cg, "A") # NULLancestors(cg, index = 2) # "A"ancestors(cg, "B") # "A"ancestors(cg, c("B", "C"))#> $B#> [1] "A"#>#> $C#> [1] "A" "B"

Convert a caugi to an adjacency matrix

Description

Does not take other edge types than the one found in a PDAG.

Usage

as_adjacency(x)

Arguments

x

Acaugi object.

Value

An integer 0/1 adjacency matrix with row/col names.

See Also

Other conversions:as_bnlearn(),as_caugi(),as_dagitty(),as_igraph()

Examples

cg <- caugi(  A %-->% B,  class = "DAG")adj <- as_adjacency(cg)

Convert a caugi to a bnlearn network

Description

Convert a caugi to a bnlearn network

Usage

as_bnlearn(x)

Arguments

x

Acaugi object.

Value

Abnlearn DAG.

See Also

Other conversions:as_adjacency(),as_caugi(),as_dagitty(),as_igraph()

Examples

cg <- caugi(  A %-->% B,  class = "DAG")g_bn <- as_bnlearn(cg)

Convert to acaugi

Description

Convert an object to acaugi. The object can be agraphNEL,matrix,tidygraph,daggity,bn, origraph.

Usage

as_caugi(  x,  class = c("DAG", "PDAG", "PAG", "UNKNOWN"),  simple = TRUE,  build = TRUE,  collapse = FALSE,  collapse_to = "---",  ...)

Arguments

x

An object to convert to acaugi.

class

"DAG", "PDAG", "PAG", or "UNKNOWN"."PAG" is only supported for integer coded matrices.

simple

logical. IfTRUE (default) the graph will be simple(no multiple edges or self-loops).

build

logical. IfTRUE (default) build the graph now, otherwisebuild lazily on first query or when usingbuild().

collapse

logical. IfTRUE collapse mutual directed edges toundirected edges. Default isFALSE.

collapse_to

Character string to use as the edge glyph when collapsing.Should be a registered symmetrical edge glyph. Default is"---".

...

Additional arguments passed to specific methods.

Details

For matrices,as_caugi assumes that the rows are thefrom nodesand the columns are theto nodes. Thus, for a graph, G: A –> B, we wouldhave thatG["A", "B"] == 1 andG["B", "A"] == 0.For PAGs, the integer codes are as follows (as used inpcalg):

Value

Acaugi object.

See Also

Other conversions:as_adjacency(),as_bnlearn(),as_dagitty(),as_igraph()

Examples

# igraphig <- igraph::graph_from_literal(A - +B, B - +C)cg_ig <- as_caugi(ig, class = "DAG")# graphNELgn <- graph::graphNEL(nodes = c("A", "B", "C"), edgemode = "directed")gn <- graph::addEdge("A", "B", gn)gn <- graph::addEdge("B", "C", gn)cg_gn <- as_caugi(gn, class = "DAG")# adjacency matrixm <- matrix(0L, 3, 3, dimnames = list(LETTERS[1:3], LETTERS[1:3]))m["A", "B"] <- 1Lm["B", "C"] <- 1Lcg_adj <- as_caugi(m, class = "DAG")# bnlearnbn <- bnlearn::model2network("[A][B|A][C|B]")cg_bn <- as_caugi(bn, class = "DAG")# dagittydg <- dagitty::dagitty("dag { A -> B B -> C }")cg_dg <- as_caugi(dg, class = "DAG")cg <- caugi(A %-->% B %-->% C, class = "DAG")# check that all nodes are equal in all graph objectsfor (cg_converted in list(cg_ig, cg_gn, cg_adj, cg_bn, cg_dg)) {  stopifnot(identical(nodes(cg), nodes(cg_converted)))  stopifnot(identical(edges(cg), edges(cg_converted)))}# collapse mutual edgesig2 <- igraph::graph_from_literal(A - +B, B - +A, C - +D)cg2 <- as_caugi(ig2, class = "PDAG", collapse = TRUE, collapse_to = "---")# coded integer matrix for PAGs (pcalg style)nm <- c("A", "B", "C", "D")M <- matrix(0L, 4, 4, dimnames = list(nm, nm))# A --> BM["A", "B"] <- 2L # mark at B endM["B", "A"] <- 3L # mark at A end# A --- CM["A", "C"] <- 3LM["C", "A"] <- 3L# B o-> CM["B", "C"] <- 2LM["C", "B"] <- 1L# C o-o DM["C", "D"] <- 1LM["D", "C"] <- 1Lcg <- as_caugi(M, class = "PAG")

Convert a caugi to a dagitty graph

Description

Convert a caugi to a dagitty graph

Usage

as_dagitty(x)

Arguments

x

Acaugi object.

Value

Adagitty object.

See Also

Other conversions:as_adjacency(),as_bnlearn(),as_caugi(),as_igraph()

Examples

cg <- caugi(  A %-->% B,  class = "DAG")g_dg <- as_dagitty(cg)

Convert a caugi to an igraph object

Description

Convert a caugi to an igraph object

Usage

as_igraph(x, ...)

Arguments

x

Acaugi object.

...

Additional arguments passed toigraph::graph_from_data_frame().

Value

Anigraph object representing the same graph structure.

See Also

Other conversions:as_adjacency(),as_bnlearn(),as_caugi(),as_dagitty()

Examples

cg <- caugi(  A %-->% B,  class = "DAG")ig <- as_igraph(cg)

Build the graph now

Description

If acaugi has been modified (nodes or edges added orremoved), it is marked asnot built, i.ecg@built = FALSE.This function builds the graph using the Rust backend and updates theinternal pointer to the graph. If the graph is already built, it is returned.

Usage

build(cg, ...)

Arguments

cg

Acaugi object.

...

Not used.

Value

The builtcaugi object.

See Also

Other verbs:caugi_verbs

Examples

# initialize empty graph and build slowlycg <- caugi(class = "PDAG")cg <- cg |>  add_nodes(c("A", "B", "C", "D", "E")) |> # A, B, C, D, E  add_edges(A %-->% B %-->% C) |> # A --> B --> C, D, E  set_edges(B %---% C) # A --> B --- C, D, Ecg <- remove_edges(cg, B %---% C) |> # A --> B, C, D, E  remove_nodes(c("C", "D", "E")) # A --> B# verbs do not build the Rust backendcg@built # FALSEbuild(cg)cg@built # TRUE

Create acaugi from edge expressions.

Description

Create acaugi from a series of edge expressions usinginfix operators. Nodes can be specified as symbols, strings, or numbers.

The following edge operators are supported by default:

You can register additional edge types usingregister_caugi_edge().

Usage

caugi(  ...,  from = NULL,  edge = NULL,  to = NULL,  nodes = NULL,  edges_df = NULL,  simple = TRUE,  build = TRUE,  class = c("UNKNOWN", "DAG", "PDAG", "UG"),  state = NULL)

Arguments

...

Edge expressions using the supported infix operators, ornodes given by symbols or strings. Multiple edges can becombined using+:⁠A --> B + C⁠, indicating an edge fromA to bothBandC. Nodes can also be grouped usingc(...) or parentheses.

from

Character vector of source node names.Optional; mutually exclusive with....

edge

Character vector of edge types.Optional; mutually exclusive with....

to

Character vector of target node names.Optional; mutually exclusive with....

nodes

Character vector of node names to declare as isolated nodes.An optional, but recommended, option is to provide all node names in thegraph, including those that appear in edges. Ifnodes is provided, theorder of nodes in the graph will follow the order innodes.

edges_df

Optional data.frame or data.table with columnsfrom,edge, andto to specify edges. Mutually exclusive with...andfrom,edge,to. Can be used to create graphs usingedges(cg)from anothercaugi object,cg.

simple

Logical; ifTRUE (default), the graph is a simple graph, andthe function will throw an error if the input contains parallel edges orself-loops.

build

Logical; ifTRUE (default), the graph will be built using theRust backend. IfFALSE, the graph will not be built, and the Rust backendcannot be used. The graph will build, when queries are made to the graph orif callingbuild().Note: Even ifbuild = TRUE, if no edges ornodes are provided, the graph will not be built and the pointer will beNULL.

class

Character; one of"UNKNOWN","DAG","PDAG", or"UG".

state

For internal use. Build a graph by supplying a pre-constructedstate environment.

Value

Acaugi S7 object containing the nodes, edges, and apointer to the underlying Rust graph structure.

Examples

# create a simple DAG (using NSE)cg <- caugi(  A %-->% B + C,  B %-->% D,  class = "DAG")# create a PDAG with undirected edges (using NSE)cg2 <- caugi(  A %-->% B + C,  B %---% D,  E, # no neighbors for this node  class = "PDAG")# create a DAG (using SE)cg3 <- caugi(  from = c("A", "A", "B"),  edge = c("-->", "-->", "-->"),  to = c("B", "C", "D"),  nodes = c("A", "B", "C", "D", "E"),  class = "DAG")# create a non-simple graphcg4 <- caugi(  A %-->% B,  B %-->% A,  class = "UNKNOWN",  simple = FALSE)cg4@simple # FALSEcg4@built # TRUEcg4@graph_class # "UNKNOWN"# create graph, but don't built Rust object yet, which is needed for queriescg5 <- caugi(  A %-->% B + C,  B %-->% D,  class = "DAG",  build = FALSE)cg@built # FALSE

Manipulate nodes and edges of acaugi

Description

Add, remove, or and set nodes or edges to / from acaugiobject. Edges can be specified using expressions with the infix operators.Alternatively, the edges to be added are specified using thefrom,edge, andto arguments.

Usage

add_edges(cg, ..., from = NULL, edge = NULL, to = NULL, inplace = FALSE)remove_edges(cg, ..., from = NULL, edge = NULL, to = NULL, inplace = FALSE)set_edges(cg, ..., from = NULL, edge = NULL, to = NULL, inplace = FALSE)add_nodes(cg, ..., name = NULL, inplace = FALSE)remove_nodes(cg, ..., name = NULL, inplace = FALSE)

Arguments

cg

Acaugi object.

...

Expressions specifying edges to add using the infix operators,or nodes to add using unquoted names, vectors viac(), or+ composition.

from

Character vector of source node names. Default isNULL.

edge

Character vector of edge types. Default isNULL.

to

Character vector of target node names. Default isNULL.

inplace

Logical, whether to modify the graph inplace or not.IfFALSE (default), a copy of thecaugi is made and modified.

name

Character vector of node names. Default isNULL.

Details

Caugi graph verbs

Value

The updatedcaugi.

Functions

See Also

Other verbs:build()

Examples

# initialize empty graph and build slowlycg <- caugi(class = "PDAG")cg <- cg |>  add_nodes(c("A", "B", "C", "D", "E")) |> # A, B, C, D, E  add_edges(A %-->% B %-->% C) |> # A --> B --> C, D, E  set_edges(B %---% C) # A --> B --- C, D, Ecg <- remove_edges(cg, B %---% C) |> # A --> B, C, D, E  remove_nodes(c("C", "D", "E")) # A --> B# verbs do not build the Rust backendcg@built # FALSEbuild(cg)cg@built # TRUE

Get children of nodes in acaugi

Description

Get children of nodes in acaugi

Usage

children(cg, nodes = NULL, index = NULL)

Arguments

cg

Acaugi object.

nodes

A vector of node names, a vector of unquotednode names, or an expression combining these with+ andc().

index

A vector of node indexes.

Value

Either a character vector of node names (if a single node isrequested) or a list of character vectors (if multiple nodes are requested).

See Also

Other queries:ancestors(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")children(cg, "A") # "B"children(cg, index = 2) # "C"children(cg, "B") # "C"children(cg, c("B", "C"))#> $B#> [1] "C"#>#> $C#> NULL

Are X and Y d-separated given Z?

Description

Checks whether every node inX is d-separated from every nodeinY givenZ in a DAG.

Usage

d_separated(  cg,  X = NULL,  Y = NULL,  Z = NULL,  X_index = NULL,  Y_index = NULL,  Z_index = NULL)

Arguments

cg

Acaugi object.

X,Y,Z

Node selectors: character vector of names, unquoted expression(supports+ andc()), orNULL. Use⁠*_index⁠ to pass 1-based indices.IfZ isNULL or missing, no nodes are conditioned on.

X_index,Y_index,Z_index

Optional numeric 1-based indices (exclusivewithX,Y,Z respectively).

Value

TRUE if d-separated,FALSE otherwise.

See Also

Other adjustment:adjustment_set(),all_backdoor_sets(),is_valid_backdoor()

Examples

cg <- caugi(  C %-->% X,  X %-->% F,  X %-->% D,  A %-->% X,  A %-->% K,  K %-->% Y,  D %-->% Y,  D %-->% G,  Y %-->% H,  class = "DAG")d_separated(cg, "X", "Y", Z = c("A", "D")) # TRUEd_separated(cg, "X", "Y", Z = NULL) # FALSE

Get descendants of nodes in acaugi

Description

Get descendants of nodes in acaugi

Usage

descendants(cg, nodes = NULL, index = NULL)

Arguments

cg

Acaugi object.

nodes

A vector of node names, a vector of unquotednode names, or an expression combining these with+ andc().

index

A vector of node indexes.

Value

Either a character vector of node names (if a single node isrequested) or a list of character vectors (if multiple nodes are requested).

See Also

Other queries:ancestors(),children(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")descendants(cg, "A") # "B" "C"descendants(cg, index = 2) # "C"descendants(cg, "B") # "C"descendants(cg, c("B", "C"))#> $B#> [1] "C"#>#> $C#> NULL

Infix operators for edge specifications

Description

These operators are used to specify edges incaugi().Should be used internally incaugi() calls.

Usage

lhs %-->% rhslhs %---% rhslhs %<->% rhslhs %o-o% rhslhs %--o% rhslhs %o->% rhs

Arguments

lhs

The left-hand side node expression.

rhs

The right-hand side node expression.

Value

Adata.table with columnsfrom,to, andedge.


Get the edge types of acaugi.

Description

Get the edge types of acaugi.

Usage

edge_types(cg)

Arguments

cg

Acaugi object.

Value

A character vector of edge types.

See Also

Other queries:ancestors(),children(),descendants(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %--o% C,  C %<->% D,  D %---% E,  A %o-o% E,  class = "UNKNOWN")edge_types(cg) # returns c("-->", "o-o", "--o", "<->", "---")

Get edges of acaugi.

Description

Get edges of acaugi.

Usage

edges(cg)E(cg)

Arguments

cg

Acaugi object.

Value

Adata.table with columnsfrom,edge, andto.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  D,  class = "DAG")edges(cg) # returns the data.table with columns from, edge, to

Get all exogenous nodes in acaugi

Description

Get all exogenous nodes (nodes with no parents) in acaugi.

Usage

exogenous(cg, undirected_as_parents = FALSE)

Arguments

cg

Acaugi object.

undirected_as_parents

Logical; ifTRUE, undirected edges are treatedas (possible) parents, ifFALSE (default), undirected edges are ignored.

Value

Either a character vector of node names (if a single node isrequested) or a list of character vectors (if multiple nodes are requested).

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")exogenous(cg) # "A"

Generate acaugi using Erdős-Rényi.

Description

Sample a random DAG or CPDAG usingErdős-Rényi for random graph generation.

Usage

generate_graph(n, m = NULL, p = NULL, class = c("DAG", "CPDAG"))

Arguments

n

Integer >= 0. Number of nodes in the graph.

m

Integer in⁠0, n*(n-1)/2⁠. Number of edges in the graph. Exactly oneofm orp must be supplied.

p

Numeric in⁠[0,1]⁠. Probability of edge creation. Exactly one ofm orp must be supplied.

class

"DAG" or "CPDAG".

Value

The sampledcaugi object.

Examples

# generate a random DAG with 5 nodes and 4 edgesdag <- generate_graph(n = 5, m = 4, class = "DAG")# generate a random CPDAG with 5 nodes and edge probability 0.3cpdag <- generate_graph(n = 5, p = 0.3, class = "CPDAG")

Hamming Distance

Description

Compute the Hamming Distance between two graphs.

Usage

hd(cg1, cg2, normalized = FALSE)

Arguments

cg1

Acaugi object.

cg2

Acaugi object.

normalized

Logical; ifTRUE, returns the normalized HammingDistance.

Value

An integer representing the Hamming Distance between the two graphs,ifnormalized = FALSE, or a numeric between 0 and 1 ifnormalized = TRUE.

See Also

Other metrics:aid(),shd()

Examples

cg1 <- caugi(A %-->% B %-->% C, D %-->% C, class = "DAG")cg2 <- caugi(A %-->% B %-->% C, D %---% C, class = "PDAG")hd(cg1, cg2) # 0

Is thecaugi acyclic?

Description

Checks if the givencaugi graph is acyclic.

Usage

is_acyclic(cg, force_check = FALSE)

Arguments

cg

Acaugi object.

force_check

Logical; ifTRUE, the function will test if the graph isacyclic, ifFALSE (default), it will look at the graph class and matchit, if possible.

Details

Logically, it should not be possible to have a graph class of "DAG" or "PDAG"that has cycles, but in case the user modified the graph after creation insome unforeseen way that could have introduced cycles, this function allowsto force a check of acyclicity, if needed.

Value

A logical value indicating whether the graph is acyclic.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg_acyclic <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")is_acyclic(cg_acyclic) # TRUEcg_cyclic <- caugi(  A %-->% B,  B %-->% C,  C %-->% A,  class = "UNKNOWN")is_acyclic(cg_cyclic) # FALSE

Is it acaugi graph?

Description

Checks if the given object is acaugi. Mostly usedinternally to validate inputs.

Usage

is_caugi(x, throw_error = FALSE)

Arguments

x

An object to check.

throw_error

Logical; ifTRUE, throws an error ifx is not acaugi.

Value

A logical value indicating whether the object is acaugi.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  class = "DAG")is_caugi(cg) # TRUE

Is thecaugi graph a CPDAG?

Description

Checks if the givencaugi graph is aComplete Partially Directed Acyclic Graph (CPDAG).

Usage

is_cpdag(cg)

Arguments

cg

Acaugi object.

Value

A logical value indicating whether the graph is a CPDAG.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg_cpdag <- caugi(  A %---% B,  A %-->% C,  B %-->% C,  class = "PDAG")is_cpdag(cg_cpdag) # TRUEcg_not_cpdag <- caugi(  A %---% B,  A %---% C,  B %-->% C,  class = "PDAG")is_cpdag(cg_not_cpdag) # FALSE

Is thecaugi graph a DAG?

Description

Checks if the givencaugi graph is aDirected Acyclic Graph (DAG).

Usage

is_dag(cg, force_check = FALSE)

Arguments

cg

Acaugi object.

force_check

Logical; ifTRUE, the function will test if the graph isa DAG, ifFALSE (default), it will look at the graph class and matchit, if possible.

Value

A logical value indicating whether the graph is a DAG.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg_dag_class <- caugi(  A %-->% B,  class = "DAG")is_dag(cg_dag_class) # TRUEcg_dag_but_pdag_class <- caugi(  A %-->% B,  class = "PDAG")is_dag(cg_dag_but_pdag_class) # TRUEcg_cyclic <- caugi(  A %-->% B,  B %-->% C,  C %-->% A,  class = "UNKNOWN",  simple = FALSE)is_dag(cg_cyclic) # FALSEcg_undirected <- caugi(  A %---% B,  class = "UNKNOWN")is_dag(cg_undirected) # FALSE

Is the edge symmetric?

Description

Check if the given edge glyph is symmetric in the edge registry.

Usage

is_edge_symmetric(glyph)

Arguments

glyph

A string representing the edge glyph (e.g.,"-->","<->").

Value

Logical,TRUE if the edge is symmetric, otherwise throws error.


Is thecaugi graph empty?

Description

Checks if the givencaugi graph is empty (has no nodes).

Usage

is_empty_caugi(cg)

Arguments

cg

Acaugi object.

Value

A logical value indicating whether the graph is empty.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg_empty <- caugi(class = "DAG")is_empty_caugi(cg_empty) # TRUEcg_non_empty <- caugi(  A %-->% B,  class = "DAG")is_empty_caugi(cg_non_empty) # FALSEcg_no_edges_but_has_nodes <- caugi(  A, B,  class = "DAG")is_empty_caugi(cg_no_edges_but_has_nodes) # FALSE

Is thecaugi graph a PDAG?

Description

Checks if the givencaugi graph is aPartially Directed Acyclic Graph (PDAG).

Usage

is_pdag(cg, force_check = FALSE)

Arguments

cg

Acaugi object.

force_check

Logical; ifTRUE, the function will test if the graph isa PDAG, ifFALSE (default), it will look at the graph class and matchit, if possible.

Value

A logical value indicating whether the graph is a PDAG.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg_dag_class <- caugi(  A %-->% B,  class = "DAG")is_pdag(cg_dag_class) # TRUEcg_dag_but_pdag_class <- caugi(  A %-->% B,  class = "PDAG")is_pdag(cg_dag_but_pdag_class) # TRUEcg_cyclic <- caugi(  A %-->% B,  B %-->% C,  C %-->% A,  D %---% A,  class = "UNKNOWN",  simple = FALSE)is_pdag(cg_cyclic) # FALSEcg_undirected <- caugi(  A %---% B,  class = "UNKNOWN")is_pdag(cg_undirected) # TRUEcg_pag <- caugi(  A %o->% B,  class = "UNKNOWN")is_pdag(cg_pag) # FALSE

Is thecaugi graph an UG?

Description

Checks if the givencaugi graph is an undirected graph (UG).

Usage

is_ug(cg, force_check = FALSE)

Arguments

cg

Acaugi object.

force_check

Logical; ifTRUE, the function will test if the graph isan UG, ifFALSE (default), it will look at the graph class and matchit, if possible.

Value

A logical value indicating whether the graph is an UG.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg_ug_class <- caugi(  A %---% B,  class = "UG")is_ug(cg_ug_class) # TRUEcg_not_ug <- caugi(  A %-->% B,  class = "DAG")is_ug(cg_not_ug) # FALSE

Is a backdoor set valid?

Description

Checks whetherZ is a valid backdoor adjustment set for⁠X --> Y⁠.

Usage

is_valid_backdoor(  cg,  X = NULL,  Y = NULL,  Z = NULL,  X_index = NULL,  Y_index = NULL,  Z_index = NULL)

Arguments

cg

Acaugi object.

X,Y

Single node names.

Z

Optional node set for conditioning

X_index,Y_index,Z_index

Optional 1-based indices.

Value

Logical value indicating if backdoor is valid or not.

See Also

Other adjustment:adjustment_set(),all_backdoor_sets(),d_separated()

Examples

cg <- caugi(  C %-->% X,  X %-->% F,  X %-->% D,  A %-->% X,  A %-->% K,  K %-->% Y,  D %-->% Y,  D %-->% G,  Y %-->% H,  class = "DAG")is_valid_backdoor(cg, X = "X", Y = "Y", Z = NULL) # FALSEis_valid_backdoor(cg, X = "X", Y = "Y", Z = "K") # TRUEis_valid_backdoor(cg, X = "X", Y = "Y", Z = c("A", "C")) # TRUE

Length of acaugi

Description

Returns the number of nodes in the graph.

Arguments

x

Acaugi object.

Value

An integer representing the number of nodes.

See Also

Other caugi methods:print()

Examples

cg <- caugi(  A %-->% B,  class = "DAG")length(cg) # 2cg2 <- caugi(  A %-->% B + C,  nodes = LETTERS[1:5],  class = "DAG")length(cg2) # 5

Get Markov blanket of nodes in acaugi

Description

Get Markov blanket of nodes in acaugi

Usage

markov_blanket(cg, nodes = NULL, index = NULL)

Arguments

cg

Acaugi object.

nodes

A vector of node names, a vector of unquotednode names, or an expression combining these with+ andc().

index

A vector of node indexes.

Value

Either a character vector of node names (if a single node isrequested) or a list of character vectors (if multiple nodes are requested).

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),neighbors(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")markov_blanket(cg, "A") # "B"markov_blanket(cg, index = 2) # "A" "C"markov_blanket(cg, "B") # "A" "C"markov_blanket(cg, c("B", "C"))#> $B#> [1] "A" "C"#>#> $C#> [1] "B"

Moralize a DAG

Description

Moralizing a DAG involves connecting all parents of each node and thenconverting all directed edges into undirected edges.

Usage

moralize(cg)

Arguments

cg

Acaugi object (DAG).

Details

This changes the graph from a Directed Acyclic Graph (DAG) to anUndirected Graph (UG), also known as a Markov Graph.

Value

Acaugi object representing the moralized graph (UG).

See Also

Other operations:mutate_caugi(),skeleton()

Examples

cg <- caugi(A %-->% C, B %-->% C, class = "DAG")moralize(cg) # A -- B, A -- C, B -- C

Mutatecaugi class

Description

Mutate thecaugi class from one graph class to another, if possible.For example, convert aDAG to aPDAG, or a fully directedcaugi ofclassUNKNOWN to aDAG. Throws an error if not possible.

Usage

mutate_caugi(cg, class)

Arguments

cg

Acaugi object.

class

A character string specifying the new class.

Details

This function returns a copy of the object, and the original remainsunchanged.

Value

Acaugi object of the specified class.

See Also

Other operations:moralize(),skeleton()

Examples

cg <- caugi(A %-->% B, class = "UNKNOWN")cg_dag <- mutate_caugi(cg, "DAG")

Get neighbors of nodes in acaugi

Description

Get neighbors of nodes in acaugi

Usage

neighbors(cg, nodes = NULL, index = NULL)neighbours(cg, nodes = NULL, index = NULL)

Arguments

cg

Acaugi object.

nodes

A vector of node names, a vector of unquotednode names, or an expression combining these with+ andc().

index

A vector of node indexes.

Value

Either a character vector of node names (if a single node isrequested) or a list of character vectors (if multiple nodes are requested).

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),nodes(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")neighbors(cg, "A") # "B"neighbors(cg, index = 2) # "A" "C"neighbors(cg, "B") # "A" "C"neighbors(cg, c("B", "C"))#> $B#> [1] "A" "C"#>#> $C#> [1] "B"

Get nodes or edges of acaugi

Description

Get nodes or edges of acaugi

Usage

nodes(cg)vertices(cg)V(cg)

Arguments

cg

Acaugi object.

Value

Adata.table with aname column.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),parents(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  D,  class = "DAG")nodes(cg) # returns the data.table with nodes A, B, C, D

Get parents of nodes in acaugi

Description

Get parents of node in a graph. Note that not both nodes and index can begiven.

Usage

parents(cg, nodes = NULL, index = NULL)

Arguments

cg

Acaugi object.

nodes

A vector of node names, a vector of unquotednode names, or an expression combining these with+ andc().

index

A vector of node indexes.

Value

Either a character vector of node names (if a single node isrequested) or a list of character vectors (if multiple nodes are requested).

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),same_nodes(),subgraph()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")parents(cg, "A") # NULLparents(cg, index = 2) # "A"parents(cg, "B") # "A"parents(cg, c("B", "C"))#> $B#> [1] "A"#>#> $C#> [1] "B"

Print acaugi

Description

Print acaugi

Arguments

x

Acaugi object.

max_nodes

Optional numeric; maximum number of node names to consider.IfNULL, the method automatically prints as many as fit on one consoleline (plus a separate truncation line if needed).

max_edges

Optional numeric; maximum number of edges to consider.IfNULL, the method automatically prints as many edges as fit on twoconsole lines (plus a separate truncation line if needed).

...

Not used.

Value

The inputcaugi object, invisibly.

See Also

Other caugi methods:length()

Examples

cg <- caugi(A %-->% B, class = "DAG")print(cg)

Register a new edge type in the global registry.

Description

Register a new edge type in the global registry.

Usage

register_caugi_edge(glyph, tail_mark, head_mark, class, symmetric = FALSE)

Arguments

glyph

A string representing the edge glyph (e.g.,"-->","<->").

tail_mark

One of "arrow", "tail", "circle", "other".

head_mark

One of "arrow", "tail", "circle", "other".

class

One of "directed","undirected","bidirected","partial".

symmetric

Logical.

Value

TRUE, invisibly.

See Also

Other registry:registry

Examples

# first, for reproducability, we reset the registry to defaultreset_caugi_registry()# create a new registryreg <- caugi_registry()# register an edgeregister_caugi_edge(  glyph = "<--",  tail_mark = "arrow",  head_mark = "tail",  class = "directed",  symmetric = FALSE)# now, this edge is available for caugi graphs:cg <- caugi(A %-->% B, B %<--% C, class = "DAG")# reset the registry to defaultreset_caugi_registry()

caugi edge registry

Description

Thecaugi edge registry stores information about the different edge typesthat can be used incaugi graphs. It maps edge glyphs (e.g.,"-->","<->","o->", etc.) to their specifications, including tail and headmarks, class, and symmetry. The registry allows for dynamic registration ofnew edge types, enabling users to extend the set of supported edges incaugi. It is implemented as a singleton, ensuring that there is a singleglobal instance of the registry throughout the R session.

Usage

caugi_registry()reset_caugi_registry()seal_caugi_registry()

Details

The intented use of thecaugi registry is mostly for advanced users anddevelopers. The registry enables users who need to define their own customedge types incaugi directly. . It currently mostly supports therepresentation of new edges, but for users that might want to representreverse edges, this preserves correctness of reason over these edges.

Value

Anedge_registry external pointer.

Functions

See Also

Other registry:register_caugi_edge()

Examples

# first, for reproducability, we reset the registry to defaultreset_caugi_registry()# create a new registryreg <- caugi_registry()# register an edgeregister_caugi_edge(  glyph = "<--",  tail_mark = "arrow",  head_mark = "tail",  class = "directed",  symmetric = FALSE)# now, this edge is available for caugi graphs:cg <- caugi(A %-->% B, B %<--% C, class = "DAG")# reset the registry to defaultreset_caugi_registry()

Same nodes?

Description

Check if twocaugi objects have the same nodes.

Usage

same_nodes(cg1, cg2, throw_error = FALSE)

Arguments

cg1

Acaugi object.

cg2

Acaugi object.

throw_error

Logical; ifTRUE, throws an error if the graphs do nothave the same nodes.

Value

A logical indicating if the two graphs have the same nodes.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),subgraph()

Examples

cg1 <- caugi(  A %-->% B,  class = "DAG")cg2 <- caugi(  A %-->% B + C,  class = "DAG")same_nodes(cg1, cg2) # FALSE

Structural Hamming Distance

Description

Compute the Structural Hamming Distance (SHD) between twographs.

Usage

shd(cg1, cg2, normalized = FALSE)

Arguments

cg1

Acaugi object.

cg2

Acaugi object.

normalized

Logical; ifTRUE, returns the normalized SHD.

Value

An integer representing the Hamming Distance between the two graphs,ifnormalized = FALSE, or a numeric between 0 and 1 ifnormalized = TRUE.

See Also

Other metrics:aid(),hd()

Examples

cg1 <- caugi(A %-->% B %-->% C, D %-->% C, class = "DAG")cg2 <- caugi(A %-->% B %-->% C, D %---% C, class = "PDAG")shd(cg1, cg2) # 1

Get the skeleton of a graph

Description

The skeleton of a graph is obtained by replacing all directed edges withundirected edges.

Usage

skeleton(cg)

Arguments

cg

Acaugi object. Either a DAG or PDAG.

Details

This changes the graph from any class to an Undirected Graph (UG), also knownas a Markov Graph.

Value

Acaugi object representing the skeleton of the graph (UG).

See Also

Other operations:moralize(),mutate_caugi()

Examples

cg <- caugi(A %-->% B, class = "DAG")skeleton(cg) # A --- B

Get the induced subgraph

Description

Get the induced subgraph

Usage

subgraph(cg, nodes = NULL, index = NULL)

Arguments

cg

Acaugi object.

nodes

A vector of node names, a vector of unquotednode names, or an expression combining these with+ andc().

index

A vector of node indexes.

Value

A newcaugi that is a subgraph of the selected nodes.

See Also

Other queries:ancestors(),children(),descendants(),edge_types(),edges(),exogenous(),is_acyclic(),is_caugi(),is_cpdag(),is_dag(),is_empty_caugi(),is_pdag(),is_ug(),markov_blanket(),neighbors(),nodes(),parents(),same_nodes()

Examples

cg <- caugi(  A %-->% B,  B %-->% C,  class = "DAG")sub_cg <- subgraph(cg, c("B", "C"))cg2 <- caugi(B %-->% C, class = "DAG")all(nodes(sub_cg) == nodes(cg2)) # TRUEall(edges(sub_cg) == edges(cg2)) # TRUE

[8]ページ先頭

©2009-2025 Movatter.jp