Learn R Programming

BayesNetBP (version 1.0.1)

FactorQuery: Queries of discrete variable distributions

Description

Obtain the joint, marginal, and conditional distributions of discrete variables

Usage

FactorQuery(tree, vars = c(), mode = c("joint", "conditional", "list"))

Arguments

tree

a clustertree object

vars

the variables to be queried

mode

type of desired distribution

Value

data.frame object specifying a joint or conditional distribution.

Details

Query the joint distribution of any combination of discrete variables when mode is "joint", or conditional distribution of a discrete variable. The mode "list" return a list of variable combinations, such that joint distributions of any subset of them are ready for extraction. Queries outside this list are also supported but may take longer computing time. This function will also return marginal distribution if only one variable is queried.

References

Cowell, R. G. (2005). Local propagation in conditional Gaussian Bayesian networks. Journal of Machine Learning Research, 6(Sep), 1517-1550.

Examples

Run this code

data(chest)
dag <- chest$dag
node.class <- rep(TRUE, length(dag@nodes))
names(node.class) <- dag@nodes
cst <- ClusterTreeCompile(dag, node.class)
models <- LocalModelCompile(chest$data, dag, node.class)
tree.init <- ElimTreeInitialize(tree=cst$tree.graph, 
                                dag=cst$dag, 
                                model=models, 
                                node.sets=cst$cluster.sets, 
                                node.class=cst$node.class)
tree.init.p <- PropagateDBN(tree.init)
# get joint distribution
FactorQuery(tree=tree.init.p, vars=c("tub", "xray", "dysp", "asia"), mode="joint")

# get joint distribution
FactorQuery(tree=tree.init.p, vars=c("xray"), mode="conditional")

Run the code above in your browser using DataLab