Learn R Programming

gRain (version 1.3-0)

set-jevidence: Set joint evidence in grain objects

Description

Setting and removing joint evidence in grain objects.

Usage

setJEvi(object, evidence = NULL, propagate = TRUE, details = 0)

insertJEvi(evi.list, pot, hostclique)

retractJEvi(object, items = NULL, propagate = TRUE, details = 0)

new_jev(ev, levels)

# S3 method for grain_jev print(x, ...)

Arguments

object

A "grain" object

evidence

A list of evidence. Each element is a named array.

propagate

Should the network be propagated?

details

Debugging information

evi.list

A "grain_jev" object.

pot

A list of clique potentials (a potential is an array).

hostclique

A numerical vector indicating in which element of 'pot' each eviendence item in 'evi.list' should be inserted in.

items

Items in the evidence list to be removed. Here, NULL means remove everything, 0 means nothing is removed. Otherwise items is a numeric vector.

ev

A named list.

levels

A named list.

x

A "grain_jev" object.

...

Additional arguments; currently not used.

References

S<U+00F8>ren H<U+00F8>jsgaard (2012). Graphical Independence Networks with the gRain Package for R. Journal of Statistical Software, 46(10), 1-26. http://www.jstatsoft.org/v46/i10/.

See Also

setFinding getFinding retractFinding pFinding

Examples

Run this code
# NOT RUN {
example("grain")

uni <- list(asia = c("yes", "no"), tub = c("yes", "no"),
            smoke = c("yes", "no"), lung = c("yes", "no"),
            bronc = c("yes", "no"), either = c("yes", "no"),
            xray = c("yes", "no"), dysp = c("yes", "no"))

ev <- list(tab("asia", levels=uni, values=c(1,0)),
           tab("dysp", levels=uni, values=c(1,0)),
           tab(c("dysp","bronc"), levels=uni, values=c(.1, .2, .9, .8)) )

bn2 <- setJEvi(bn, evidence=ev)
bn2

## Notice: The evidence is defined on (subsets of) cliques of the junction tree
# and therefore evidence can readily be absorbed:
getgrain(bn, "rip")$cliques  %>% str

## On the other hand, below evidence is not defined cliques of the
# junction tree and therefore evidence can not easily be absorbed.
# Hence this will fail:

# }
# NOT RUN {
ev.fail <- list(tab(c("dysp","smoke"), levels=uni, values=c(.1, .2, .9, .8)) )
setJEvi(bn, evidence=ev.fail)
# }
# NOT RUN {
## Evidence can be removed with

retractJEvi(bn2)    ## All evidence removed.
retractJEvi(bn2, 0) ## No evidence removed.
retractJEvi(bn2, 1:2) ## Evidence items 1 and 2 are removed.

## Setting additional joint evidence to an object where joint
# evidence already is set will cause an error. Hence this will fail:
# }
# NOT RUN {
  ev2 <- list(smoke="yes")
  setJEvi(bn2, evidence=ev2)
# }
# NOT RUN {
## Instead we can do
new.ev <- c( getEvidence(bn2), list(smoke="yes") )
setJEvi( bn, evidence=new.ev )


## Create joint evidence object:

db <- parray(c("dysp","bronc"), list(yn,yn), values=c(.1,.2,.9,.8))
db
ev   <- list(asia=c(1,0), dysp="yes", db)

uni <- list(asia = c("yes", "no"), tub = c("yes", "no"),
  smoke = c("yes", "no"), lung = c("yes", "no"),
  bronc = c("yes", "no"), either = c("yes", "no"),
  xray = c("yes", "no"), dysp = c("yes", "no"))

jevi <- new_jev( ev, levels=uni )
jevi


bn3 <- setJEvi( bn, evidence=jevi)
evidence( bn3 )

# }

Run the code above in your browser using DataLab