create_event_tree {stCEG} | R Documentation |
Create an Event Tree from a Dataset
Description
This function constructs an event tree from a given dataset based on user-specified categorical variables. The resulting tree is represented as a graph, where each unique combination of variable values corresponds to a distinct path in the tree.
Usage
create_event_tree(
dataset,
columns = seq_along(dataset),
label_type = "both",
level_separation = 1000,
node_distance = 300
)
Arguments
dataset |
A data frame containing categorical variables. |
columns |
A vector of column indices or names specifying which variables to use for constructing the event tree. |
label_type |
A character string specifying how edge labels should be displayed. Options are |
level_separation |
A numeric value indicating the spacing between levels in the visualization. Default is |
node_distance |
A numeric value specifying the horizontal distance between nodes in the visualization. Default is |
Details
The function follows these steps:
Extracts the specified columns from the dataset.
Determines unique values for each variable and generates state names dynamically.
Constructs a directed acyclic graph (DAG) using
igraph
, where each state represents a unique combination of variable values.Computes transition counts between states.
Uses
visNetwork
to generate an interactive visualization of the event tree.
Value
A visNetwork
object displaying the event tree.
Examples
data <- homicides
event_tree <- create_event_tree(data, columns = c(1,2,4,5), "both")
event_tree