library(simDAG)
# some example DAG
dag <- empty_dag() +
node("death", type="binomial", parents=c("age", "sex"), betas=c(1, 2),
intercept=-10) +
node("age", type="rnorm", mean=10, sd=2) +
node("sex", parents="", type="rbernoulli", p=0.5) +
node("smoking", parents=c("sex", "age"), type="binomial",
betas=c(0.6, 0.2), intercept=-2)
# get adjacency matrix
dag2matrix(dag)
# get adjacency matrix using only the child nodes
dag2matrix(dag, include_root_nodes=FALSE)
## adding time-varying nodes
dag <- dag +
node_td("disease", type="time_to_event", parents=c("age", "smoking"),
prob_fun=0.01) +
node_td("cve", type="time_to_event", parents=c("age", "sex", "smoking",
"disease"),
prob_fun=0.001, event_duration=Inf)
# get adjacency matrix including all nodes
dag2matrix(dag, include_td_nodes=TRUE)
# get adjacency matrix including only time-constant nodes
dag2matrix(dag, include_td_nodes=FALSE)
# get adjacency matrix using only the child nodes
dag2matrix(dag, include_root_nodes=FALSE)
Run the code above in your browser using DataLab