parray: Representation of and operations on multidimensional tables

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/parray.R

Description

General representation of multidimensional tables (by parray objects).

Usage

1
2
3
parray(varNames, levels, values = 1, normalize = "none", smooth = 0)
as.parray(values, normalize="none", smooth=0)
data2parray(data, varNames=NULL, normalize="none", smooth=0)

Arguments

varNames

Names of variables defining table; can be a right hand sided formula.

levels

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

values

Values to go into the parray

normalize

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

smooth

Should values be smoothed, see 'Details' below.

data

A dataframe, a table, an xtabs (a cross classified contingency table) a matrix (with dimnames) or a vector (with dimnames).

Details

A parray 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 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). If normalize="all" then the sum over all entries of f(a,b,c) is one.

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

as.parray can be used for coercing an array or an xtabs to a parray object.

Value

An object of class parray.

Author(s)

S<f8>ren H<f8>jsgaard, sorenh@math.aau.dk

See Also

tableOp, tableMargin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
t1 <- parray(c("gender","answer"), list(c('male','female'),c('yes','no')), values=1:4)
t1 <- parray(~gender:answer, list(c('male','female'),c('yes','no')), values=1:4)
t1 <- parray(~gender:answer, c(2,2), values=1:4)

t2 <- parray(c("answer","category"), list(c('yes','no'),c(1,2)), values=1:4+10)
t3 <- parray(c("category","foo"), c(2,2), values=1:4+100)

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


## Create 1-dimensional vector with dim and dimnames
x1 <- 1:5
as.parray(x1)
x2 <- parray("x", levels=length(x1), values=x1)
dim(x2)
dimnames(x2)

## Matrix
x1 <- matrix(1:6, nrow=2)
as.parray(x1)
parray(~a:b, levels=dim(x1), values=x1)

## Extract parrays from data
## 1) a dataframe
data(cad1) 
data2parray(cad1, ~Sex:AngPec:AMI)
data2parray(cad1, c("Sex","AngPec","AMI"))
data2parray(cad1, c(1,2,3))
## 2) a table
data2parray(UCBAdmissions,c(1,2), normalize="first")

gRbase documentation built on May 2, 2019, 4:51 p.m.