Learn R Programming

CausalQueries (version 1.2.1)

inspection: Helpers for inspecting causal models

Description

Various helpers to inspect or access internal objects generated or used by Causal Models

Returns specified elements from a causal_model and prints summary. Users can use inspect to extract model's components or objects implied by the model structure including nodal types, causal types, parameter priors, parameter posteriors, type priors, type posteriors, and other relevant elements. See argument what for other options.

Returns specified elements from a causal_model. Users can use inspect to extract model's components or objects implied by the model structure including nodal types, causal types, parameter priors, parameter posteriors, type priors, type posteriors, and other relevant elements. See argument what for other options.

Usage

inspect(model, what = NULL, ...)

grab(model, what = NULL, ...)

Value

Objects that can be derived from a causal_model, with summary.

Quiet return of objects that can be derived from a causal_model.

Arguments

model

A causal_model. A model object generated by make_model.

what

A character string specifying the component to retrieve. Available options are:

  • "statement" a character string describing causal relations using dagitty syntax,

  • "nodes" A list containing the nodes in the model,

  • "parents_df" A table listing nodes, whether they are root nodes or not, and the number and names of parents they have,

  • "parameters" A vector of 'true' parameters,

  • "parameter_names" A vector of names of parameters,

  • "parameter_mapping" A matrix mapping from parameters into data types,

  • "parameter_matrix" A matrix mapping from parameters into causal types,

  • "parameters_df" A data frame containing parameter information,

  • "causal_types" A data frame listing causal types and the nodal types that produce them,

  • "nodal_types" A list with the nodal types of the model,

  • "data_types" A list with all data types consistent with the model; for options see ?get_all_data_types,

  • "ambiguities_matrix" A matrix mapping from causal types into data types,

  • "type_prior" A matrix of type probabilities using priors,

  • "prior_hyperparameters" A vector of alpha values used to parameterize Dirichlet prior distributions; optionally provide node names to reduce output, e.g., inspect(prior_hyperparameters, nodes = c('M', 'Y')),

  • "prior_event_probabilities" A vector of data (event) probabilities given a single realization of parameters; for options see ?get_event_probabilities,

  • "prior_distribution" A data frame of the parameter prior distribution,

  • "posterior_distribution" A data frame of the parameter posterior distribution,

  • "posterior_event_probabilities" A sample of data (event) probabilities from the posterior,

  • "type_distribution" A matrix of type probabilities using posteriors,

  • "data" A data frame with data that was provided to update the model,

  • "stanfit" A stanfit object generated by Stan; prints stanfit summary with updated parameter names,

  • "stan_summary" A list of Stan outputs that includes stanfit, data, and, if requested when updating the model, posterior event_probabilities and type_distribution; prints stanfit summary with updated parameter names.

...

Other arguments passed to helper "get_*" functions: get_all_data_types, get_event_probabilities, get_priors, Anys such additional arguments must be named.

Examples

Run this code
# \donttest{

model <- make_model("X -> Y")
data <- make_data(model, n = 4)

inspect(model, what = "statement")
inspect(model, what = "parameters")
inspect(model, what = "nodes")
inspect(model, what = "parents_df")
inspect(model, what = "parameters_df")
inspect(model, what = "causal_types")
inspect(model, what = "prior_distribution")
inspect(model, what = "prior_hyperparameters", nodes = "Y")
inspect(model, what = "prior_event_probabilities", parameters = c(.1, .9, .25, .25, 0, .5))
inspect(model, what = "prior_event_probabilities", given = "Y==1")
inspect(model, what = "data_types", complete_data = TRUE)
inspect(model, what = "data_types", complete_data = FALSE)


model <- update_model(model,
  data = data,
  keep_fit = TRUE,
  keep_event_probabilities = TRUE)

inspect(model, what = "posterior_distribution")
inspect(model, what = "posterior_event_probabilities")
inspect(model, what = "type_distribution")
inspect(model, what = "data")
inspect(model, what = "stanfit")
# }

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

x <- grab(model, what = "statement")
x

Run the code above in your browser using DataLab