Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R bnlearn Grow-Shrink structure learning returns undirected graph

Tags:

r

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...

like image 361
yannis Avatar asked Feb 13 '23 21:02

yannis


1 Answers

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...

like image 177
yannis Avatar answered Feb 16 '23 11:02

yannis