Compute the score of the Bayesian network.
score(x, data, type = NULL, ..., by.node = FALSE, debug = FALSE)# S3 method for bn
logLik(object, data, ...)
# S3 method for bn
AIC(object, data, ..., k = 1)
# S3 method for bn
BIC(object, data, ...)
an object of class bn.
a data frame containing the data the Bayesian network that will be used to compute the score.
a character string, the label of a network score. If none is
specified, the default score is the Bayesian Information Criterion
for both discrete and continuous data sets. See
bnlearn-package for details.
a boolean value. If TRUE and the score is decomposable,
the function returns the score terms corresponding to each node; otherwise
it returns their sum (the overall score of x).
a boolean value. If TRUE a lot of debugging output is
printed; otherwise the function is completely silent.
extra arguments from the generic method (for the AIC and
logLik functions, currently ignored) or additional tuning parameters
(for the score function).
a numeric value, the penalty coefficient to be used; the default
k = 1 gives the expression used to compute the AIC in the context of
scoring Bayesian networks.
For score() with by.node = TRUE, a vector of numeric values, the
individual node contributions to the score of the Bayesian network.
Otherwise, a single numeric value, the score of the Bayesian network.
Additional arguments of the score() function:
iss: the imaginary sample size, used by the Bayesian Dirichlet
scores (bde, mbde, bds, bdj) and the Bayesian
Gaussian score (bge). It is also known as “equivalent sample
size”. The default value is equal to 1 for the Dirichlet scores and
10 for bge.
exp: a list of indexes of experimental observations (those that
have been artificially manipulated). Each element of the list must be
named after one of the nodes, and must contain a numeric vector with
indexes of the observations whose value has been manipulated for that node.
k: the penalty coefficient to be used by the AIC and BIC
scores. The default value is 1 for AIC and log(nrow(data))/2
for BIC.
phi: the prior phi matrix formula to use in the Bayesian
Gaussian equivalent (bge) score. Possible values are
heckerman (default) and bottcher (the one used by default
in the deal package.)
prior: the prior distribution to be used with the various
Bayesian Dirichlet scores (bde, mbde, bds) and the
Bayesian Gaussian score (bge). Possible values are uniform
(the default), vsp (the Bayesian variable selection prior, which
puts a probability of inclusion on parents), marginal (an
independent marginal uniform for each arc) and cs (the Castelo &
Siebes prior, which puts an independent prior probability on each arc
and direction).
beta: the parameter associated with prior.
If prior is uniform, beta is ignored.
If prior is vsp, beta is the probability of
inclusion of an additional parent. The default is 1/ncol(data).
If prior is marginal, beta is the probability
of inclusion of an arc. Each direction has a probability of inclusion
of beta / 2 and the probability that the arc is not included is
therefore 1 - beta. The default value is 0.5, so that
arc inclusion and arc exclusion have the same probability.
If prior is cs, beta is a data frame with
columns from, to and prob specifying the prior
probability for a set of arcs. A uniform probability distribution is
assumed for the remaining arcs.
Castelo R, Siebes A (2000). "Priors on Network Structures. Biasing the Search for Bayesian Networks". International Journal of Approximate Reasoning, 24(1), 39-57.
Chickering DM (1995). "A Transformational Characterization of Equivalent Bayesian Network Structures". In "UAI '95: Proceedings of the Eleventh Annual Conference on Uncertainty in Artificial Intelligence", pp. 87-98. Morgan Kaufmann.
Cooper GF, Yoo C (1999). "Causal Discovery from a Mixture of Experimental and Observational Data". In "UAI '99: Proceedings of the Fifteenth Annual Conference on Uncertainty in Artificial Intelligence", pp. 116-125. Morgann Kaufmann.
Geiger D, Heckerman D (1994). "Learning Gaussian Networks". In "UAI '94: Proceedings of the Tenth Annual Conference on Uncertainty in Artificial Intelligence", pp. 235-243. Morgann Kaufmann. Available as Technical Report MSR-TR-94-10.
Hausser J, Strimmer K (2009). "Entropy inference and the James-Stein estimator, with application to nonlinear gene association networks". Statistical Applications in Genetics and Molecular Biology, 10, 1469-1484.
Heckerman D, Geiger D, Chickering DM (1995). "Learning Bayesian Networks: The Combination of Knowledge and Statistical Data". Machine Learning, 20(3), 197-243. Available as Technical Report MSR-TR-94-09.
Suzuki J (2016). "A Theoretical Analysis of the BDeu Scores in Bayesian Network Structure Learning". Behaviormetrika, 44(1), 97-116.
Scutari M (2016). "An Empirical-Bayes Score for Discrete Bayesian Networks". Journal of Machine Learning Research, 52, 438-448.
Cano A and Gomez-Olmedo M and Masegosa AR and Moral S (2013). "Locally Averaged Bayesian Dirichlet Metrics for Learning the Structure and the Parameters of Bayesian Networks". International Journal of Approximate Reasoning, 54, 526-540.
# NOT RUN {
data(learning.test)
res = set.arc(gs(learning.test), "A", "B")
score(res, learning.test, type = "bde")
## let's see score equivalence in action!
res2 = set.arc(gs(learning.test), "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")
# }
Run the code above in your browser using DataLab