Learn R Programming

gRain (version 0.8.0)

cptable: Create conditional probability tables (CPTs)

Description

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

Usage

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

Arguments

v
A vertex
pa
The parents of vertex v
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.

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