I'm setting up the most simple of Bayesian Networks using 3.3.2 to 3.3.6 as a template. I used the following code,
library(bnlearn)
library(Rgraphviz)
dag <- empty.graph(nodes = c("T", "N"))
arc.set <- matrix(c("T", "N"),
byrow = TRUE, ncol = 2,
dimnames = list(NULL, c("from", "to")))
arcs(dag) <- arc.set
graphviz.plot(dag)
T.lv <- c("False", "True")
N.lv <- c("N.nL", "N.L")
T.prob <- array(c(0.9, 0.1), dim = 2, dimnames = list(T = T.lv))
N.prob <- array(c(0.9, 0.1), dim = 2, dimnames = list(N = N.lv))
cpt <- list(T = T.prob, N = N.prob)
bn <- custom.fit(dag, cpt, debug = TRUE)
and got the following error,
* processing node T .
> the node has class bn.fit.dnode .
* processing node N .
> found parents: T .
Error in check.dnode.rvalue.vs.parents(node, new = dist[[node]], parents = fitted[node.parents]) :
wrong number of parents for node N.
it appears to be such a simple error but I can't seem to fix it.
(For those who may be interested, I'm trying to apply bnlearn to the problems found in 'Risk Assessment and Decision Analysis with Bayesian Networks' by Fenton and Neil, 2013 p132)