0

I have got a Bayesian network with nodes X1 to X5 and a dataframe with states as follows:

   X1  X2  X3  X4  X5
   yes yes no  yes no
   yes no  no  yes no
   no  yes yes yes yes
   yes no  no  no  yes

   etc.

I want to calculate the joint probability of each row using the pEvidence function in gRain (after setting the evidence). However, it is very slow to iterate line by line. Is there a way to calculate these probabilities quicker?

Edit: This is what I've done:

     summation=apply(dataframe,1,function(x)log(pEvidence(setEvidence(empbayesnet,
                                                nodes=c("X1","X2","X3","X4","X5"), 
                                                states=c(as.character(x[1]),
                                                         as.character(x[2]),
                                                         as.character(x[3]),
                                                         as.character(x[4]),
                                                         as.character(x[5])))))  

'empbayesnet' is the bayesian network which I'd like to calculate the joint probability from. Thanks!

mackbox
  • 199
  • 5
  • What have you done so far, can you show us some code? [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – rcs Aug 23 '16 at 12:54
  • Hi @rcs, I have edited my question. Thanks! – mackbox Aug 23 '16 at 13:06

0 Answers0