Learn R Programming

gRain (version 1.3-0)

evidence-object: Evidence objects

Description

Functions for defining and manipulating evidence.

Usage

new_ev(evi.list = NULL, levels)

is.null_ev(object)

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

# S3 method for grain_ev varNames(x)

# S3 method for grain_ev as.data.frame(x, row.names = NULL, optional = FALSE, ...)

setdiff_ev(ev1, ev2)

union_ev(ev1, ev2)

Arguments

evi.list

A named list with evidence; see 'examples' below.

levels

A named list with the levels of all variables.

object

Some R object.

x

Evidence object

...

Not used.

row.names

Not used.

optional

Not used.

ev1, ev2

Evidence.

Details

Evidence is specified as a list. Internally, evidence is represented as a grain evidence object which is a list with 4 elements.

Examples

Run this code
# NOT RUN {
## Define the universe

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"))

e1 <- list(dysp="no", xray="no")
eo1 <- new_ev( e1, levels=uni )
eo1
as.data.frame( eo1 )
eo1 %>% str

e1.2 <- list(dysp="no", xray=c(0, 1))
eo1.2 <- new_ev( e1.2, levels=uni )
eo1.2

# Notice that in \code{eo1.2}, \code{xray} is not regarded as hard
# evidence but as a weight on each level. Other than that \code{eo1.2}
# and \code{eo1} are equivalent here. This is used in connection
# with specifying likelihood evidence. 

e2 <- list(dysp="yes", asia="yes")
eo2 <- new_ev(e2, uni)

# If evidence 'e1' is already set in the network and new evidence
# 'e2' emerges, the evidence in the network must be updated. But
# there is a conflict in that \code{dysp="yes"} in 'e1' and
# \code{dysp="no"} in 'e2'. The (arbitrary) convention is that
# existsting evidence overrides new evidence so that the only new
# evidence in 'e2' is really \code{asia="yes"}.

# To subtract existing evidence from new evidence we can do:
setdiff_ev( eo2, eo1 )

# Likewise the 'union' is
union_ev( eo2, eo1 )


# }

Run the code above in your browser using DataLab