| components_extract | R Documentation |
Extract list of conditional probability tables and list of clique potentials from data.
extract_cpt(data_, graph, smooth = 0) extract_pot(data_, graph, smooth = 0) extract_marg(data_, graph, smooth = 0) marg2pot(marg_rep) pot2marg(pot_rep) extractCPT(data_, graph, smooth = 0) extractPOT(data_, graph, smooth = 0) extractMARG(data_, graph, smooth = 0)
data_ |
A named array or a dataframe. |
graph |
An |
smooth |
See 'details' below. |
marg_rep |
An object of class |
pot_rep |
An object of class |
If smooth is non-zero then smooth is added
to all cell counts before normalization takes place.
extract_cpt: A list of conditional probability tables.
extract_pot: A list of clique potentials.
extract_marg: A list of clique marginals.
Søren Højsgaard, sorenh@math.aau.dk
Søren Højsgaard (2012). Graphical Independence Networks with the gRain Package for R. Journal of Statistical Software, 46(10), 1-26. https://www.jstatsoft.org/v46/i10/.
compileCPT, compilePOT,
grain
## 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 ## Not run: # 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) ## End(Not run)