Learn R Programming

gRain (version 1.4.5)

grain_evidence: Set, update and remove evidence.

Description

Set, update and remove evidence.

Usage

evidence_add(object, evidence, propagate = TRUE, details = 0)

evidence_get(object, short = TRUE)

evidence_drop(object, nodes = NULL, propagate = TRUE)

evidence_prob(object, evidence = NULL)

Value

A list of tables with potentials.

Arguments

object

A "grain" object

evidence

A list of name=value. See examples below.

propagate

Should the network be propagated?

details

Debugging information

short

If TRUE a dataframe with a summary is returned; otherwise a list with all details.

nodes

A vector of nodes.

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

setFinding, getFinding, retractFinding, pFinding

Examples

Run this code

example("grain")
chest_bn <- grain(compileCPT(chest_cpt))

bn2 <- chest_bn |> evidence_add(list(asia="yes", xray="yes"))
bn3 <- chest_bn |> evidence_add(list(asia=c(0.8, 0.1), xray="yes"))

bn2 |> evidence_get()
bn3 |> evidence_get()

bn2 |> evidence_prob()
bn3 |> evidence_prob()

bn2 |> evidence_drop("xray")
bn3 |> evidence_drop("xray")

bn2 |> evidence_drop("xray") |> evidence_get()
bn3 |> evidence_drop("xray") |> evidence_get()


## For backward compatibility these functions are available now but
# may be deprecated later.
bb2 <- setEvidence(chest_bn, c("asia", "xray"), c("yes", "yes"))
bb3 <- setEvidence(chest_bn, c("asia", "xray"), list(c(0.8, 0.2), "yes"))
bb4 <- setFinding(chest_bn, c("asia", "xray"), c("yes", "yes"))

bb2 |> getEvidence()
bb3 |> getEvidence()

bb2 |> retractEvidence("xray")
bb3 |> retractEvidence("xray")

bb2 |> pEvidence()
bb3 |> pEvidence()

bb2 |> retractEvidence("xray") |> getEvidence()
bb3 |> retractEvidence("xray") |> getEvidence()

Run the code above in your browser using DataLab