Find which nodal or causal types are satisfied by a query.
Arguments
- model
A
causal_model
. A model object generated bymake_model
.- query
A character string. An expression defining nodal types to interrogate. An expression of the form "Y[X=1]" asks for the value of Y when X is set to 1
- map
Types in query. Either
nodal_type
orcausal_type
. Default iscausal_type
.- join_by
A logical operator. Used to connect causal statements: AND ('&') or OR ('|'). Defaults to '|'.
Value
A list containing some of the following elements
- types
A named vector with logical values indicating whether a
nodal_type
or acausal_type
satisfy `query`- query
A character string as specified by the user
- expanded_query
A character string with the expanded query. Only differs from `query` if this contains wildcard '.'
- evaluated_nodes
Value that the nodes take given a query
- node
A character string of the node whose nodal types are being queried
- type_list
List of causal types satisfied by a query
Examples
model <- make_model('X -> M -> Y; X->Y')
query <- '(Y[X=0] > Y[X=1])'
# \donttest{
get_query_types(model, query, map="nodal_type")
#>
#> Nodal types adding weight to query
#>
#> query : (Y[X=0,M=0]>Y[X=1,M=0] | Y[X=0,M=1]>Y[X=1,M=1])
#>
#> 1000 0010
#> 1010 0110
#> 1110 1001
#> 1011
#>
#>
#> Number of nodal types that add weight to query = 7
#> Total number of nodal types related to Y = 16
get_query_types(model, query, map="causal_type")
#>
#> Causal types satisfying query's condition(s)
#>
#> query = (Y[X=0]>Y[X=1])
#>
#> X0.M00.Y1000 X1.M00.Y1000
#> X0.M01.Y1000 X1.M01.Y1000
#> X0.M01.Y1100 X1.M01.Y1100
#> X0.M10.Y0010 X1.M10.Y0010
#> X0.M11.Y0010 X1.M11.Y0010
#> X0.M00.Y1010 X1.M00.Y1010
#> X0.M10.Y1010 X1.M10.Y1010
#> X0.M01.Y1010 X1.M01.Y1010
#> X0.M11.Y1010 X1.M11.Y1010
#> X0.M11.Y0110 X1.M11.Y0110
#> X0.M01.Y1110 X1.M01.Y1110
#> X0.M11.Y1110 X1.M11.Y1110
#> X0.M00.Y1001 X1.M00.Y1001
#> X0.M10.Y0011 X1.M10.Y0011
#> X0.M00.Y1011 X1.M00.Y1011
#> X0.M10.Y1011 X1.M10.Y1011
#>
#>
#> Number of causal types that meet condition(s) = 32
#> Total number of causal types in model = 128
get_query_types(model, query)
#>
#> Causal types satisfying query's condition(s)
#>
#> query = (Y[X=0]>Y[X=1])
#>
#> X0.M00.Y1000 X1.M00.Y1000
#> X0.M01.Y1000 X1.M01.Y1000
#> X0.M01.Y1100 X1.M01.Y1100
#> X0.M10.Y0010 X1.M10.Y0010
#> X0.M11.Y0010 X1.M11.Y0010
#> X0.M00.Y1010 X1.M00.Y1010
#> X0.M10.Y1010 X1.M10.Y1010
#> X0.M01.Y1010 X1.M01.Y1010
#> X0.M11.Y1010 X1.M11.Y1010
#> X0.M11.Y0110 X1.M11.Y0110
#> X0.M01.Y1110 X1.M01.Y1110
#> X0.M11.Y1110 X1.M11.Y1110
#> X0.M00.Y1001 X1.M00.Y1001
#> X0.M10.Y0011 X1.M10.Y0011
#> X0.M00.Y1011 X1.M00.Y1011
#> X0.M10.Y1011 X1.M10.Y1011
#>
#>
#> Number of causal types that meet condition(s) = 32
#> Total number of causal types in model = 128
# Examples with map = "nodal_type"
query <- '(Y[X=0, M = .] > Y[X=1, M = 0])'
get_query_types(model, query, map="nodal_type")
#>
#> Nodal types adding weight to query
#>
#> query : (Y[X=0,M=0]>Y[X=1,M=0] | Y[X=0,M=1]>Y[X=1,M=0])
#>
#> 1000 0010
#> 1010 1001
#> 0011 1011
#>
#>
#> Number of nodal types that add weight to query = 6
#> Total number of nodal types related to Y = 16
query <- '(Y[] == 1)'
get_query_types(model, query, map="nodal_type")
#>
#> Nodal types adding weight to query
#>
#> query : (Y[X=0,M=0]==1 | Y[X=1,M=0]==1 | Y[X=0,M=1]==1 | Y[X=1,M=1]==1)
#>
#> 1000 0100
#> 1100 0010
#> 1010 0110
#> 1110 0001
#> 1001 0101
#> 1101 0011
#> 1011 0111
#> 1111
#>
#>
#> Number of nodal types that add weight to query = 15
#> Total number of nodal types related to Y = 16
get_query_types(model, query, map="nodal_type", join_by = '&')
#>
#> Nodal types adding weight to query
#>
#> query : (Y[X=0,M=0]==1 & Y[X=1,M=0]==1 & Y[X=0,M=1]==1 & Y[X=1,M=1]==1)
#>
#> 1111
#>
#>
#> Number of nodal types that add weight to query = 1
#> Total number of nodal types related to Y = 16
# Root nodes specified with []
get_query_types(model, '(X[] == 1)', map="nodal_type")
#>
#> Nodal types adding weight to query
#>
#> query : (X[]==1)
#>
#> 1
#>
#>
#> Number of nodal types that add weight to query = 1
#> Total number of nodal types related to X = 2
query <- '(M[X=1] == M[X=0])'
get_query_types(model, query, map="nodal_type")
#>
#> Nodal types adding weight to query
#>
#> query : (M[X=1]==M[X=0])
#>
#> 00 11
#>
#>
#> Number of nodal types that add weight to query = 2
#> Total number of nodal types related to M = 4
# Nested do operations
get_query_types(
model = make_model('A -> B -> C -> D'),
query = '(D[C=C[B=B[A=1]], A=0] > D[C=C[B=B[A=0]], A=0])')
#>
#> Causal types satisfying query's condition(s)
#>
#> query = (D[C=C[B=B[A=1]],A=0]>D[C=C[B=B[A=0]],A=0])
#>
#> A0.B01.C10.D10 A1.B01.C10.D10
#> A0.B10.C01.D10 A1.B10.C01.D10
#> A0.B10.C10.D01 A1.B10.C10.D01
#> A0.B01.C01.D01 A1.B01.C01.D01
#>
#>
#> Number of causal types that meet condition(s) = 8
#> Total number of causal types in model = 128
# Helpers
model <- make_model('M->Y; X->Y')
query <- complements('X', 'M', 'Y')
get_query_types(model, query, map="nodal_type")
#>
#> Nodal types adding weight to query
#>
#> query : ((Y[X=1,M=1])-(Y[X=0,M=1]))>((Y[X=1,M=0])-(Y[X=0,M=0]))
#>
#> 1000 0001
#> 1001 1101
#> 1011
#>
#>
#> Number of nodal types that add weight to query = 5
#> Total number of nodal types related to Y = 16
# Examples with map = "causal_type"
model <- make_model('X -> M -> Y; X->Y')
query <- 'Y[M=M[X=0], X=1]==1'
get_query_types(model, query, map= "causal_type")
#>
#> Causal types satisfying query's condition(s)
#>
#> query = Y[M=M[X=0],X=1]==1
#>
#> X0.M00.Y0100 X1.M00.Y0100
#> X0.M01.Y0100 X1.M01.Y0100
#> X0.M00.Y1100 X1.M00.Y1100
#> X0.M01.Y1100 X1.M01.Y1100
#> X0.M00.Y0110 X1.M00.Y0110
#> X0.M01.Y0110 X1.M01.Y0110
#> X0.M00.Y1110 X1.M00.Y1110
#> X0.M01.Y1110 X1.M01.Y1110
#> X0.M10.Y0001 X1.M10.Y0001
#> X0.M11.Y0001 X1.M11.Y0001
#> X0.M10.Y1001 X1.M10.Y1001
#> X0.M11.Y1001 X1.M11.Y1001
#> X0.M00.Y0101 X1.M00.Y0101
#> X0.M10.Y0101 X1.M10.Y0101
#> X0.M01.Y0101 X1.M01.Y0101
#> X0.M11.Y0101 X1.M11.Y0101
#> X0.M00.Y1101 X1.M00.Y1101
#> X0.M10.Y1101 X1.M10.Y1101
#> X0.M01.Y1101 X1.M01.Y1101
#> X0.M11.Y1101 X1.M11.Y1101
#> X0.M10.Y0011 X1.M10.Y0011
#> X0.M11.Y0011 X1.M11.Y0011
#> X0.M10.Y1011 X1.M10.Y1011
#> X0.M11.Y1011 X1.M11.Y1011
#> X0.M00.Y0111 X1.M00.Y0111
#> X0.M10.Y0111 X1.M10.Y0111
#> X0.M01.Y0111 X1.M01.Y0111
#> X0.M11.Y0111 X1.M11.Y0111
#> X0.M00.Y1111 X1.M00.Y1111
#> X0.M10.Y1111 X1.M10.Y1111
#> X0.M01.Y1111 X1.M01.Y1111
#> X0.M11.Y1111 X1.M11.Y1111
#>
#>
#> Number of causal types that meet condition(s) = 64
#> Total number of causal types in model = 128
query <- '(Y[X = 1, M = 1] > Y[X = 0, M = 1]) &
(Y[X = 1, M = 0] > Y[X = 0, M = 0])'
get_query_types(model, query, "causal_type")
#>
#> Causal types satisfying query's condition(s)
#>
#> query = (Y[X=1,M=1]>Y[X=0,M=1])&
#> (Y[X=1,M=0]>Y[X=0,M=0])
#>
#> X0.M00.Y0101 X1.M00.Y0101
#> X0.M10.Y0101 X1.M10.Y0101
#> X0.M01.Y0101 X1.M01.Y0101
#> X0.M11.Y0101 X1.M11.Y0101
#>
#>
#> Number of causal types that meet condition(s) = 8
#> Total number of causal types in model = 128
query <- 'Y[X=1] == Y[X=0]'
get_query_types(model, query, "causal_type")
#>
#> Causal types satisfying query's condition(s)
#>
#> query = Y[X=1]==Y[X=0]
#>
#> X0.M00.Y0000 X1.M00.Y0000
#> X0.M10.Y0000 X1.M10.Y0000
#> X0.M01.Y0000 X1.M01.Y0000
#> X0.M11.Y0000 X1.M11.Y0000
#> X0.M10.Y1000 X1.M10.Y1000
#> X0.M11.Y1000 X1.M11.Y1000
#> X0.M01.Y0100 X1.M01.Y0100
#> X0.M11.Y0100 X1.M11.Y0100
#> X0.M00.Y1100 X1.M00.Y1100
#> X0.M11.Y1100 X1.M11.Y1100
#> X0.M00.Y0010 X1.M00.Y0010
#> X0.M01.Y0010 X1.M01.Y0010
#> X0.M10.Y0110 X1.M10.Y0110
#> X0.M01.Y0110 X1.M01.Y0110
#> X0.M00.Y1110 X1.M00.Y1110
#> X0.M10.Y1110 X1.M10.Y1110
#> X0.M00.Y0001 X1.M00.Y0001
#> X0.M10.Y0001 X1.M10.Y0001
#> X0.M10.Y1001 X1.M10.Y1001
#> X0.M01.Y1001 X1.M01.Y1001
#> X0.M00.Y1101 X1.M00.Y1101
#> X0.M01.Y1101 X1.M01.Y1101
#> X0.M00.Y0011 X1.M00.Y0011
#> X0.M11.Y0011 X1.M11.Y0011
#> X0.M01.Y1011 X1.M01.Y1011
#> X0.M11.Y1011 X1.M11.Y1011
#> X0.M10.Y0111 X1.M10.Y0111
#> X0.M11.Y0111 X1.M11.Y0111
#> X0.M00.Y1111 X1.M00.Y1111
#> X0.M10.Y1111 X1.M10.Y1111
#> X0.M01.Y1111 X1.M01.Y1111
#> X0.M11.Y1111 X1.M11.Y1111
#>
#>
#> Number of causal types that meet condition(s) = 64
#> Total number of causal types in model = 128
query <- '(X == 1) & (M==1) & (Y ==1) & (Y[X=0] ==1)'
get_query_types(model, query, "causal_type")
#>
#> Causal types satisfying query's condition(s)
#>
#> query = (X==1)&(M==1)&(Y==1)&(Y[X=0]==1)
#>
#> X1.M01.Y1001 X1.M01.Y1101
#> X1.M11.Y0011 X1.M01.Y1011
#> X1.M11.Y1011 X1.M11.Y0111
#> X1.M01.Y1111 X1.M11.Y1111
#>
#>
#> Number of causal types that meet condition(s) = 8
#> Total number of causal types in model = 128
query <- '(Y[X = .]==1)'
get_query_types(model, query, "causal_type")
#> Generated expanded expression:
#> (Y[X=0]==1 | Y[X=1]==1)
#>
#> Causal types satisfying query's condition(s)
#>
#> query = (Y[X=0]==1|Y[X=1]==1)
#>
#> X0.M00.Y1000 X1.M00.Y1000
#> X0.M01.Y1000 X1.M01.Y1000
#> X0.M00.Y0100 X1.M00.Y0100
#> X0.M10.Y0100 X1.M10.Y0100
#> X0.M00.Y1100 X1.M00.Y1100
#> X0.M10.Y1100 X1.M10.Y1100
#> X0.M01.Y1100 X1.M01.Y1100
#> X0.M10.Y0010 X1.M10.Y0010
#> X0.M11.Y0010 X1.M11.Y0010
#> X0.M00.Y1010 X1.M00.Y1010
#> X0.M10.Y1010 X1.M10.Y1010
#> X0.M01.Y1010 X1.M01.Y1010
#> X0.M11.Y1010 X1.M11.Y1010
#> X0.M00.Y0110 X1.M00.Y0110
#> X0.M10.Y0110 X1.M10.Y0110
#> X0.M11.Y0110 X1.M11.Y0110
#> X0.M00.Y1110 X1.M00.Y1110
#> X0.M10.Y1110 X1.M10.Y1110
#> X0.M01.Y1110 X1.M01.Y1110
#> X0.M11.Y1110 X1.M11.Y1110
#> X0.M01.Y0001 X1.M01.Y0001
#> X0.M11.Y0001 X1.M11.Y0001
#> X0.M00.Y1001 X1.M00.Y1001
#> X0.M01.Y1001 X1.M01.Y1001
#> X0.M11.Y1001 X1.M11.Y1001
#> X0.M00.Y0101 X1.M00.Y0101
#> X0.M10.Y0101 X1.M10.Y0101
#> X0.M01.Y0101 X1.M01.Y0101
#> X0.M11.Y0101 X1.M11.Y0101
#> X0.M00.Y1101 X1.M00.Y1101
#> X0.M10.Y1101 X1.M10.Y1101
#> X0.M01.Y1101 X1.M01.Y1101
#> X0.M11.Y1101 X1.M11.Y1101
#> X0.M10.Y0011 X1.M10.Y0011
#> X0.M01.Y0011 X1.M01.Y0011
#> X0.M11.Y0011 X1.M11.Y0011
#> X0.M00.Y1011 X1.M00.Y1011
#> X0.M10.Y1011 X1.M10.Y1011
#> X0.M01.Y1011 X1.M01.Y1011
#> X0.M11.Y1011 X1.M11.Y1011
#> X0.M00.Y0111 X1.M00.Y0111
#> X0.M10.Y0111 X1.M10.Y0111
#> X0.M01.Y0111 X1.M01.Y0111
#> X0.M11.Y0111 X1.M11.Y0111
#> X0.M00.Y1111 X1.M00.Y1111
#> X0.M10.Y1111 X1.M10.Y1111
#> X0.M01.Y1111 X1.M01.Y1111
#> X0.M11.Y1111 X1.M11.Y1111
#>
#>
#> Number of causal types that meet condition(s) = 96
#> Total number of causal types in model = 128
# }