Set joint evidence in grain objects

Description

Setting and removing joint evidence in grain objects.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 class '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.

Note

All the joint evidence functionality should be used *with great care*.

Author(s)

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. http://www.jstatsoft.org/v46/i10/.

See Also

setFinding getFinding retractFinding pFinding

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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)

## End(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)

## End(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 )