Learn R Programming

gRain (version 1.4.1)

querygrain: Query a network

Description

Query an independence network, i.e. obtain the conditional distribution of a set of variables - possibly (and typically) given finding (evidence) on other variables.

Usage

querygrain(
  object,
  nodes = nodeNames(object),
  type = "marginal",
  evidence = NULL,
  exclude = TRUE,
  normalize = TRUE,
  simplify = FALSE,
  result = "array",
  details = 0
)

Value

A list of tables with potentials.

Arguments

object

A grain object.

nodes

A vector of nodes; those nodes for which the (conditional) distribution is requested.

type

Valid choices are "marginal" which gives the marginal distribution for each node in nodes; "joint" which gives the joint distribution for nodes and "conditional" which gives the conditional distribution for the first variable in nodes given the other variables in nodes.

evidence

An alternative way of specifying findings (evidence), see examples below.

exclude

If TRUE then nodes on which evidence is given will be excluded from nodes (see above).

normalize

Should the results be normalized to sum to one.

simplify

Should the result be simplified (to a dataframe) if possible.

result

If "data.frame" the result is returned as a data frame (or possibly as a list of dataframes).

details

Debugging information

Author

Søren Højsgaard, sorenh@math.aau.dk

References

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/.

See Also

setEvidence, getEvidence, retractEvidence, pEvidence

Examples

Run this code

testfile <- system.file("huginex", "chest_clinic.net", package = "gRain")
chest <- loadHuginNet(testfile, details=0)
qb <- querygrain(chest)
qb

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

Run the code above in your browser using DataLab