Alternative ways of creating arrays

tabNew(names, levels, values, normalize = "none", smooth = 0)

Arguments

names

Names of variables defining table; either a character vector or a right hand sided formula.

levels
  1. a list with specification of the levels of the factors in names or 2) a vector with number of levels of the factors in names. See 'examples' below.

values

values to go into the array.

normalize

Either "none", "first" or "all". Should result be normalized, see 'Details' below.

smooth

Should values be smoothed, see 'Details' below.

Value

An array.

Details

  1. If normalize="first" then for each configuration of all other variables than the first, 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).

  2. If normalize="all" then the sum over all entries of f(a,b,c) is one.

  3. If smooth is positive then smooth is added to values BEFORE normalization takes place.

Author

Søren Højsgaard, sorenh@math.aau.dk

Examples


universe <- list(gender=c('male', 'female'),
                 answer=c('yes', 'no'),
                 rain=c('yes', 'no'))
t1 <- tabNew(c("gender", "answer"), levels=universe, values=1:4)
t1
#>         answer
#> gender   yes no
#>   male     1  3
#>   female   2  4
t2 <- tabNew(~gender:answer, levels=universe, values=1:4)
t2
#>         answer
#> gender   yes no
#>   male     1  3
#>   female   2  4
t3 <- tabNew(~gender:answer, c(2, 2), values=1:4)
t3
#>       answer
#> gender 1 2
#>      1 1 3
#>      2 2 4