1

I have created a Bayesian network model using the library bnlearn. I would like to calculate the log-likelihood of the model. Could you please let me know how can I do this? Sample code for creation of model:

bn = bn.fit(net, train)
nationprob = sumnations / sumallnations
cpt = coef(bn[["UserLocation"]])
cpt[1:length(EUROPE)] = nationprob
bn[["UserLocation"]] = cpt
cpt = coef(bn[["FriendsLocation"]])
cpt[1:length(EUROPE)] = nationprob
bn[["FriendsLocation"]] = cpt
bn.pred = predict(bn, node = "scaledsci", data = test) 
tabl1 = table(bn.pred, test[, "scaledsci"])
mn = mean(bn.pred == test$scaledsci)
C. Peck
  • 3,641
  • 3
  • 19
  • 36
  • 1
    There is a `logLik` method for objects of type `bn` or `bn.fit`; so try `logLik(bn, train)`. If this doesn't work can you update your question with a small reproducible example please -- https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – user20650 May 22 '21 at 20:08
  • I voted to close this as the example is not reproducible, – user20650 Aug 29 '21 at 19:42

0 Answers0