data(learning.test)
res = hc(learning.test)
score(res, learning.test, type = "bde")
## let's see score equivalence in action!
res2 = set.arc(res, "B", "A")
score(res2, learning.test, type = "bde")
## K2 score on the other hand is not score equivalent.
score(res, learning.test, type = "k2")
score(res2, learning.test, type = "k2")
## BDe with a prior.
beta = data.frame(from = c("A", "D"), to = c("B", "F"),
prob = c(0.2, 0.5), stringsAsFactors = FALSE)
score(res, learning.test, type = "bde", prior = "cs", beta = beta)
## equivalent to logLik(res, learning.test)
score(res, learning.test, type = "loglik")
## equivalent to AIC(res, learning.test)
score(res, learning.test, type = "aic")
## custom score, computing BIC manually.
my.bic = function(node, parents, data, args) {
n = nrow(data)
if (length(parents) == 0) {
counts = table(data[, node])
nparams = dim(counts) - 1
sum(counts * log(counts / n)) - nparams * log(n) / 2
}#THEN
else {
counts = table(data[, node], configs(data[, parents, drop = FALSE]))
nparams = ncol(counts) * (nrow(counts) - 1)
sum(counts * log(prop.table(counts, 2))) - nparams * log(n) / 2
}#ELSE
}#MY.BIC
score(res, learning.test, type = "custom", fun = my.bic, by.node = TRUE)
score(res, learning.test, type = "bic", by.node = TRUE)
Run the code above in your browser using DataLab