Learn R Programming

stCEG (version 0.1.0)

create_ceg: Create a Chain Event Graph (CEG)

Description

This function generates a Chain Event Graph (CEG) from a staged tree object and a prior table. It allows for node contraction and mapping, adjusts edge and node attributes, and visualizes the graph with specific customisations for labels, colour, and node arrangement.

Usage

create_ceg(
  staged_tree_obj,
  level_separation = 1200,
  node_distance = 400,
  label = "posterior",
  view_table = FALSE
)

Value

A visNetwork object representing the Chain Event Graph, including contracted nodes and updated edges.If view_table = TRUE, a coloured table is returned that can be displayed in the viewer, instead of just an update_table which can be viewed in the console.

Arguments

staged_tree_obj

A staged tree object containing nodes and edges. It should have the following structure:

  • staged_tree_obj$x$nodes : A data frame of node attributes with columns such as id, level, colour, label, etc.

  • staged_tree_obj$x$edges : A data frame of edge attributes with columns such as from, to, label1, label2, label3, etc.

level_separation

Numeric. The level separation value for hierarchical layout in the visualised graph. Default is 1200.

node_distance

Numeric. The node distance value for hierarchical layout in the visualised graph. Default is 400.

label

A character string specifying the type of label to display on edges. Options include:

  • "prior": Uses posterior label information.

  • "prior_mean": Uses posterior label information.

  • "posterior": Uses posterior label information.

  • "posterior_mean": Uses posterior mean label information.

  • "none": No labels on edges. Default is "posterior_mean".

view_table

Logical. Whether to display the summary table of the aggregated CEG data in the console. Default is FALSE.

Details

This function processes the staged tree and prior table, contracts nodes based on connected nodes, creates aggregated edge summaries, computes posterior and prior mean values, and visualizes the CEG with hierarchical layout, customizable labels, and node distance adjustments.

The function also provides detailed printing of updated edges and contracted nodes for debugging purposes.

Examples

Run this code
data <- homicides
event_tree <- create_event_tree(data, columns = c(1,2,4,5), "both")
coloured_tree <- ahc_colouring(event_tree)

# Cannot run this whole chunk at once as specify_priors needs user input
tree_priors <- specify_priors(coloured_tree, prior_type = "Uniform", ask_edit = FALSE)
staged_tree <- staged_tree_prior(coloured_tree, tree_priors)
ceg <- create_ceg(staged_tree, view_table = TRUE)


Run the code above in your browser using DataLab