collapse_data {CausalQueries}R 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 <- simulate_data(model, n = 10)
df[1,1] <- ''
collapse_data(df, model)

collapse_data(df, model, drop_NA = FALSE)

collapse_data(df, model, drop_family = TRUE)

collapse_data(df, model, summary = TRUE)

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

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

model <- make_model('X->Y')
long_data <- simulate_data(model, n = 6)
collapse_data(long_data, model)


[Package CausalQueries version 0.0.3 Index]