integrated-inferences / CausalQueries

Bayesian inference from binary causal models
Other
24 stars 7 forks source link

make dag plotable and attache list of parents currenlty in dag as attribute to parents_df #344

Open till-tietz opened 2 months ago

till-tietz commented 2 months ago

We have an issue here that dag does not contain the information we need for plot_model I wonder should we remove or rename model$dag. We only use it for accessing the list of parents. So we could just have a list of parents as an attribute on model$parents_df

Here’s a function to generate the list and replace get_parents:

generate_node_parents_list <- function(df) {

# Initialize an empty list
node_parents_list <- list()

# Iterate over each row of the data frame
for (i in 1:nrow(df)) {
node <- df$node[i]
parent_nodes <- df$parent_nodes[i]

# Split the parent nodes by comma and remove any whitespace
parent_nodes_list <- unlist(strsplit(parent_nodes, ",\\s*"))

# Assign the parent nodes to the corresponding node in the list
node_parents_list[[node]] <- parent_nodes_list
}

node_parents_list[df$parent_nodes != ""]
} 

Need to be sure it goes in the right order and does not break anything

till-tietz commented 2 months ago

@macartan --> revised function etc. is in the linked branch. Let me know if we should kill dag entirely or if you want to make dag a plotable object (e.g. rename statement to dag)