collapse_data: Make compact data with data strategies

View source: R/data_helpers.R

collapse_dataR Documentation

Make compact data with data strategies

Description

Take a 'data.frame' and return compact 'data.frame' of event types and strategies.

Usage

collapse_data(
  data,
  model,
  drop_NA = TRUE,
  drop_family = FALSE,
  summary = FALSE
)

Arguments

data

A data.frame. Data of nodes that can take three values: 0, 1, and NA. In long form as generated by make_events

model

A causal_model. A model object generated by make_model.

drop_NA

Logical. Whether to exclude strategy families that contain no observed data. Exceptionally if no data is provided, minimal data on data on first node is returned. Defaults to 'TRUE'

drop_family

Logical. Whether to remove column strategy from the output. Defaults to 'FALSE'.

summary

Logical. Whether to return summary of the data. See details. Defaults to 'FALSE'.

Value

A vector of data events

If summary = TRUE 'collapse_data' returns a list containing the following components:

data_events

A compact data.frame of event types and strategies.

observed_events

A vector of character strings specifying the events observed in the data

unobserved_events

A vector of character strings specifying the events not observed in the data

Examples



model <- make_model('X -> Y')

df <- data.frame(X = c(0,1,NA), Y = c(0,0,1))

df %>% collapse_data(model)


collapse_data(df, model, drop_NA = FALSE)

collapse_data(df, model, drop_family = TRUE)

collapse_data(df, model, summary = TRUE)

data <- make_data(model, n = 0)
collapse_data(data, model)

model <- make_model('X -> Y') %>% set_restrictions('X[]==1')
df <- make_data(model, n = 10)
df[1,1] <- ''
collapse_data(df, model)
data <- data.frame(X= 0:1)
collapse_data(data, model)




CausalQueries documentation built on June 22, 2024, 6:50 p.m.