query_model: Generate estimands dataframe

Description Usage Arguments Value Examples

View source: R/query_model.R

Description

Calculated from a parameter vector, from a prior or from a posterior distribution

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
query_model(
  model,
  queries = NULL,
  given = NULL,
  using = list("priors"),
  parameters = NULL,
  stats = NULL,
  digits = 3,
  n_draws = 4000,
  expand_grid = FALSE,
  query = NULL
)

Arguments

model

A causal_model. A model object generated by make_model.

queries

A vector of characters. Query on potential outcomes such as "Y[X=1] - Y[X=0]".

given

A character. A quoted expression that evaluates to a logical statement. Allows estimand to be conditioned on *observational* (or counterfactual) distribution.

using

A character. Whether to use 'priors', 'posteriors' or 'parameters'.

parameters

A vector of real numbers in [0,1]. Values of parameters to specify (optional). By default, parameters is drawn from model$parameters_df.

stats

Functions to be applied to estimand distribution. If 'NULL', defaults to mean and standard deviation.

digits

An integer. Decimal digits in output table.

n_draws

An integer. Number of draws.

expand_grid

Logical. If TRUE then all combinations of provided lists are examined. If not then each list is cycled through separately. Defaults to 'FALSE'.

query

alias for queries

Value

A data.frame with columns 'Query', 'Given' and 'Using' defined by corresponding input values. Further columns are generated as specified in 'stats'.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
model <- make_model("X -> Y") %>% set_prior_distribution(n_draws = 10000)


estimands_df <-query_model(
               model,
               query = list(ATE = "Y[X=1] - Y[X=0]", Share_positive = "Y[X=1] > Y[X=0]"),
               using = c("parameters", "priors"),
               expand_grid = TRUE)

estimands_df <-query_model(
               model,
               query = list(ATE = "Y[X=1] - Y[X=0]", Share_positive = "Y[X=1] > Y[X=0]"),
               using = c("parameters", "priors"),
               expand_grid = FALSE)

estimands_df <- query_model(
                model,
                using = list( "parameters", "priors"),
                query = list(ATE = "Y[X=1] - Y[X=0]", Is_B = "Y[X=1] > Y[X=0]"),
                given = list(TRUE,  "Y==0 & X==1"),
                expand_grid = TRUE,
                digits = 3)

# An example: a stat representing uncertainty of token causation
token_var <- function(x) mean(x)*(1-mean(x))
estimands_df <- query_model(
                model,
                using = list( "parameters", "priors"),
                query = "Y[X=1] > Y[X=0]",
                stats = c(mean = mean, sd = sd, token_var = token_var))

CausalQueries documentation built on July 1, 2020, 7:46 p.m.