Various helpers to describe queries or parts of queries in natural language.
Generate a statement for Y monotonic (increasing) in X
Generate a statement for Y weakly monotonic (increasing) in X
Generate a statement for Y monotonic (decreasing) in X
Generate a statement for Y weakly monotonic (not increasing) in X
Generate a statement for X1, X1 interact in the production of Y
Generate a statement for X1, X1 complement each other in the production of Y
Generate a statement for X1, X1 substitute for each other in the production of Y
Generate a statement for (Y(1) - Y(0)). This statement when applied to
a model returns an element in (1,0,-1) and not a set of cases.
This is useful for some purposes such as querying a model, but not for
uses that require a list of types, such as set_restrictions
.
Usage
increasing(X, Y)
non_decreasing(X, Y)
decreasing(X, Y)
non_increasing(X, Y)
interacts(X1, X2, Y)
complements(X1, X2, Y)
substitutes(X1, X2, Y)
te(X, Y)
Value
A character statement of class statement
A character statement of class statement
A character statement of class statement
A character statement of class statement
A character statement of class statement
A character statement of class statement
A character statement of class statement
A character statement of class statement
Examples
# \donttest{
increasing('A', 'B')
#> [1] "(B[A=1] > B[A=0])"
# }
# \donttest{
non_decreasing('A', 'B')
#> [1] "(B[A=1] >= B[A=0])"
# }
# \donttest{
decreasing('A', 'B')
#> [1] "(B[A=1] < B[A=0])"
# }
# \donttest{
non_increasing('A', 'B')
#> [1] "(B[A=1] <= B[A=0])"
# }
# \donttest{
interacts('A', 'B', 'W')
#> [1] "((W[A =1, B = 1]) - (W[A = 0, B = 1])) != ((W[A =1, B = 0]) - (W[A = 0, B = 0]))"
get_query_types(model = make_model('X-> Y <- W'),
query = interacts('X', 'W', 'Y'), map = "causal_type")
#>
#> Causal types satisfying query's condition(s)
#>
#> query = ((Y[X=1,W=1])-(Y[X=0,W=1]))!=((Y[X=1,W=0])-(Y[X=0,W=0]))
#>
#> W0.X0.Y1000 W1.X0.Y1000
#> W0.X1.Y1000 W1.X1.Y1000
#> W0.X0.Y0100 W1.X0.Y0100
#> W0.X1.Y0100 W1.X1.Y0100
#> W0.X0.Y0010 W1.X0.Y0010
#> W0.X1.Y0010 W1.X1.Y0010
#> W0.X0.Y0110 W1.X0.Y0110
#> W0.X1.Y0110 W1.X1.Y0110
#> W0.X0.Y1110 W1.X0.Y1110
#> W0.X1.Y1110 W1.X1.Y1110
#> W0.X0.Y0001 W1.X0.Y0001
#> W0.X1.Y0001 W1.X1.Y0001
#> W0.X0.Y1001 W1.X0.Y1001
#> W0.X1.Y1001 W1.X1.Y1001
#> W0.X0.Y1101 W1.X0.Y1101
#> W0.X1.Y1101 W1.X1.Y1101
#> W0.X0.Y1011 W1.X0.Y1011
#> W0.X1.Y1011 W1.X1.Y1011
#> W0.X0.Y0111 W1.X0.Y0111
#> W0.X1.Y0111 W1.X1.Y0111
#>
#>
#> Number of causal types that meet condition(s) = 40
#> Total number of causal types in model = 64
# }
# \donttest{
complements('A', 'B', 'W')
#> [1] "((W[A =1, B = 1]) - (W[A = 0, B = 1])) > ((W[A =1, B = 0]) - (W[A = 0, B = 0]))"
# }
# \donttest{
get_query_types(model = make_model('A -> B <- C'),
query = substitutes('A', 'C', 'B'),map = "causal_type")
#>
#> Causal types satisfying query's condition(s)
#>
#> query = ((B[A=1,C=1])-(B[A=0,C=1]))<((B[A=1,C=0])-(B[A=0,C=0]))
#>
#> A0.C0.B0100 A1.C0.B0100
#> A0.C1.B0100 A1.C1.B0100
#> A0.C0.B0010 A1.C0.B0010
#> A0.C1.B0010 A1.C1.B0010
#> A0.C0.B0110 A1.C0.B0110
#> A0.C1.B0110 A1.C1.B0110
#> A0.C0.B1110 A1.C0.B1110
#> A0.C1.B1110 A1.C1.B1110
#> A0.C0.B0111 A1.C0.B0111
#> A0.C1.B0111 A1.C1.B0111
#>
#>
#> Number of causal types that meet condition(s) = 20
#> Total number of causal types in model = 64
query_model(model = make_model('A -> B <- C'),
queries = substitutes('A', 'C', 'B'),
using = 'parameters')
#>
#> Causal queries generated by query_model (all at population level)
#>
#> |query |using | mean|
#> |:---------------------------------------------------------------------------------|:----------|-----:|
#> |((B[A = 1, C = 1]) - (B[A = 0, C = 1])) < ((B[A = 1, C = 0]) - (B[A = 0, C = 0])) |parameters | 0.312|
#>
# }
# \donttest{
te('A', 'B')
#> [1] "(B[A=1] - B[A=0])"
model <- make_model('X->Y') |> set_restrictions(increasing('X', 'Y'))
query_model(model, list(ate = te('X', 'Y')), using = 'parameters')
#>
#> Causal queries generated by query_model (all at population level)
#>
#> |query |using | mean|
#> |:-----|:----------|------:|
#> |ate |parameters | -0.333|
#>
# set_restrictions breaks with te because it requires a listing
# of causal types, not numeric output.
# }
if (FALSE) { # \dontrun{
model <- make_model('X->Y') |> set_restrictions(te('X', 'Y'))
} # }