Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performing intervention in ver. 0.5.0 #5

Open
wilsoncai1992 opened this issue Mar 28, 2016 · 2 comments
Open

Performing intervention in ver. 0.5.0 #5

wilsoncai1992 opened this issue Mar 28, 2016 · 2 comments

Comments

@wilsoncai1992
Copy link

I am trying to perform a deterministic intervention on a DAG.

library(simcausal)
library(rje)
D <- DAG.empty()

D <- D +
  node("U1", distr="runif"
  )

D <- D +
  node("U2", distr="runif"
       )

D <- D +
  node("UA", distr="runif"
  )

D <- D +
  node("UY", distr="runif"
  )

D <- D +
  node("W1", distr="rconst",
       const = as.numeric(U1 < 0.5))

D <- D +
  node("W2", distr="rconst",
       const = as.numeric(U2 < 0.5))

D <- D +
  node("A", distr="rconst",
       const = as.numeric(UA < expit(-0.5 + W1 - 1.5 * W2)) )

D <- D +
  node("Y", distr="rconst",
       const = as.numeric(UY < expit(-0.75 + W1 - 2 * W2 + 2.5 * A + A*W1)),
       EFU = TRUE)

setDl2 <- set.DAG(D)
# ----------------------------------------------------------------------
plotDAG(setDl2, xjitter = 0.32, yjitter = 0.03,
        edge_attrs = list(width = 0.5, arrow.width = 0.4, arrow.size = 0.8),
        vertex_attrs = list(size = 19, label.cex = 1.5))
title(main = "SCM graph")
# ----------------------------------------------------------------------
# intervention
actN_A <- node("A",distr="rconst", const = theta)

D_act <- D + action("A_th0", nodes=actN_A, theta=0)
D_act <- D_act + action("A_th1", nodes=actN_A, theta=1)
D_act <- D_act + action("A_no_intervene", nodes=node("A", distr="rconst", const = as.numeric(UA < expit(-0.5 + W1 - 1.5 * W2)) ))

ate.data <- simfull(A(D_act), n=1e5 , rndseed = 252)

The D_act assignment fails to run under 0.5.0 while suceeds under 0.4.0. Could you please take a look when you have time?

@osofr
Copy link
Owner

osofr commented Mar 28, 2016

Thanks for pointing this out, this is very interesting.
This code should have given an error in the previous versions of the package as well. It was working, but it wasn't designed to work in this manner. Actions should only be added to DAGs returned from set.DAG() function, which checks the DAG object for consistency and errors. The above code is trying to add an action to a DAG object "D", rather than object "setDl2". Otherwise you are not using setDl2 anywhere in your code.

D_act <- setDl2 + action("A_th0", nodes=actN_A, theta=0)
D_act <- D_act + action("A_th1", nodes=actN_A, theta=1)
D_act <- D_act + action("A_no_intervene", nodes=node("A", distr="rconst", const = as.numeric(UA < expit(-0.5 + W1 - 1.5 * W2)) ))
ate.data <- simfull(A(D_act), n=1e5 , rndseed = 252)

The error message returned is non-informative and needs to be changed, so keeping this issue open.

@wilsoncai1992
Copy link
Author

Thank you for your timely reply! I overlooked the difference when I did it, since the class for both "D" and "setDl2" are both "DAG".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants