## Extract cpts / clique potentials from data and graph
# specification and create network. There are different ways:
data(lizard, package="gRbase")
# DAG: height <- species -> diam
daG <- dag(~species + height:species + diam:species, result="igraph")
# UG : [height:species][diam:species]
uG <- ug(~height:species + diam:species, result="igraph")
pt <- extract_pot(lizard, ~height:species + diam:species)
cp <- extract_cpt(lizard, ~species + height:species + diam:species)
pt
cp
# Both specify the same probability distribution
tabListMult(pt) |> as.data.frame.table()
tabListMult(cp) |> as.data.frame.table()
if (FALSE) {
# Bayesian networks can be created as
bn.uG <- grain(pt)
bn.daG <- grain(cp)
# The steps above are wrapped into a convenience method which
# builds a network from at graph and data.
bn.uG <- grain(uG, data=lizard)
bn.daG <- grain(daG, data=lizard)
}
Run the code above in your browser using DataLab