0
votes

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)

When I apply

bn.gs = gs(marks)

bn.gs or even bn.hc, it says that:

"Error in matrix(c(x$d, x$pi, x$sigma, x$rho), ncol = 1) : 'data' must be of a vector type, was 'NULL'"

It seems it has problem with my data type, which is exactly the same as book. What can I do?

1
I cant reproduce this. Can you add the results of sessionInfo() to your question please. Also does the problem persist on a new R session? - user20650
I fail to reproduce this (3.3.1, Win7). Are you sure those three lines are the ones you're using at the start of a new session, and the error comes after running the last one? - Jonathan Carroll
@user20650 > sessionInfo() R version 3.3.1 (2016-06-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 - GulfChanter
@JonathanCarroll, yes I exactly use: rm(list=ls(all=TRUE)) >library(bnlearn) > data(marks) >bn.gs = gs(marks) >print(bn.gs) & I added the sessionInfo() as well - GulfChanter
@GulfChanter and which line causes the error? - Jonathan Carroll

1 Answers

0
votes

I can't reproduce this, but I'm hoping we can figure out what's happening because you appear to be on the same setup as I am. I'm posting this as an answer so that code shows up, but I'll modify this to the answer once we get there.

Please try:

devtools::install_github("jennybc/reprex")
library(reprex)

copy this code to your clipboard (e.g. CTRL+C)

library(bnlearn)
data(marks)
bn.gs = gs(marks)
bn.gs

then type

reprex(venue = "so")

and paste the output. You should get something like the following if it works (and should fail if it's not a reproducible error)

library(bnlearn)
data(marks)
bn.gs = gs(marks)
bn.gs
#> 
#>   Bayesian network learned via Constraint-based methods
#> 
#>   model:
#>     [undirected graph]
#>   nodes:                                 5 
#>   arcs:                                  6 
#>     undirected arcs:                     6 
#>     directed arcs:                       0 
#>   average markov blanket size:           2.40 
#>   average neighbourhood size:            2.40 
#>   average branching factor:              0.00 
#> 
#>   learning algorithm:                    Grow-Shrink 
#>   conditional independence test:         Pearson's Correlation 
#>   alpha threshold:                       0.05 
#>   tests used in the learning procedure:  44 
#>   optimized:                             TRUE