table-operations: Compute table margin or table slice

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

Description

For a contingency table in array form, compute the sum of table entries for a given index (i.e. a marginal table) or find the slice of the table defined by specific margins being at a specific level.

Usage

1
2
3
4
5
6
tableOp(t1, t2, op = "*")
tableMult(t1, t2)
tableDiv(t1, t2) 
tableMargin(x, margin, keep.class=FALSE)
tableSlice(x, margin, level, impose)
tablePerm(a, perm, resize = TRUE, keep.class=FALSE) 

Arguments

x, t1, t2, a

An array

margin

An index, either numerical or character

keep.class

If TRUE the result will be forced to have the same class as the input; otherwise the result will be an array.

level

A value, either numerical or character

impose

Possible value used to fill up a slice to give it full dimension

op

Either "*" or "/"

perm

The subscript permutation vector, which must be a permutation of the integers 1:n, where n is the number of dimensions of a OR a permutation of the dimension names of a. The default is to reverse the order of the dimensions. A permutation of the dimensions of a.

resize

A flag indicating whether the vector should be resized as well as having its elements reordered.

Details

tableMargin: tableMargin is analogous to margin.table except that margin can be given both as array indices or as variable names

tableSlice: If the table x has dimensions Z,U,V where V has levels 1 and 2 then tableSlice can extract the slice of x (in this case a 2-way table) defined by e.g. U=2. Setting impose=1000 implies that a 3-way table is returned with the U=2 slice in the right place and the U=1-slice consisting of 1000 in each cell.

tableOp: If t1 has dimnames A and B and t2 has dimnames B and C then tableOp(t1,t2) will return a table (an array) with dimnames A, B and C containing the product.

tableMult(t1,t2) is a wrapper for tableOp(t1,t2, op="*") and tableMult(t1,t2) is a wrapper for tableDiv(t1,t2, op="/")

tablePerm: A wrapper for aperm, but tablePerm accepts dimnames in addition to indices.

See examples below.

Value

An array.

Author(s)

S<f8>ren H<f8>jsgaard

See Also

margin.table

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
data(HairEyeColor)

tableMargin(HairEyeColor, "Hair")
tableMargin(HairEyeColor, 1)
tableMargin(HairEyeColor, c("Hair","Eye"))
tableMargin(HairEyeColor, c(1,2))


tableSlice(HairEyeColor, "Sex","Male")
tableSlice(HairEyeColor, 3,1)
tableSlice(HairEyeColor, "Sex","Male", impose=1000)
tableSlice(HairEyeColor, 3,1, impose=1000)

t1 <- array(1:4, dim=c(2,2), dimnames=list(gender=c('male','female'),answer=c('yes','no')))
t2 <- array(1:4+10, dim=c(2,2), dimnames=list(answer=c('yes','no'),category=c(1,2)))

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

data(reinis)

t1 <- tableMargin(reinis, c(6,5,2,1))
t2 <- tableMargin(reinis, c(6,5,3,4))

tt1 <- tableOp(t1,t2)

t1 <- tableMargin(reinis, c(6,5,2,4,1))
t2 <- tableMargin(reinis, c(6,5,4))

tt1 <- tableOp2(t1,t2)

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