logical.Rd
Generate conditional probability tables based on the logical expressions AND and OR.
An array.
Regarding the form of the argument vpa
: To specify
\(P(a|b,c)\) one may write ~a|b+c
or ~a+b+c
or
~a|b:c
or ~a:b:c
or c("a","b","c")
.
Internally, the last form is used. Notice that the +
and
:
operator are used as separators only. The order of the
variables is important so +
and :
DO NOT commute.
andtable
and ortable
are aliases for
andtab
and ortab
and are kept for backward
compatibility.
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/.
## Logical OR:
## A variable v is TRUE if either of its parents pa1 and pa2 are TRUE:
ortab( c("v", "pa1", "pa2") ) |> ftable(row.vars="v")
#> pa1 TRUE FALSE
#> pa2 TRUE FALSE TRUE FALSE
#> v
#> TRUE 1 1 1 0
#> FALSE 0 0 0 1
## TRUE and FALSE can be recoded to e.g. yes and no:
ortab( c("v", "pa1", "pa2"), levels=c("yes", "no") ) |> ftable(row.vars="v")
#> pa1 yes no
#> pa2 yes no yes no
#> v
#> yes 1 1 1 0
#> no 0 0 0 1
## Logical AND:
## Same story here:
andtab(c("v", "pa1", "pa2") ) |> ftable(row.vars="v")
#> pa1 TRUE FALSE
#> pa2 TRUE FALSE TRUE FALSE
#> v
#> TRUE 1 0 0 0
#> FALSE 0 1 1 1
andtab(c("v", "pa1", "pa2"), levels=c("yes", "no") ) |> ftable(row.vars="v")
#> pa1 yes no
#> pa2 yes no yes no
#> v
#> yes 1 0 0 0
#> no 0 1 1 1
## Combined approach
booltab(c("v", "pa1", "pa2"), op=`&`) |> ftable(row.vars="v") ## AND
#> pa1 TRUE FALSE
#> pa2 TRUE FALSE TRUE FALSE
#> v
#> TRUE 1 0 0 0
#> FALSE 0 1 1 1
booltab(c("v", "pa1", "pa2"), op=`|`) |> ftable(row.vars="v") ## OR
#> pa1 TRUE FALSE
#> pa2 TRUE FALSE TRUE FALSE
#> v
#> TRUE 1 1 1 0
#> FALSE 0 0 0 1
booltab(~v + pa1 + pa2, op=`&`) |> ftable(row.vars="v") ## AND
#> pa1 TRUE FALSE
#> pa2 TRUE FALSE TRUE FALSE
#> v
#> TRUE 1 0 0 0
#> FALSE 0 1 1 1
booltab(~v + pa1 + pa2, op=`|`) |> ftable(row.vars="v") ## OR
#> pa1 TRUE FALSE
#> pa2 TRUE FALSE TRUE FALSE
#> v
#> TRUE 1 1 1 0
#> FALSE 0 0 0 1