Learn R Programming

gRain (version 0.3.0)

ctab: Representation of and operations on multidimensional tables

Description

General representation of multidimensional tables (by ctab objects). Operations on these include multiplication, division and marginalization.

Usage

ctab(varNames, nLevels, values = 1, normalize = c("none", "first", "all"), smooth = 0)
ctabop(t1, t2, op="*")ctabmarg(t1, marg, normalize=FALSE)

## S3 method for class 'ptab':
varNames(x)
## S3 method for class 'ptab':
nLevels(x)
## S3 method for class 'ptab':
valueLabels(x)

Arguments

varNames
Names of variables defining table
nLevels
Levels of variables
values
Table values
t1,t2,x
Objects of class "ptab"
op
Operation to perform. Either "*" or "/" (where 0/0=0)
marg
Set of nodes to marginalize onto
normalize
Should result be normalized, see 'Details' below.
smooth
Should values be smoothed, see 'Details' below.

Value

  • All ctab functions return an object of class ctab.

Details

A ctab object represents a table defined by a set of variables and their levels, together with the values of the table. E.g. f(a,b,c) can be a table with a,b,c representing levels of binary variable If normalize="first" then for each configuration of the parents, "pa", the probabilities are normalized to sum to one. Thus f(a,b,c) becomes a conditional probability table of the form p(a|b,c). If normalize="all" then the sum over all entries of f(a,b,c) is one. If smooth is non--zero then zero entries of values are replaced with smooth before normalization takes place.

See Also

cpt

Examples

Run this code
t1 <- ctab(c("gender","answer"),list(c('male','female'),c('yes','no')), values=1:4)
t2 <- ctab(c("answer","category"), list(c('yes','no'),c(1,2)), values=1:4+10)
t3 <- ctab(c("category","foo"), c(2,2), values=1:4+100)

varNames(t1)
nLevels(t1)
valueLabels(t1)

ctabop(t1,t2, "*")
ctabop(t1,t2, "/")

tgender <- ctabmarg(t1, "gender")
t1
tgender
ctabop(t1,tgender,"/")

Run the code above in your browser using DataLab