Search code examples
rdynamicbayesian-networksbnlearn

Setting layers for a Dynamic Bayesian Network with bnstruct in R


I am currently creating a DBN using bnstruct package in R. I have 9 variables in each 6 time steps. I have biotic and abiotic variables. I want to prevent the biotic variables to be parents of the abiotic variables.For a Bayesian Network, it's pretty easy to implement using for instance layering = c(1,1,2,2,2) in learn.dynamic.network().

But a problem rises for the Dynamic part: I would like to keep preventing biotic variables to be parents of abiotic ones in every time step while preventing edges to appear between any variables from t+1 to t.

If I use in layering =:

  • 1 for abiotic variables at t1
  • 2 for biotic variables at t1
  • 3 for abiotic variables at t2
  • 4 for biotic variables at t2...

I allow biotic variables from t-1 to explain the abiotic variables at t (and I don't want that).

So I tried:

## 9 variables for 6 time steps 
test1 <- BNDataset(data = timedData,
                   discreteness = rep('d', 54),
                   variables = colnames(timedData),
                   node.sizes = rep(c(3,3,3,2,2,3,3,3,3), 6)
                   # num.time.steps = 6
                   )


## the 5 first variables are abiotic, the 4 last are biotics
dbn <- learn.dynamic.network(test1, 
                             num.time.steps = 6, 
                             layering = rep(c(1,1,1,1,1,2,2,2,2),6))

So now, I don't have any edges from biotic to abiotic (that's nice), but I have edges from variable_t(n+1) to variable_t(n).

I know that in bnlearn you can create a "blacklist" of edges that you don't want to see but I don't see any equivalent arguments in bnstruct. Any idea?


Solution

  • With the mmhc algorithm that is used as default, you can use the layer.struct parameter to specify which pairs of layers are allowed to have edges between them. layer.struct takes a binary matrix where cell i,j is 1 if there can be edges going from variables in layer i to variables in layer j, and 0 otherwise.

    The best way to use this is to combine it with the manually-specified layering of your first solution.