Skip to contents

Realise outcomes for all causal types. Calculated by sequentially calculating endogenous nodes. If a do operator is applied to any node then it takes the given value and all its descendants are generated accordingly.

Usage

realise_outcomes(model, dos = NULL, node = NULL, add_rownames = TRUE)

Arguments

model

A causal_model. A model object generated by make_model.

dos

A named list. Do actions defining node values, e.g., list(X = 0, M = 1).

node

A character. An optional quoted name of the node whose outcome should be revealed. If specified all values of parents need to be specified via dos.

add_rownames

logical indicating whether to add causal types as rownames to the output

Value

A data.frame object of revealed data for each node (columns) given causal / nodal type (rows) .

Details

If a node is not specified all outcomes are realised for all possible causal types consistent with the model. If a node is specified then outcomes of Y are returned conditional on different values of parents, whether or not these values of the parents obtain given restrictions under the model.

realise_outcomes starts off by creating types (via get_nodal_types). It then takes types of endogenous and reveals their outcome based on the value that their parents took. Exogenous nodes outcomes correspond to their type.

Examples

# \donttest{
make_model("X -> Y") |>
  realise_outcomes()
#>      X Y
#> 0.00 0 0
#> 1.00 1 0
#> 0.10 0 1
#> 1.10 1 0
#> 0.01 0 0
#> 1.01 1 1
#> 0.11 0 1
#> 1.11 1 1

make_model("X -> Y <- W") |>
set_restrictions(labels = list(X = "1", Y="0010"), keep = TRUE) |>
 realise_outcomes()
#>          W X Y
#> 0.1.0010 0 1 1
#> 1.1.0010 1 1 0

