2

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?

FrsLry
  • 348
  • 4
  • 19

2 Answers2

2

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.

Alberto Franzin
  • 221
  • 1
  • 6
2

Perfect, the combination of both arguments layering = and layer.struct = does what I wanted.

I post what I used here just to provide an example:

## DBN study
dbn <- learn.dynamic.network(test1, 
                             num.time.steps = 6, 
                             layering = rep(c(1,1,1,1,1,2,2,2,2,  # set 2 layers per time step
                                              3,3,3,3,3,4,4,4,4,
                                              5,5,5,5,5,6,6,6,6,
                                              7,7,7,7,7,8,8,8,8,
                                              9,9,9,9,9,10,10,10,10,
                                              11,11,11,11,11,12,12,12,12)),
                             layer.struct = matrix(c(1,0,0,0,0,0,0,0,0,0,0,0,  ## allow certain layers to connect to others by hand
                                                     1,1,0,0,0,0,0,0,0,0,0,0,
                                                     1,0,1,0,0,0,0,0,0,0,0,0,
                                                     1,1,1,1,0,0,0,0,0,0,0,0,
                                                     1,0,1,0,1,0,0,0,0,0,0,0,
                                                     1,1,1,1,1,1,0,0,0,0,0,0,
                                                     1,0,1,0,1,0,1,0,0,0,0,0,
                                                     1,1,1,1,1,1,1,1,0,0,0,0,
                                                     1,0,1,0,1,0,1,0,1,0,0,0,
                                                     1,1,1,1,1,1,1,1,1,1,0,0,
                                                     1,0,1,0,1,0,1,0,1,0,1,0,
                                                     1,1,1,1,1,1,1,1,1,1,1,1),c(12,12)))

Thanks for the quick answer and the package btw

FrsLry
  • 348
  • 4
  • 19