| spbn | R Documentation |
Fits a semiparametric Bayesian network (Atienza et al., 2022)
to continuous data: every node has either a linear Gaussian conditional
density or a conditional kernel density estimate (CKDE) given its parents.
It is the density model of dfr_llr2().
spbn(data, structure = NULL, node_types = NULL, max_parents = 4, folds = 5)
data |
A data frame or matrix of numeric variables (no missing values). |
structure |
Optional structure: a named list giving the parents of
every variable ( |
node_types |
Optional named character vector of node types ( |
max_parents |
Largest number of parents of a node in the learned structure. |
folds |
Number of folds of the cross-validation used to choose the node types. |
Structure learning is a greedy hill climbing (arc addition, removal
and reversal) with the BIC score of a Gaussian Bayesian network. The type of
each node is then chosen given its parents: the type with the larger
log-likelihood over folds contiguous folds (each fold scored by the CPD
fitted on the other folds).
A linear Gaussian CPD is the least-squares regression of the node on its
parents with the maximum likelihood variance. A CKDE CPD is
f(x, pa) / f(pa), the ratio of Gaussian kernel density estimates with the
bandwidth matrix of the normal reference rule,
H = (4 / (d + 2))^(2 / (d + 4)) S N^(-2 / (d + 4)) (S the sample covariance
of the node and its parents, d their number, N the sample size); the
density of the parents uses the corresponding block of H, so the
conditional density integrates to one.
The paper uses the binned version (B-SPBN), which speeds up the kernel sums by binning the data on a grid, and learns the structure and the node types together by hill climbing with a cross-validated score. Here the kernel sums are exact and the node types are chosen after the structure.
An spbn object: the variables, their parents, node types and the
fitted CPDs.
Atienza, D., Bielza, C. and Larrañaga, P. (2022). Semiparametric Bayesian networks. Information Sciences, 584, 564-582. doi:10.1016/j.ins.2021.10.074
spbn_loglik(), dfr_llr2().
set.seed(1)
a <- stats::rnorm(500)
b <- 2 * a + stats::rnorm(500, sd = 0.5)
c <- ifelse(stats::runif(500) < 0.5, b - 3, b + 3) + stats::rnorm(500)
model <- spbn(data.frame(a, b, c))
model
colMeans(spbn_loglik(model, data.frame(a, b, c)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.