Learn R Programming

gRain (version 1.0-3)

cptable: Create conditional probability tables (CPTs)

Description

Creates conditional probability tables of the form p(v|pa(v)).

Usage

cptable(v, levels=NULL, values = NULL, normalize = TRUE, smooth = 0)

Arguments

v
Specifications of the names in P(v|pa1,...pak). See section 'details' for information about the form of the argument.
values
Probabilities; recycled if necessary
normalize
See 'details' below.
smooth
See 'details' below.
levels
See 'details' below.

Value

  • If a gmData object is given, then 'cpt' returns an object of class 'ctab' (which is a general representation of a table). If no gmData object is given, then 'cpt' returns an object of class 'cptTemplate'. 'compileCPT' returns an object of class 'cptspec' (which is just a list with a special class attribute).

Details

If normalize=TRUE then for each configuration of the parents the probabilities are normalized to sum to one. If smooth is non--zero then zero entries of values are replaced with smooth before normalization takes place. Regarding the form of the argument v: To specify $P(a|b,c)$ one may write ~a|b+c or ~a+b+c or c("a","b","c"). Internally, the last form is used. Notice that the + operator is used as a separator only. The order of the variables is important so + does not commute.

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

andtable

Examples

Run this code
yn <- c("yes","no")
ynm <- c("yes","no","maybe")
a    <- cptable(~asia, values=c(1,99),levels=yn)
t.a  <- cptable(~tub+asia, values=c(5,95,1,99,1,999),levels=ynm)
d.a  <- cptable(~dia+asia, values=c(5,5,1,99,100,999),levels=ynm)
compileCPT(list(a,t.a,d.a))

Run the code above in your browser using DataLab