## regular IV case
graph <- initialize_graph(graph_from_literal(Z -+ X, X -+ Y, Ur -+ X, Ur -+ Y))
iv_model <- create_causalmodel(graph, prob.form = list(out = c("X", "Y"), cond = "Z"))
# with monotonicity
iv_model_mono <- create_causalmodel(graph, prob.form = list(out = c("X", "Y"), cond = "Z"),
constraints = list("X(Z = 1) >= X(Z = 0)"))
#showing the use of right.vars
b <- initialize_graph(graph_from_literal(Ul -+ X -+ Y -+ Y2, Ur -+ Y, Ur -+ Y2))
V(b)$latent <- c(1, 0, 1, 0, 1)
respvars <- create_response_function(b)
create_causalmodel(graph = b, constraints = "Y2(Y = 1) >= Y2(Y = 0)",
p.vals = expand.grid(X = 0:1, Y2 = 0:1),
prob.form = list(out = "Y2", cond = "X"))
## need to specify right.vars because it cannot be inferred from the response functions alone
create_causalmodel(graph = NULL, respvars = respvars,
constraints = "Y2(Y = 1) >= Y2(Y = 0)",
p.vals = expand.grid(X = 0:1, Y2 = 0:1),
prob.form = list(out = "Y2", cond = "X"),
right.vars = c("Y", "Y2"))
Run the code above in your browser using DataLab