counterfactual {R6causal} | R Documentation |
Counterfactual inference via simulation
Description
Counterfactual inference via simulation
Usage
counterfactual(
scm,
situation,
n,
target = NULL,
ifunction = NULL,
method = NULL,
returnscm = FALSE,
control = NULL
)
Arguments
scm |
An SCM object |
situation |
A list or a character string. The list has the following elements:
|
n |
The number of rows in the data to be simulated |
target |
NULL or a vector of variable names that specify the target variable(s) of the counterfactual intervention. |
ifunction |
NULL or a list of functions for the counterfactual intervention. |
method |
The simulation method, "u_find", "rejection" or "analytic_linear_gaussian" |
returnscm |
A logical, should the internally created twin SCM or parallel world SCM returned? |
control |
List of parameters to be passed to the simulation method:
|
Value
A data table representing the situation after the counterfactual intervention
Examples
cfdata <- counterfactual(backdoor,
situation = list(
do = list(target = "x", ifunction = 0),
condition = data.table::data.table( x = 0, y = 0)),
target = "x",
ifunction = 1,
method = "rejection",
n = 1000)
mean(cfdata$y)
backdoor_parallel <- ParallelWorld$new(backdoor,
dolist=list(
list(target = "x", ifunction = 0),
list(target = list("z","x"), ifunction = list(1,0))
)
)
cfdata2 <- counterfactual(backdoor_parallel,
situation = list(
do = NULL,
condition = data.table::data.table( y = 0, y_1 = 0, y_2 = 0)),
target = "x",
ifunction = 1,
method = "rejection",
n = 1000)
mean(cfdata2$y)