Rajinder
Rajinder

Reputation: 41

Computing dynamic bayesian networks using bnstruct

I am trying to compute a dynamic Bayesian network (DBN) using bnstruct library in R. The data used here for illustartion is seven variables over two time points.

Rep_1 <- c(0, 0, 13343.36, 13343.36, 0, 0, 0.00, 5.36, 0, 0.00, 0, 0.4, 0, 4.56)
Rep_2 <- c(0, 0, 10579.92, 10579.92, 0, 0, 5.76, 33.60, 0, 0.00, 0, 0.0, 0, 0.24)
Rep_3 <- c(0, 0, 11256.40, 11256.40, 0, 0, 68.04, 0.00, 0, 0.04, 0, 0.0, 0, 0.00)

expression <- rbind(Rep1, Rep2, Rep3)
colnames(expression) <- c("var1_t1", "var2_t1", "var3_t1", "var4_t1", "var5_t1", "var6_t1", "var7_t1", "var1_t2", "var2_t2", "var3_t2", "var4_t2", "var5_t2", "var6_t2", "var7_t2")

Then I created the BNDataset from it

dataset <- BNDataset(data = expression,  discreteness = rep(F, ncol(expression)), 
                 variables = colnames(expression), node.sizes = rep(3, ncol(expression)))

And finally computing the DBN using learn.dynamic.network from bnstruct

dbn <- learn.dynamic.network(dataset, num.time.steps = 2)

This gives the error

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': invalid number of intervals

I tried changing the expression to dataframe and matrix before applying BNDataset but nothing works.

Thanks in advance!

Upvotes: 1

Views: 421

Answers (1)

Alberto Franzin
Alberto Franzin

Reputation: 231

Package developer here. I cannot reproduce the error, and I've never seen it either. Apparently simpleError is a S3 object, while bnstruct uses S4. Maybe you loaded another package containing a method with a conflicting name?

However, in the MWE the learning in bnstruct will fail on the variables for which you have a single value observed, e.g. var1_t1 or var2_t1. If you have a larger dataset with more values it's probably going to be fine, otherwise the easiest thing to do is to remove those variables.

Upvotes: 2

Related Questions