Learn R Programming

gRain (version 0.3.0)

querygm: Query an independence network

Description

Query an independence network, i.e. obtain the conditional distribution of a set of variables given evidence on other variables.

Usage

querygm(object, nodes = nodeNames(object), normalize = TRUE, type =
c("marginal", "joint", "conditional"), return="array", trace = 0)

enterEvidence(object, nodes=NULL, states=NULL, evlist=NULL, propagate=TRUE)
retractEvidence(object, nodes=NULL, propagate=TRUE)
evidence(object)
pevidence(object)

Arguments

object
A "gmInstance" object
nodes
A vector of nodes
states
A vector of states (of the nodes given by 'nodes')
evlist
An alternative way of specifying evidence, see examples below.
propagate
Should the network be propagated?
normalize
Should the results be normalized to sum to one.
type
Should marginals (for each node), the joint for all nodes, or the conditional of the first node given the rest be returned.
return
If "data.frame" the result is returned as a data frame (or possibly as a list of dataframes).
trace
Debugging information

Value

  • A list of tables with potentials

See Also

ctab, cpt

Examples

Run this code
testfile <- system.file("huginex", "chest_clinic.net", package = "gRain")
chest <- as.gmInstance(loadHuginNet(testfile, trace=1))
print(class(chest))


qb <- querygm(chest)
qb

lapply(qb, as.numeric) # Safe
sapply(qb, as.numeric) # Risky

Run the code above in your browser using DataLab