make_model("X1->Y; X2->M; M->Y") |>
realise_outcomes(dos = list(X1 = 1, M = 0))
#>             X1 X2 M Y
#> 0.0.00.0000  1  0 0 0
#> 1.0.00.0000  1  0 0 0
#> 0.1.00.0000  1  1 0 0
#> 1.1.00.0000  1  1 0 0
#> 0.0.10.0000  1  0 0 0
#> 1.0.10.0000  1  0 0 0
#> 0.1.10.0000  1  1 0 0
#> 1.1.10.0000  1  1 0 0
#> 0.0.01.0000  1  0 0 0
#> 1.0.01.0000  1  0 0 0
#> 0.1.01.0000  1  1 0 0
#> 1.1.01.0000  1  1 0 0
#> 0.0.11.0000  1  0 0 0
#> 1.0.11.0000  1  0 0 0
#> 0.1.11.0000  1  1 0 0
#> 1.1.11.0000  1  1 0 0
#> 0.0.00.1000  1  0 0 0
#> 1.0.00.1000  1  0 0 0
#> 0.1.00.1000  1  1 0 0
#> 1.1.00.1000  1  1 0 0
#> 0.0.10.1000  1  0 0 0
#> 1.0.10.1000  1  0 0 0
#> 0.1.10.1000  1  1 0 0
#> 1.1.10.1000  1  1 0 0
#> 0.0.01.1000  1  0 0 0
#> 1.0.01.1000  1  0 0 0
#> 0.1.01.1000  1  1 0 0
#> 1.1.01.1000  1  1 0 0
#> 0.0.11.1000  1  0 0 0
#> 1.0.11.1000  1  0 0 0
#> 0.1.11.1000  1  1 0 0
#> 1.1.11.1000  1  1 0 0
#> 0.0.00.0100  1  0 0 1
#> 1.0.00.0100  1  0 0 1
#> 0.1.00.0100  1  1 0 1
#> 1.1.00.0100  1  1 0 1
#> 0.0.10.0100  1  0 0 1
#> 1.0.10.0100  1  0 0 1
#> 0.1.10.0100  1  1 0 1
#> 1.1.10.0100  1  1 0 1
#> 0.0.01.0100  1  0 0 1
#> 1.0.01.0100  1  0 0 1
#> 0.1.01.0100  1  1 0 1
#> 1.1.01.0100  1  1 0 1
#> 0.0.11.0100  1  0 0 1
#> 1.0.11.0100  1  0 0 1
#> 0.1.11.0100  1  1 0 1
#> 1.1.11.0100  1  1 0 1
#> 0.0.00.1100  1  0 0 1
#> 1.0.00.1100  1  0 0 1
#> 0.1.00.1100  1  1 0 1
#> 1.1.00.1100  1  1 0 1
#> 0.0.10.1100  1  0 0 1
#> 1.0.10.1100  1  0 0 1
#> 0.1.10.1100  1  1 0 1
#> 1.1.10.1100  1  1 0 1
#> 0.0.01.1100  1  0 0 1
#> 1.0.01.1100  1  0 0 1
#> 0.1.01.1100  1  1 0 1
#> 1.1.01.1100  1  1 0 1
#> 0.0.11.1100  1  0 0 1
#> 1.0.11.1100  1  0 0 1
#> 0.1.11.1100  1  1 0 1
#> 1.1.11.1100  1  1 0 1
#> 0.0.00.0010  1  0 0 0
#> 1.0.00.0010  1  0 0 0
#> 0.1.00.0010  1  1 0 0
#> 1.1.00.0010  1  1 0 0
#> 0.0.10.0010  1  0 0 0
#> 1.0.10.0010  1  0 0 0
#> 0.1.10.0010  1  1 0 0
#> 1.1.10.0010  1  1 0 0
#> 0.0.01.0010  1  0 0 0
#> 1.0.01.0010  1  0 0 0
#> 0.1.01.0010  1  1 0 0
#> 1.1.01.0010  1  1 0 0
#> 0.0.11.0010  1  0 0 0
#> 1.0.11.0010  1  0 0 0
#> 0.1.11.0010  1  1 0 0
#> 1.1.11.0010  1  1 0 0
#> 0.0.00.1010  1  0 0 0
#> 1.0.00.1010  1  0 0 0
#> 0.1.00.1010  1  1 0 0
#> 1.1.00.1010  1  1 0 0
#> 0.0.10.1010  1  0 0 0
#> 1.0.10.1010  1  0 0 0
#> 0.1.10.1010  1  1 0 0
#> 1.1.10.1010  1  1 0 0
#> 0.0.01.1010  1  0 0 0
#> 1.0.01.1010  1  0 0 0
#> 0.1.01.1010  1  1 0 0
#> 1.1.01.1010  1  1 0 0
#> 0.0.11.1010  1  0 0 0
#> 1.0.11.1010  1  0 0 0
#> 0.1.11.1010  1  1 0 0
#> 1.1.11.1010  1  1 0 0
#> 0.0.00.0110  1  0 0 1
#> 1.0.00.0110  1  0 0 1
#> 0.1.00.0110  1  1 0 1
#> 1.1.00.0110  1  1 0 1
#> 0.0.10.0110  1  0 0 1
#> 1.0.10.0110  1  0 0 1
#> 0.1.10.0110  1  1 0 1
#> 1.1.10.0110  1  1 0 1
#> 0.0.01.0110  1  0 0 1
#> 1.0.01.0110  1  0 0 1
#> 0.1.01.0110  1  1 0 1
#> 1.1.01.0110  1  1 0 1
#> 0.0.11.0110  1  0 0 1
#> 1.0.11.0110  1  0 0 1
#> 0.1.11.0110  1  1 0 1
#> 1.1.11.0110  1  1 0 1
#> 0.0.00.1110  1  0 0 1
#> 1.0.00.1110  1  0 0 1
#> 0.1.00.1110  1  1 0 1
#> 1.1.00.1110  1  1 0 1
#> 0.0.10.1110  1  0 0 1
#> 1.0.10.1110  1  0 0 1
#> 0.1.10.1110  1  1 0 1
#> 1.1.10.1110  1  1 0 1
#> 0.0.01.1110  1  0 0 1
#> 1.0.01.1110  1  0 0 1
#> 0.1.01.1110  1  1 0 1
#> 1.1.01.1110  1  1 0 1
#> 0.0.11.1110  1  0 0 1
#> 1.0.11.1110  1  0 0 1
#> 0.1.11.1110  1  1 0 1
#> 1.1.11.1110  1  1 0 1
#> 0.0.00.0001  1  0 0 0
#> 1.0.00.0001  1  0 0 0
#> 0.1.00.0001  1  1 0 0
#> 1.1.00.0001  1  1 0 0
#> 0.0.10.0001  1  0 0 0
#> 1.0.10.0001  1  0 0 0
#> 0.1.10.0001  1  1 0 0
#> 1.1.10.0001  1  1 0 0
#> 0.0.01.0001  1  0 0 0
#> 1.0.01.0001  1  0 0 0
#> 0.1.01.0001  1  1 0 0
#> 1.1.01.0001  1  1 0 0
#> 0.0.11.0001  1  0 0 0
#> 1.0.11.0001  1  0 0 0
#> 0.1.11.0001  1  1 0 0
#> 1.1.11.0001  1  1 0 0
#> 0.0.00.1001  1  0 0 0
#> 1.0.00.1001  1  0 0 0
#> 0.1.00.1001  1  1 0 0
#> 1.1.00.1001  1  1 0 0
#> 0.0.10.1001  1  0 0 0
#> 1.0.10.1001  1  0 0 0
#> 0.1.10.1001  1  1 0 0
#> 1.1.10.1001  1  1 0 0
#> 0.0.01.1001  1  0 0 0
#> 1.0.01.1001  1  0 0 0
#> 0.1.01.1001  1  1 0 0
#> 1.1.01.1001  1  1 0 0
#> 0.0.11.1001  1  0 0 0
#> 1.0.11.1001  1  0 0 0
#> 0.1.11.1001  1  1 0 0
#> 1.1.11.1001  1  1 0 0
#> 0.0.00.0101  1  0 0 1
#> 1.0.00.0101  1  0 0 1
#> 0.1.00.0101  1  1 0 1
#> 1.1.00.0101  1  1 0 1
#> 0.0.10.0101  1  0 0 1
#> 1.0.10.0101  1  0 0 1
#> 0.1.10.0101  1  1 0 1
#> 1.1.10.0101  1  1 0 1
#> 0.0.01.0101  1  0 0 1
#> 1.0.01.0101  1  0 0 1
#> 0.1.01.0101  1  1 0 1
#> 1.1.01.0101  1  1 0 1
#> 0.0.11.0101  1  0 0 1
#> 1.0.11.0101  1  0 0 1
#> 0.1.11.0101  1  1 0 1
#> 1.1.11.0101  1  1 0 1
#> 0.0.00.1101  1  0 0 1
#> 1.0.00.1101  1  0 0 1
#> 0.1.00.1101  1  1 0 1
#> 1.1.00.1101  1  1 0 1
#> 0.0.10.1101  1  0 0 1
#> 1.0.10.1101  1  0 0 1
#> 0.1.10.1101  1  1 0 1
#> 1.1.10.1101  1  1 0 1
#> 0.0.01.1101  1  0 0 1
#> 1.0.01.1101  1  0 0 1
#> 0.1.01.1101  1  1 0 1
#> 1.1.01.1101  1  1 0 1
#> 0.0.11.1101  1  0 0 1
#> 1.0.11.1101  1  0 0 1
#> 0.1.11.1101  1  1 0 1
#> 1.1.11.1101  1  1 0 1
#> 0.0.00.0011  1  0 0 0
#> 1.0.00.0011  1  0 0 0
#> 0.1.00.0011  1  1 0 0
#> 1.1.00.0011  1  1 0 0
#> 0.0.10.0011  1  0 0 0
#> 1.0.10.0011  1  0 0 0
#> 0.1.10.0011  1  1 0 0
#> 1.1.10.0011  1  1 0 0
#> 0.0.01.0011  1  0 0 0
#> 1.0.01.0011  1  0 0 0
#> 0.1.01.0011  1  1 0 0
#> 1.1.01.0011  1  1 0 0
#> 0.0.11.0011  1  0 0 0
#> 1.0.11.0011  1  0 0 0
#> 0.1.11.0011  1  1 0 0
#> 1.1.11.0011  1  1 0 0
#> 0.0.00.1011  1  0 0 0
#> 1.0.00.1011  1  0 0 0
#> 0.1.00.1011  1  1 0 0
#> 1.1.00.1011  1  1 0 0
#> 0.0.10.1011  1  0 0 0
#> 1.0.10.1011  1  0 0 0
#> 0.1.10.1011  1  1 0 0
#> 1.1.10.1011  1  1 0 0
#> 0.0.01.1011  1  0 0 0
#> 1.0.01.1011  1  0 0 0
#> 0.1.01.1011  1  1 0 0
#> 1.1.01.1011  1  1 0 0
#> 0.0.11.1011  1  0 0 0
#> 1.0.11.1011  1  0 0 0
#> 0.1.11.1011  1  1 0 0
#> 1.1.11.1011  1  1 0 0
#> 0.0.00.0111  1  0 0 1
#> 1.0.00.0111  1  0 0 1
#> 0.1.00.0111  1  1 0 1
#> 1.1.00.0111  1  1 0 1
#> 0.0.10.0111  1  0 0 1
#> 1.0.10.0111  1  0 0 1
#> 0.1.10.0111  1  1 0 1
#> 1.1.10.0111  1  1 0 1
#> 0.0.01.0111  1  0 0 1
#> 1.0.01.0111  1  0 0 1
#> 0.1.01.0111  1  1 0 1
#> 1.1.01.0111  1  1 0 1
#> 0.0.11.0111  1  0 0 1
#> 1.0.11.0111  1  0 0 1
#> 0.1.11.0111  1  1 0 1
#> 1.1.11.0111  1  1 0 1
#> 0.0.00.1111  1  0 0 1
#> 1.0.00.1111  1  0 0 1
#> 0.1.00.1111  1  1 0 1
#> 1.1.00.1111  1  1 0 1
#> 0.0.10.1111  1  0 0 1
#> 1.0.10.1111  1  0 0 1
#> 0.1.10.1111  1  1 0 1
#> 1.1.10.1111  1  1 0 1
#> 0.0.01.1111  1  0 0 1
#> 1.0.01.1111  1  0 0 1
#> 0.1.01.1111  1  1 0 1
#> 1.1.01.1111  1  1 0 1
#> 0.0.11.1111  1  0 0 1
#> 1.0.11.1111  1  0 0 1
#> 0.1.11.1111  1  1 0 1
#> 1.1.11.1111  1  1 0 1

# With node specified
make_model("X->M->Y") |>
realise_outcomes(node = "Y")
#>      M Y
#> 0.00 0 0
#> 1.00 1 0
#> 0.10 0 1
#> 1.10 1 0
#> 0.01 0 0
#> 1.01 1 1
#> 0.11 0 1
#> 1.11 1 1

make_model("X->M->Y") |>
realise_outcomes(dos = list(M = 1), node = "Y")
#>      M Y
#> 1.00 1 0
#> 1.10 1 0
#> 1.01 1 1
#> 1.11 1 1
# }