The package parental
provides lightweight tools
for creating, modifying network/graph objects. The
emphasis is on representing Bayesian Networks, so the
focus is on Directed Acyclic Graphs.
Constructors for objects: parental
,
bn
, bvsresponse
,
bvs
. Particular graphs:
complete
, empty
. Plotting:
grplot
. Properties: nNodes
,
nEdges
, indegrees
,
checkAcyclic
,
topologicallyOrder
, routes
.
Collections of objects: parental.list
,
bn.list
Conversion to/from other graph
objects: as.parental
, as.bn
.
Routes matrices: routes
,
routesAddEdge
,
routesRemoveEdge
Random Bayesian network:
sampleBN
Draw data from a Bayesian network:
simulate.bn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # A `bn` object is created by specifying the parents of each node.
x <- bn(c(2), c(), c(1, 2))
grplot(x)
# A `bn` object can be converted to an adjacency matrix
adj <- matrix(c(0, 0, 1, 1, 0, 0, 0, 0, 0), 3, 3)
x <- as.bn(adj)
grplot(x)
# A `bn` object can be converted to an adjacency matrix
x <- bn(c(2), c(), c(1, 2))
as.adjacency(x)
# Properties of a `bn`
x <- bn(c(2), c(), c(1, 2))
nNodes(x)
nEdges(x)
indegrees(x)
checkAcyclic(x)
topologicallyOrder(x)
# Manipulating `bn` objects
x <- bn(c(2), c(), c(1, 2))
# Fast, but less intuitive manipulation of `bn` objects
x <- bn(c(2), c(), c(1, 2))
x[[1]] <- c()
x
x[[2]] <- 1
x
# Sample a BN
sampleBN(10)
sampleBN(10, maxNumberParents = 2)
# An empty graph
empty(10, "bn")
# Enumerate all the Bayesian Networks
enumerateBNSpace(3)
# Tools for handling "routes matrices"
x <- bn(c(2), c(), c(1, 2))
routes(x)
# Simulate from a `bn`
cpt <- list(
as.table(array(c(0.7, 0.3), 2)),
as.table(array(c(0.5, 0.5, 0.2, 0.8), c(2, 2)))
)
net <- bn(c(), 1)
sim <- simulate(object = net, nsim = 1000, ptables = cpt)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.