query_distribution {CausalQueries}R Documentation

Calculate query distribution

Description

Calculated distribution of a query from a prior or posterior distribution of parameters

Usage

query_distribution(
  model,
  query,
  given = TRUE,
  using = "priors",
  parameters = NULL,
  type_distribution = NULL,
  verbose = FALSE,
  join_by = "|"
)

Arguments

model

A causal_model. A model object generated by make_model.

query

A character. A query on potential outcomes such as "Y[X=1] - Y[X=0]"

given

A character. A quoted expression evaluates to logical statement. given allows estimand to be conditioned on *observational* distribution.

using

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

parameters

A vector of real numbers in [0,1]. A true parameter vector to be used instead of parameters attached to the model in case 'using' specifies 'parameters'

type_distribution

A numeric vector. If provided saves calculation, otherwise calculated from model; may be based on prior or posterior

verbose

Logical. Whether to print mean and standard deviation of the estimand on the console.

join_by

A character. The logical operator joining expanded types when query contains wildcard (.). Can take values "&" (logical AND) or "|" (logical OR). When restriction contains wildcard (.) and join_by is not specified, it defaults to "|", otherwise it defaults to NULL.

Value

A vector of draws from the distribution of the potential outcomes specified in 'query'

Examples

model <- make_model("X -> Y") %>%
         set_prior_distribution()
 
 distribution <- query_distribution(model, query = "(Y[X=1] - Y[X=0])")

 distribution <- query_distribution(model, query = "(Y[X=1] - Y[X=0])", given = "X==1")
 distribution <- query_distribution(model, query = "(Y[X=1] - Y[X=0])", given = "Y[X=1]==1")
 distribution <- query_distribution(model, query = "(Y[X=1] > Y[X=0])")
 distribution <- query_distribution(model, query = "(Y[X=.] == 1)", join_by = "&")
 distribution <- query_distribution(model, query = "(Y[X=1] - Y[X=0])", using = "parameters")
 df    <- simulate_data(model, n = 3)
 updated_model <- update_model(model, df)
 query_distribution( updated_model , query = "(Y[X=1] - Y[X=0])", using = "posteriors")


[Package CausalQueries version 0.0.3 Index]