164 Bayesian Networks: With Examples in R
> wl1 <- cbind(from = rep(co, each = 9), to = rep(vr, 5))
> dag2 <- hc(dtr, whitelist = wl1)
> paste(substr(modelstring(dag2), 1, 40), "...", sep = "")
[1] "[A][H][W|H][B|H:W][C|A:H:B][LB|A:H:W:C:B..."
As expected, the covariates are in the first positions in the topological
ordering of the DAG. To relax the constraints on the search, we can switch
from the whitelist wl1 to a blacklist preventing only unwanted arcs. In other
words, variables cannot be the parents of covariates but covariates are not
necessarily the parents of all the variables.
> bl1 <- wl1[, 2:1]
> dag3 <- hc(dtr, blacklist = bl1)
> paste(substr(modelstring(dag3), 1, 40), "...", sep = "")
[1] "[A][H][W|H][B|H:W][C|A:H:B][TF|C][AF|TF:..."
> all.equal(dag2, ...