finding.Rd
Set, retrieve, and retract finding in Bayesian network. NOTICE: The functions described here are kept only for backward compatibility; please use the corresponding evidence-functions in the future.
setFinding(object, nodes = NULL, states = NULL, flist = NULL, propagate = TRUE)
NOTICE: The functions described here are kept only for backward compatibility; please use the corresponding evidence-functions in the future:
setEvidence()
is an improvement of setFinding()
(and as such
setFinding
is obsolete). Users are recommended to use
setEvidence()
in the future.
setEvidence()
allows to specification of "hard evidence" (specific
values for variables) and likelihood evidence (also known as virtual
evidence) for variables.
The syntax of setEvidence()
may change in the future.
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/.
## setFindings
yn <- c("yes", "no")
a <- cpt(~asia, values=c(1, 99),levels=yn)
t.a <- cpt(~tub+asia, values=c(5, 95, 1, 99),levels=yn)
s <- cpt(~smoke, values=c(5,5), levels=yn)
l.s <- cpt(~lung+smoke, values=c(1, 9, 1, 99), levels=yn)
b.s <- cpt(~bronc+smoke, values=c(6, 4, 3, 7), levels=yn)
e.lt <- cpt(~either+lung+tub,values=c(1, 0, 1, 0, 1, 0, 0, 1),levels=yn)
x.e <- cpt(~xray+either, values=c(98, 2, 5, 95), levels=yn)
d.be <- cpt(~dysp+bronc+either, values=c(9, 1, 7, 3, 8, 2, 1, 9), levels=yn)
chest.cpt <- compileCPT(a, t.a, s, l.s, b.s, e.lt, x.e, d.be)
chest.bn <- grain(chest.cpt)
## These two forms are equivalent
bn1 <- setFinding(chest.bn, nodes=c("chest", "xray"), states=c("yes", "yes"))
bn2 <- setFinding(chest.bn, flist=list(c("chest", "yes"), c("xray", "yes")))
getFinding(bn1)
#> nodes is_hard hard_state evi_weight
#> 1 xray TRUE yes 1, 0
getFinding(bn2)
#> nodes is_hard hard_state evi_weight
#> 1 xray TRUE yes 1, 0
pFinding(bn1)
#> [1] 0.11029
pFinding(bn2)
#> [1] 0.11029
bn1 <- retractFinding(bn1, nodes="asia")
bn2 <- retractFinding(bn2, nodes="asia")
getFinding(bn1)
#> nodes is_hard hard_state evi_weight
#> 1 xray TRUE yes 1, 0
getFinding(bn2)
#> nodes is_hard hard_state evi_weight
#> 1 xray TRUE yes 1, 0
pFinding(bn1)
#> [1] 0.11029
pFinding(bn2)
#> [1] 0.11029