old_grain_evidence.Rd
Set, update and remove evidence.
setEvidence(
object,
nodes = NULL,
states = NULL,
evidence = NULL,
propagate = TRUE,
details = 0
)
retractEvidence(object, nodes = NULL, propagate = TRUE)
absorbEvidence(object, propagate = TRUE)
getEvidence(object, short = TRUE)
pEvidence(object, evidence = NULL)
A "grain" object
A vector of nodes.
A vector of states (of the nodes given by 'nodes'). Now deprecated; use argument 'evidence' instead.
A list of name=value. See examples below.
Should the network be propagated?
Debugging information
If TRUE a dataframe with a summary is returned; otherwise a list with all details.
A list of tables with potentials.
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/.
example("example_chest_cpt")
#>
#> exmp__> yn <- c("yes", "no")
#>
#> exmp__> a <- cpt(~asia, values=c(1,99),levels=yn)
#>
#> exmp__> t.a <- cpt(~tub|asia, values=c(5,95,1,99),levels=yn)
#>
#> exmp__> s <- cpt(~smoke, values=c(5,5), levels=yn)
#>
#> exmp__> l.s <- cpt(~lung|smoke, values=c(1,9,1,99), levels=yn)
#>
#> exmp__> b.s <- cpt(~bronc|smoke, values=c(6,4,3,7), levels=yn)
#>
#> exmp__> e.lt <- cpt(~either|lung:tub,values=c(1,0,1,0,1,0,0,1),levels=yn)
#>
#> exmp__> x.e <- cpt(~xray|either, values=c(98,2,5,95), levels=yn)
#>
#> exmp__> d.be <- cpt(~dysp|bronc:either, values=c(9,1,7,3,8,2,1,9), levels=yn)
#>
#> exmp__> chest_cpt <- list(a, t.a, s, l.s, b.s, e.lt, x.e, d.be)
#>
#> exmp__> ## bn <- grain(compile_cpt(chest_cpt))
#> exmp__>
#> exmp__>
#> exmp__>
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()
#> nodes is_hard hard_state evi_weight
#> 1 asia TRUE yes 1, 0
#> 2 xray TRUE yes 1, 0
bn3 |> evidence_get()
#> nodes is_hard hard_state evi_weight
#> 1 asia FALSE <NA> 0.8, 0.1
#> 2 xray TRUE yes 1, 0
bn2 |> evidence_prob()
#> [1] 0.001450925
bn3 |> evidence_prob()
#> [1] 0.01204465
bn2 |> evidence_drop("xray")
#> Independence network: Compiled: TRUE Propagated: TRUE Evidence: TRUE
bn3 |> evidence_drop("xray")
#> Independence network: Compiled: TRUE Propagated: TRUE Evidence: TRUE
bn2 |> evidence_drop("xray") |> evidence_get()
#> nodes is_hard hard_state evi_weight
#> 1 asia TRUE yes 1, 0
#> 2 xray TRUE yes 1, 0
bn3 |> evidence_drop("xray") |> evidence_get()
#> nodes is_hard hard_state evi_weight
#> 1 asia FALSE <NA> 0.8, 0.1
#> 2 xray TRUE yes 1, 0
## 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()
#> nodes is_hard hard_state evi_weight
#> 1 asia TRUE yes 1, 0
#> 2 xray TRUE yes 1, 0
bb3 |> getEvidence()
#> nodes is_hard hard_state evi_weight
#> 1 asia FALSE <NA> 0.8, 0.2
#> 2 xray TRUE yes 1, 0
bb2 |> retractEvidence("xray")
#> Independence network: Compiled: TRUE Propagated: TRUE Evidence: TRUE
bb3 |> retractEvidence("xray")
#> Independence network: Compiled: TRUE Propagated: TRUE Evidence: TRUE
bb2 |> pEvidence()
#> [1] 0.001450925
bb3 |> pEvidence()
#> [1] 0.02292856
bb2 |> retractEvidence("xray") |> getEvidence()
#> nodes is_hard hard_state evi_weight
#> 1 asia TRUE yes 1, 0
#> 2 xray TRUE yes 1, 0
bb3 |> retractEvidence("xray") |> getEvidence()
#> nodes is_hard hard_state evi_weight
#> 1 asia FALSE <NA> 0.8, 0.2
#> 2 xray TRUE yes 1, 0