8
$\begingroup$

I've been trying to teach myself about Network Analysis, and I've been able to develop DAG charts in R. However, I've looked through three or four R packages and have seen little in the way to a function to generate joint probabilities for the network. The DAG plot tells me about the variables in relation to one another, but I'm more curious about the probabilities and haven't found a way to do that in R. If anything, there seem to be a lot of packages dedicated to generating plots or focused on inference, and I want to know how I can get the probabilities for the networks.

library("bnlearn")
library("Rgraphviz")

dat=data.frame(won=c(1,0,0,1,0,0), sold=c(0,0,0,1,0,0), insured=c(0,0,1,0,0,1), 
               credit=c("POOR","FAIR","GOOD","FAIR","FAIR","GOOD"))
dat$won = factor(dat$won)
dat$sold = factor(dat$sold)
dat$insured = factor(dat$insured)
dat$credit = factor(dat$credit) 

highlight.opts <- list(nodes = c("won","sold","insured","credit"),
                       col = "red", fill = "grey")
bn.hc <- hc(dat, score = "aic")
graphviz.plot(bn.hc, highlight=highlight.opts)
$\endgroup$
0

1 Answer 1

2
$\begingroup$

I think everything is in the function bn.fit. Following up on your code, I got

> bn.fit(bn.hc, dat)

  Bayesian network parameters

  Parameters of node won (multinomial distribution)

Conditional probability table:

        0         1 
0.6666667 0.3333333 

  Parameters of node sold (multinomial distribution)

Conditional probability table:

    won
sold   0   1
   0 1.0 0.5
   1 0.0 0.5

  Parameters of node insured (multinomial distribution)

Conditional probability table:

       won
insured   0   1
      0 0.5 1.0
      1 0.5 0.0

  Parameters of node credit (multinomial distribution)

Conditional probability table:

      insured
credit    0    1
  FAIR 0.75 0.00
  GOOD 0.00 1.00
  POOR 0.25 0.00
$\endgroup$
1
  • $\begingroup$ +1 Thanks! However, I can see how this approach could get out of hand if the Bayesian Network had 5+ nodes and arc. $\endgroup$
    – ATMathew
    Commented Sep 25, 2012 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.