| Title: | Causal Effect Identification from Multiple Incomplete Data Sources |
| Version: | 1.1.0 |
| Description: | Identification of causal effects from arbitrary observational and experimental probability distributions via do-calculus and standard probability manipulations using a search-based algorithm by Tikka, Hyttinen and Karvanen (2021) <doi:10.18637/jss.v099.i05>. Allows for the presence of mechanisms related to selection bias (Bareinboim and Tian, 2015) <doi:10.1609/aaai.v29i1.9679>, transportability (Bareinboim and Pearl, 2014) http://ftp.cs.ucla.edu/pub/stat_ser/r443.pdf, missing data (Mohan, Pearl, and Tian, 2013) http://ftp.cs.ucla.edu/pub/stat_ser/r410.pdf) and arbitrary combinations of these. Also supports identification in the presence of context-specific independence (CSI) relations through labeled directed acyclic graphs (LDAG). For details on CSIs see (Corander et al., 2019) <doi:10.1016/j.apal.2019.04.004>. |
| License: | GPL (≥ 3) |
| Depends: | R (≥ 4.0) |
| Suggests: | covr, dagitty, DiagrammeR, igraph, knitr, mockr, rmarkdown, testthat (≥ 3.0.0) |
| Imports: | graphics, Rcpp |
| LinkingTo: | Rcpp |
| VignetteBuilder: | knitr |
| BugReports: | https://github.com/santikka/dosearch/issues |
| URL: | https://github.com/santikka/dosearch |
| Encoding: | UTF-8 |
| NeedsCompilation: | yes |
| Config/testthat/edition: | 3 |
| LazyData: | true |
| Config/roxygen2/version: | 8.1.1 |
| Packaged: | 2026-11-29 07:42:34 UTC; Santtu |
| Author: | Santtu Tikka |
| Maintainer: | Santtu Tikka <santtuth@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-29 08:10:02 UTC |
Causal Effect Identification from Multiple Incomplete Data Sources
Description
Solves causal effect identifiability problems from arbitrary observational and experimental distributions using a heuristic search. Allows for the presence of advanced data-generating mechanisms. See Tikka et al. (2021) https://doi.org/10.18637/jss.v099.i05 for further details.
See also
The package vignette.
-
dosearch()for instructions and various examples. -
https://github.com/santikka/dosearch/issues/ to submit a bug report.
Author(s)
Santtu Tikka, Antti Hyttinen, Juha Karvanen
References
S. Tikka, A. Hyttinen and J. Karvanen. "Causal effect identification from multiple incomplete data sources: a general search-based approach." Journal of Statistical Software, 99(5):1–40, 2021.
See Also
Useful links:
Systematic Analysis of Bivariate Missing Data Problems
Description
This data set contains the results of a systematic analysis of all missing
data problems of two variables. Each problem is associated with a graph
containing two vertices, X and Y, and their response indicators,
R_X and R_Y.
Usage
data(bivariate_missingness)
Format
A data frame with 6144 rows and 8 variables:
- graph
the graph of the instance.
- nedges
number of edges in the graph (directed and bidirected).
- arrowXtoY
whether the graph contains an arrow from
XtoYor not.- jointXY
identifiability of the joint distribution of
XandY- marginX
identifiability of the marginal distribution of
X.- marginY
identifiability of the marginal distribution of
Y.- YcondX
identifiability of the conditional distribution of
YgivenX.- YdoX
identifiability of the causal effect of
XonY.
Source
Tikka et al. https://arxiv.org/abs/1902.01073
Identify a Causal Effect from Arbitrary Experiments And Observations
Description
Identify a causal query from available data in a semi-Markovian
causal model described by a graph that is a directed acyclic graph
(DAG) or a labeled directed acyclic graph (LDAG). In a semi-Markovian causal
model, each unobserved variable has exactly two children and they are denoted
by bidirected edges. For DAGs, special mechanisms related to
transportability of causal effects, recoverability from selection bias and
identifiability under missing data can also be included.
See 'Details' for the syntax of each argument. Note that all character
type arguments are case-sensitive.
is_identifiable returns the a logical value describing the identifiability
of a causal query of an object of class dosearch.
get_formula returns the identifying formula describing a causal query of
an object of class dosearch. If no formula is available, returns NULL.
get_derivation returns the derivation of a causal query of an object of
class dosearch. If no derivation is available, returns NULL.
get_benchmark returns the benchmarking information of an object of
class dosearch. If no benchmark is available, returns NULL.
Usage
dosearch(
data,
query,
graph,
transportability = NULL,
selection_bias = NULL,
missing_data = NULL,
control = list(),
case_reasoning = FALSE
)
## S3 method for class 'dosearch'
summary(object, ...)
## S3 method for class 'dosearch'
plot(x, ...)
## S3 method for class 'dosearch'
print(x, max_chars = 300L, ...)
is_identifiable(x)
get_formula(x, run_again = FALSE, variants = FALSE)
get_derivation(x, run_again = FALSE, draw_all = FALSE)
get_benchmark(x, run_again = FALSE, include_rules = FALSE)
Arguments
data |
A |
query |
A |
graph |
A |
transportability |
A |
selection_bias |
A |
missing_data |
A |
control |
A |
case_reasoning |
A |
object |
An object of class |
... |
Additional arguments passed to |
x |
An object of class |
max_chars |
Maximum number of characters of the formula to display. The default is 300. |
run_again |
If |
variants |
If |
draw_all |
A logical value. If |
include_rules |
A |
Details
Argument data is used to list the available input distributions.
When graph is a DAG the distributions should be of the form
P(A_i|do(B_i),C_i)
Individual variables within sets should be separated by a comma. For example, three input distributions:
P(Z|do(X)), P(W,Y|do(Z,X)), P(W,Y,X|Z)
should be given as follows:
> data <- " + P(Z|do(X)) + P(W,Y|do(Z,X)) + P(W,Y,X|Z) +"
The use of multiple do-operators is not permitted. Furthermore, when both
conditioning variables and a do-operator are present, every conditioning
variable must either precede the do-operator or follow it. When graph is
an LDAG, the do-operation is represented by an intervention node, i.e.,
P(Y|do(X),Z) = P(Y|X,Z,I_X = 1)
For example, in the case of the previous example in an LDAG, the three input distributions become:
> data <- " + P(Z|X,I_X = 1) + P(W,Y|Z,X,I_X=1,I_Z=1) + P(W,Y,X|Z) +"
The intervention nodes I_X and I_Z must be explicitly defined in
the graph along with the relevant labels for the edges.
Argument query is the target distribution of the search.
It has the same syntax as data, but only a single distribution should be
given. Multiple simultaneous target distributions are not supported.
Argument graph is a description of a directed acyclic graph where directed
edges are denoted by -> and bidirected arcs corresponding to unobserved
confounders are denoted by <-> (or by --). As an example, a DAG with two
directed edges and one bidirected edge is constructed as follows:
> graph <- " + X -> Z + Z -> Y + X <-> Y +"
Some alternative formats for DAGs are supported as well. Graphs created using the igraph package in the causal.effect package syntax can be used for dosearch as well. DAGs created using the dagitty package are also supported. Note that both time and space complexity of the underlying search algorithm are exponential in the number of vertices, but instances with up to ten nodes are routinely solved in under a second.
LDAGs are constructed similarly with the addition of labels and with the omission bidirected edges (latent variables must be explicitly defined). As an example, an LDAG with two labeled edges can be constructed as follows:
> graph <- " + X -> Z : A = 0 + Z -> Y : A = 1 + A -> Z + A -> Y +"
Here the labels indicate that the edge from X to Z vanishes when
A has the value 0 and the edge from Z to Y vanishes when
A has the value 1. Multiple labels on the same edge should be
separated by a semi-colon, and individual assignments within each label
should be separated by a comma.
Argument transportability enumerates the nodes that should be understood
as transportability nodes responsible for discrepancies between domains.
Individual variables should be separated by a comma.
See e.g., (Bareinboim and Pearl, 2014) for details on transportability.
Argument selection_bias enumerates the nodes that should be understood as
selection bias nodes responsible for bias in the input data sets.
Individual variables should be separated by a comma. See e.g.,
(Bareinboim and Tian, 2015) for details on selection bias recoverability.
Argument missing_data enumerates the missingness mechanisms of the model.
The syntax for a single mechanism is M_X : X where
MX is the mechanism for X.
Individual mechanisms should be separated by a comma.
If MX or X is not present
in the graph, it is added to the graph with no edges other than the edge to
the proxy variable of X, i.e., it is independent of the other
variables of the graph, and a warning is issued by default. Proxy variables
should not be included in the graph, since they are automatically generated
based on missing_data. By default, a warning
is issued if a proxy variable is present in an input distribution but its
corresponding mechanism is not present in any input. See e.g.,
(Mohan, Pearl and Tian, 2013) for details on missing data as
a causal inference problem. Note that dosearch is not complete for
missing data problems, meaning that if dosearch is not able to identify
the query, it might still be identifiable via some other means.
Missing data mechanisms can be assigned values in data and query.
The value 1 denotes an enabled mechanism, i.e., the variable is observed
and its proxy variable is equal to the true variable, and the value 0
denotes a disabled mechanism, i.e., the variable is missing. For example,
P(Y*,R_Y = 1) is the distribution of the observed values of Y, and
P(Y|R_Y = 0) is the distribution of Y among the units for which
Y is missing, as obtained from a follow-up study of non-respondents.
No other values are permitted. In addition to the rules of
Tikka et al. (2021), the search can use rules analogous to the
case-by-case, general-by-case and case-by-general reasoning of
Tikka et al. (2019) for the values of the mechanisms by setting
case_reasoning = TRUE. These rules are typically needed when mechanisms
are disabled in the input or target distributions, and they can also
identify queries that are not identifiable otherwise when the inputs
originate from different sources. However, they increase the size of the
search space, so they are not used by default.
Before the search is started, the target is checked against criteria that
can show it to be non-identifiable directly from the inputs, in which case
the search is not carried out (when improve = TRUE in control). The
target is non-identifiable by do-search when a variable on the left-hand
side of the target does not appear on the left-hand side of any input
distribution (Tikka et al., 2021). For DAGs without missing data mechanisms,
two additional criteria are used. The first applies when a variable on the
right-hand side of the target does not appear in any input distribution
but the target depends on it, and the second applies when every input
distribution of some variable of the left-hand side of the target also
conditions on, or intervenes on, a neighbor of the variable in the graph
that the rules of the search can never remove, but the target does not.
See the vignette "New features in dosearch 1.1.0" for the precise criteria
and their proofs. With verbose = TRUE in control, the criterion that
applies is reported.
The control argument is a list that can supply any of the following
components:
-
benchmark: alogicalvalue. IfTRUE, the search time is recorded and returned (in milliseconds). Defaults toFALSE. -
benchmark_rules: alogicalvalue. IfTRUE, the time taken by each individual inference rule is also recorded in the benchmark (in milliseconds). Defaults toFALSE. -
cache: alogicalvalue. IfTRUE, the results of the separation criteria evaluated during the search are cached (for LDAGs only). Defaults toTRUE. -
con_vars: acharactervector of additional context variables for LDAGs, i.e., variables that can be assigned values in the input and target distributions even though they do not appear in any edge label. Defaults to an empty vector. -
draw_derivation: alogicalvalue. IfTRUE, a string representing the derivation steps as a DOT graph is returned. If theDiagrammeRpackage is installed, the DOT graph can be plotted by callingploton the return object. Defaults toFALSE. -
draw_all: alogicalvalue. IfTRUEand ifdraw_derivation = TRUE, the derivation will contain every step taken by the search. IfFALSE, only the steps that resulted in an identifiable target are returned. Defaults toFALSE. -
empty: alogicalvalue. IfTRUE, an emptydosearchobject is returned without running the search. -
formula: alogicalvalue. IfTRUE, a string representing the identifiable query is returned when the target query is identifiable. IfFALSE, only a logical value is returned that takes the valueTRUEfor an identifiable target andFALSEotherwise. Defaults toTRUE. -
heuristic: alogicalvalue. IfTRUE, new distributions are expanded during the search according to a search heuristic (see Tikka et al., 2021, for details). Otherwise, distributions are expanded in the order in which they were identified. Defaults toFALSE. -
improve: alogicalvalue. IfTRUE, the search is not carried out when the target can be shown to be non-identifiable directly from the inputs (see 'Details'), and the default rules for DAGs exclude the insertion and deletion of observations (rule 1 of do-calculus), which are implied by the other rules (see Tikka et al., 2021, for details). The observations of proxy variables can still be deleted in missing data problems, because the other rules do not apply to proxy variables. Defaults toTRUE. -
md_sym: deprecated and ignored. Previously, a singlecharacterdescribing the symbol to use for enabled missing data mechanisms. The value 1 now always denotes an enabled mechanism and the value 0 a disabled mechanism. A warning is issued if this argument is provided. -
rules: anintegervector of inference rules to use in the search instead of the default rules. The valid rules are -13, -11, -9, -8, -7, -6, -3, -2, -1 and 1 to 13 for DAGs and -8, -7, -5, -4, -3, -2 and 0 to 8 for LDAGs. For DAGs, rules 9 to 13 and -13 to -9 are used only for missing data problems: rules 9 and -9 assign the values 1 and 0 to missing data mechanisms (case-by-general reasoning), rule 10 exchanges proxy variables for true variables, rules 11 and -11 combine the distributions for both values of a mechanism (case-by-case reasoning), and rules 12, 13 and -13 derive the distribution for one value of a mechanism from the distribution for the other value and the distribution where the mechanism is not assigned a value or is not present (general-by-case reasoning). Rules -9, 11, -11, 12, 13 and -13 are not among the default rules, but they are added to the rules that are used whencase_reasoning = TRUE. Mainly intended for testing and benchmarking, as the search may fail to identify an identifiable query if a necessary rule is omitted. Defaults to an empty vector, which uses the default rules. -
time_limit: anumericvalue giving a time limit for the search (in hours). Defaults to a negative value that disables the time limit. -
verbose: alogicalvalue. IfTRUE, diagnostic information is printed to the console during the search. Defaults toFALSE. -
warn: alogicalvalue. IfTRUE, a warning is issued for possibly unintentionally misspecified but syntactically correct inputs, e.g., when a variable of an input distribution is not present in the graph, in any other input distribution or in the target distribution. A warning is also raised if both lower-case and upper-case node or variable names are used simultaneously in the inputs. Defaults toTRUE.
Value
dosearch returns an object of class dosearch which is a list
with the following components by default. See the control options
on how to obtain a graphical representation of the derivation or
how to benchmark the search.
-
identifiable: alogicalvalue that isTRUEif the target quantity is identifiable andFALSEotherwise. -
formula: acharacterstring describing the formula for an identifiable query in LaTeX syntax or an empty character vector for a non-identifiable effect. The formula shows the derivation of the target from the input distributions: every distribution in the formula is an input distribution or a marginal or conditional distribution of an input distribution, where the values assigned to the variables during the derivation are shown, and the steps of do-calculus do not appear as they do not change the distributions. A marginal or conditional distribution is given as such when the distribution that is marginalized or conditioned is derived from an input distribution by rules that have a single parent distribution, including the rules of do-calculus. The same holds for the division of a distribution by its marginal or conditional distribution (rules 7, -7, 8 and -8) when both are derived from the same input distribution by such rules. Case-by-case reasoning over a variable that is assigned a value reduces to the case of that value, so it counts as a rule with a single parent. Otherwise, the summations and quotients are given explicitly. A summation applies to every term that follows it in the same product, i.e., up to a minus or a plus sign, the end of the enclosing expression or the end of the formula. Products are not enclosed in parentheses, and differences are enclosed in parentheses only when they are terms of products or summations, when they are subtracted or when they are cases of case-by-case reasoning (see below). A variable that is bound by a summation is primed when a variable of the same name is already in scope, i.e., when it is a variable of the target distribution, it appears in the formula outside the summations that bind it, or another summation over a variable of the same name applies at the position of the summation. For example, the front-door formula forP(y|do(x))from the inputP(x,y,z)is given as\sum_{z}p(z|x)\sum_{x'}p(x')p(y|z,x'). Variables bound by nested summations receive additional primes, and a superscript of the form^{(k)}is used instead when the number of primeskwould exceed three. In missing data problems, the proxy variablex*of a variablexis written asx^{\ast}in the formula, and its primes are given in the same superscript, e.g.,x^{\ast\prime}orx^{\ast(4)}. A proxy variable that stands for the value of its true variable has the same primes as the true variable, and the summations over a true variable and over its proxy variable are distinguished in the same way as summations over the same variable. A proxy variable that is removed from a distribution by deleting an observation is not bound by a summation, but it is a variable of its own, which is primed in the same way when a variable of the same name is in scope. The formula holds for every value of such a variable that is possible given its missing data mechanism in the same distribution. When the mechanism has the value 0, the variable is missing, so it is determined by the mechanism, and it is omitted from the distribution, e.g.,p(y|r_x = 0)is given instead ofp(y|r_x = 0,x^{\ast}). The variable is kept only when omitting it would change the distribution, i.e., when the mechanism is on the left-hand side and the variable is not, or when the variable is the only variable on the left-hand side. Furthermore,\left[f_0 \vee f_1\right]denotes the distribution given byf_0when a missing data mechanism has the value 0 and byf_1when it has the value 1 (case-by-case reasoning, seevariants), where a case that is a difference is enclosed in parentheses, e.g.,\left[\left(p(y) - p(r_x = 1,y)\right) \vee p(r_x = 1,y)\right]. -
variants: a namedcharactervector of the variants offormulathat is included when the formula is derived by case-by-case reasoning, i.e., by rules 11 and -11 on the values of missing data mechanisms or by rules 5 and -5 on the values of context variables of labeled DAGs. These variables are binary, and the variants give the formula for each combination of values of the variables that are free in the formula, named by the values, e.g.,"r_x = 0, r_y = 1". The values are assigned in the variants, so the case-by-case reasoning over a variable reduces to the case of its value, and a summation over a variable of case-by-case reasoning is written out as the sum of its terms for the values 0 and 1, which is enclosed in parentheses in the same way as a difference. For example, the formula forP(y)from the inputsP(y^*,r_y)andP(y|r_y = 0)in the graphy -> r_yis\sum_{r_y}\left[p(r_y = 0)p(y|r_y = 0) \vee p(r_y = 1,y^{\ast})\right], and its variant isp(r_y = 0)p(y|r_y = 0) + p(r_y = 1,y^{\ast}). If none of the variables is free in the formula, as here, there is a single variant with an empty name. The variants are also available viaget_formula().
summary returns a summary.dosearch object.
plot returns a htmlwidget object or NULL (invisibly)
print returns x invisibly.
is_identifiable returns a logical value. If TRUE, the target
distribution was identifiable from the available inputs.
get_formula returns a character string representing the query
in terms of the input data or NULL if the query is not identifiable.
If variants is TRUE, the variants are returned as a named
character vector when they are available.
get_derivation returns a graphical representation of the
derivation steps that resulted in identification. The return object
is a character string in DOT syntax.
get_benchmark returns a list with one or two elements or NULL.
The first element of the list is always a numeric
value of the total time taken by the search in milliseconds.
The second is a numeric vector of the time taken by each inference rule
(in the internal C++ implementation) of the search in milliseconds
if include_rules is TRUE.
References
S. Tikka, A. Hyttinen, J. Karvanen. "Causal Effect Identification from Multiple Incomplete Data Sources: A General Search-based Approach." Journal of Statistical Software, 99(5):1–40, 2021.
E. Bareinboim, J. Pearl. "Transportability from Multiple Environments with Limited Experiments: Completeness Results." In Proceedings of the 27th Annual Conference on Neural Information Processing Systems, 280–288, 2014.
E. Bareinboim, J. Tian. "Recovering Causal Effects from Selection Bias " In Proceedings of the 29th AAAI Conference on Artificial Intelligence, 3475–3481, 2015.
K. Mohan, J. Pearl, J. Tian. "Graphical Models for Inference with Missing Data." In Proceedings of the 26th International Conference on Neural Information Processing Systems, 1277–1285, 2013.
S. Tikka, A. Hyttinen, J. Karvanen. "Identifying Causal Effects via Context-Specific Independence Relations." In Proceedings of the 33rd Annual Conference on Neural Information Processing Systems, 2019.
Examples
# A simple back-door formula
data1 <- "P(x,y,z)"
query1 <- "P(y|do(x))"
graph1 <- "
x -> y
z -> x
z -> y
"
dosearch(data1, query1, graph1)
# A simple front-door formula
data2 <- "P(x,y,z)"
query2 <- "P(y|do(x))"
graph2 <- "
x -> z
z -> y
x <-> y
"
dosearch(data2, query2, graph2)
# A scenario with combined transportability and selection bias
data <- "
p(x,z,y|s)
p(y,z|t,do(x))
"
query <- "p(y|do(x))"
graph <- "
x -> z
z -> y
x -> s
t -> z
x <-> y
"
dosearch(
data,
query,
graph,
transportability = "t",
selection_bias = "s",
control = list(heuristic = TRUE, improve = FALSE)
)
# A simple case-control design
data <- "
p(x*,y*,r_x,r_y)
p(y)
"
graph <- "
x -> y
y -> r_y
r_y -> r_x
"
md <- "r_x : x, r_y : y"
dosearch(data, query, graph, missing_data = md)
# The value 0 denotes a disabled missing data mechanism. Here y is
# missing not at random, but a follow-up study of the non-respondents
# provides the distribution of y when it is missing in the original data.
# Combining the cases requires case-by-case reasoning.
data <- "
p(y*,r_y)
p(y|r_y = 0)
"
dosearch(
data,
"p(y)",
"y -> r_y",
missing_data = "r_y : y",
case_reasoning = TRUE
)
# Graph input using 'igraph' in the 'causaleffect' syntax
if (requireNamespace("igraph", quietly = TRUE)) {
g_igraph <- igraph::graph_from_literal(
x -+ z, z -+ y, x -+ y, y -+ x,
simplify = FALSE
)
g_igraph <- igraph::set.edge.attribute(g_igraph, "description", 3:4, "U")
dosearch(data2, query2, g_igraph)
}
# Graph input with 'dagitty'
if (requireNamespace("dagitty", quietly = TRUE)) {
g_dagitty <- dagitty::dagitty("dag{x -> z -> y; x <-> y}")
dosearch(data2, query2, g_dagitty)
}
# Alternative distribution input style using lists and vectors:
# Each element of the list describes a single distribution
# Each element is a character vector that describes the role
# of each variable in the distribution as follows:
# For a variable V and a distribution P(A|do(B),C) we have
# V = 0, if V is in A
# V = 1, if V is in B
# V = 2, if V is in C
data_alt <- list(
c(x = 0, y = 0, z = 0) # = P(x,y,z)
)
query_alt <- c(x = 1, y = 0) # = P(y|do(x))
dosearch(data_alt, query_alt, graph2)
## Not run:
# Additional examples
# Multiple input distributions (both observational and interventional)
data3 <- "
p(z_2,x_2|do(x_1))
p(z_1|x_2,do(x_1,y))
p(x_1|w,do(x_2))
p(y|z_1,z_2,x_1,do(x_2))
p(w|y,x_1,do(x_2))
"
query3 <- "p(y,x_1|w,do(x_2))"
graph3 <- "
x_1 -> z_2
x_1 -> z_1
x_2 -> z_1
x_2 -> z_2
z_1 -> y
z_2 -> y
x_1 -> w
x_2 -> w
z_1 -> w
z_2 -> w
"
dosearch(data3, query3, graph3)
# Selection bias
data4 <- "
p(x,y,z_1,z_2|s)
p(z_1,z_2)
"
query4 <- "p(y|do(x))"
graph4 <- "
x -> z_1
z_1 -> z_2
x -> y
y -- z_2
z_2 -> s
"
dosearch(data4, query4, graph4, selection_bias = "s")
# Transportability
data5 <- "
p(x,y,z_1,z_2)
p(x,y,z_1|t_1,t_2,do(z_2))
p(x,y,z_2|t_3,do(z_1))
"
query5 <- "p(y|do(x))"
graph5 <- "
z_1 -> x
x -> z_2
z_2 -> y
z_1 <-> x
z_1 <-> z_2
z_1 <-> y
t_1 -> z_1
t_2 -> z_2
t_3 -> y
"
dosearch(data5, query5, graph5, transportability = "t_1, t_2, t_3")
# Missing data
# Proxy variables are denoted by an asterisk (*)
data6 <- "
p(x*,y*,z*,m_x,m_y,m_z)
"
query6 <- "p(x,y,z)"
graph6 <- "
z -> x
x -> y
x -> m_z
y -> m_z
y -> m_x
z <-> y
"
# The mechanism m_y is independent of the other variables, so it is not
# present in the graph, which would produce a warning by default
dosearch(
data6,
query6,
graph6,
missing_data = "m_x : x, m_y : y, m_z : z",
control = list(warn = FALSE)
)
# An LDAG
data7 <- "P(X,Y,Z)"
query7 <- "P(Y|X,I_X=1)"
graph7 <- "
X -> Y : Z = 1
Z -> Y
Z -> X : I_X = 1
I_X -> X
H -> X : I_X = 1
H -> Z
Q -> Z
Q -> Y : Z = 0
"
dosearch(data7, query7, graph7)
# A more complicated LDAG
# with multiple assignments for the edge X -> Z
data8 <- "P(X,Y,Z,A,W)"
query8 <- "P(Y|X,I_X=1)"
graph8 <- "
I_X -> X
I_Z -> Z
A -> W
Z -> Y
A -> Z
X -> Z : I_Z = 1; A = 1
X -> Y : A = 0
W -> X : I_X = 1
W -> Y : A = 0
A -> Y
U -> X : I_X = 1
U -> Y : A = 1
"
dosearch(data8, query8, graph8)
## End(Not run)
data <- "p(x,y,z)"
query <- "p(y|do(x))"
graph <- "
x -> y
z -> x
z -> y
"
x <- dosearch(data, query, graph)
y <- summary(x)
## Not run:
out <- dosearch(
"p(x,y,z, w)",
"p(y|do(x))",
"x -> y \n z -> x \n w -> z \n x <-> w \n w <-> y",
control = list(draw_derivation = TRUE)
)
if (requireNamespace("DiagrammeR", quietly = TRUE)) {
plot(out)
}
## End(Not run)
data <- "p(x,y,z)"
query <- "p(y|do(x))"
graph <- "
x -> z
z -> y
x <-> y
"
x <- dosearch(data, query, graph)
print(x)
data <- "P(x,y,z)"
query <- "P(y|do(x))"
graph <- "
x -> y
z -> x
z -> y
"
x <- dosearch(data, query, graph)
is_identifiable(x)
# TRUE
data <- "P(x,y,z)"
query <- "P(y|do(x))"
graph <- "
x -> y
z -> x
z -> y
"
x <- dosearch(data, query, graph, control = list(formula = FALSE))
get_formula(x, run_again = TRUE)
# The variants of a formula derived by case-by-case reasoning
x <- dosearch(
"p(y*,r_y = 1) \n p(y,r_y = 0)",
"p(y|r_y)",
"y -> r_y",
missing_data = "r_y : y",
case_reasoning = TRUE
)
get_formula(x, variants = TRUE)
data <- "P(x,y,z)"
query <- "P(y|do(x))"
graph <- "
x -> y
z -> x
z -> y
"
x <- dosearch(data, query, graph, control = list(draw_derivation = FALSE))
get_derivation(x, run_again = TRUE)
data <- "P(x,y,z)"
query <- "P(y|do(x))"
graph <- "
x -> y
z -> x
z -> y
"
x <- dosearch(data, query, graph, control = list(benchmark = FALSE))
get_benchmark(x, run_again = TRUE)
Plot the Formula of a Causal Query
Description
plot_formula draws the formula of an object of class dosearch on the
current graphics device with the mathematics rendered, e.g., summations
with their limits, fractions, subscripts, superscripts and primes. The
formula is converted to a grDevices::plotmath expression, so no LaTeX
installation is needed.
Usage
plot_formula(x, variants = FALSE, max_chars = 500L, cex = 1.5, ...)
Arguments
x |
An object of class |
variants |
A |
max_chars |
The maximum number of characters of a formula to plot. The default is 500. |
cex |
A |
... |
Additional arguments passed to |
Details
The formula is drawn on a single line without line breaks, and the text is
shrunk to fit the plot region, so the function is intended for formulas of
moderate length. Formulas longer than max_chars characters (as given by
get_formula()) are not plotted.
The name of a variable is split at its first underscore into a name and a
subscript, e.g., r_x is drawn as r_x. Proxy variables are drawn
with an asterisk as a superscript, and primes as prime marks, e.g.,
y^{\ast\prime} is drawn as y^{*\prime}. A variable name that
contains other characters than ASCII letters, digits, periods and
underscores, or that begins or ends with an underscore, is cleaned for
plotting: non-ASCII characters are transliterated, the other characters are
replaced by periods, and the underscores at the beginning and the end are
removed. A warning lists the names that were changed. The formula itself
is not changed.
The mathematical symbols are drawn with the symbol font of the graphics
device. The grDevices::pdf() device does not embed this font in the file,
so PDF viewers may substitute another font, which can affect the spacing
around the symbols. The grDevices::cairo_pdf() device embeds the fonts.
Value
The plotted formulas as an expression vector (invisibly), which
can also be drawn by other functions that support
grDevices::plotmath, or NULL (invisibly) if no formula is available.
Examples
data <- "p(x,y,z)"
query <- "p(y|do(x))"
graph <- "
x -> z
z -> y
x <-> y
"
x <- dosearch(data, query, graph)
plot_formula(x)
# The variants of a formula derived by case-by-case reasoning
x <- dosearch(
"p(y*,r_y = 1) \n p(y,r_y = 0)",
"p(y|r_y)",
"y -> r_y",
missing_data = "r_y : y",
case_reasoning = TRUE
)
plot_formula(x, variants = TRUE)
Print the Summary of a dosearch Object
Description
Print the Summary of a dosearch Object
Usage
## S3 method for class 'summary.dosearch'
print(x, max_chars = 300L, ...)
Arguments
x |
An object of class |
max_chars |
Maximum number of characters of the formula to display. The default is 300. |
... |
Not used. |
Value
x (invisibly)
Examples
data <- "p(x,y,z)"
query <- "p(y|do(x))"
graph <- "
x -> y
z -> x
z -> y
"
x <- dosearch(data, query, graph)
y <- summary(x)
print(y)