The Nagarajan et al. book (Bayesian Networks in R, O'Reilly 2013, p. 35) says that when I take the marks dataset of the R bnlearn package and ask to learn structure using the grow-shrink implementation by writing
library(bnlearn)
data(marks)
bn.gs = gs(marks)
then I should obtain a directed graph:
model: [STAT][ANL|STAT][ALG|ANL:STAT][VECT|ALG] [MECH|VECT:ALG]
nodes: 5
arcs: 6
undirected arcs: 0
directed arcs: 6
Instead of that I get an undirected graph:
model: [undirected graph]
nodes: 5
arcs: 6
undirected arcs: 6
directed arcs: 0
Even when I add the option undirected=FALSE to the gs method, I still get the same result. What am I doing wrong? Or is there a bug in the R implementation? I have tried it both on my Mac and on a Debian machine, the result is the same...
The answer is provided by the authors on their Web site (which I just discovered): http://www.bnlearn.com/book-useR/
“page 35: bnlearn 3.2 and later versions are more picky about setting arc directions; as a result bn.gs is an undirected graph and must be extended into a DAG with cextend() to conclude the example.”
In other words, replace the last line of code by
bn.gs = cextend(gs(marks))
It is a pity that Springer does not provide a standard service for errata, as does, for example, O'Reilly. The authors of this book had to create their own Web site, and it took my some time to find it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With