# [R] how to solve a simple discrete Bayesian Belief Network?

Marcio Pupin Mello mello at ieee.org
Wed Sep 28 14:03:31 CEST 2011

```Can somebody save-me? Thanks in advance!

#R script:
#trying to find out how solve a discrete Bayesian Belief Network.
#option: using 'catnet' package

#BEGIN
library(catnet)
cnet <- cnNew(nodes = c("a", "b", "c"), cats = list(c("1", "2"),
c("1", "2"), c("1", "2")), parents = list(NULL, c(1), c(1,
2)), probs = list(c(0.2, 0.8), list(c(0.6, 0.4), c(0.4, 0.6)),
list(list(c(0.3, 0.7), c(0.7, 0.3)), list(c(0.9, 0.1), c(0.1,
0.9)))))

#what is the probability of a="1"?
cnNodeMarginalProb(cnet,node=1)
#0.2

#what is the probability of b="2"?
cnNodeMarginalProb(cnet,node=2)
#0.56

#what is the probability of c="1"?
cnNodeMarginalProb(cnet,node=3)
#0.428

#but how can I answer questions like:

#what is the probability of a="1" given that c="1"? i.e. P(a="1"|c="1")?

#or what is the probability of a="1" given that b="2" and c="1"? i.e.
P(a="1"|b="2",c="1")?
#END

--
Marcio Pupin Mello

Survey Engineer
PhD candidate in Remote Sensing
National Institute for Space Research (INPE) - Brazil
Laboratory of Remote Sensing in Agriculture and Forestry (LAF)
www.dsr.inpe.br/~mello

```