Marginalize and condition in multidimensional array.

Description

Marginalize and condition in a multidimensional array which is assumed to represent a discrete multivariate distribution.

Usage

1
ardist(tab, marg = NULL, cond = NULL, normalize = TRUE)

Arguments

tab

Multidimensional array with dimnames.

marg

A specification of the desired margin; a character vector, a numeric vector or a right hand sided formula.

cond

A specification of what is conditioned on. Can take two forms: Form one is a a character vector, a numeric vector or a right hand sided formula. Form two is as a simple slice of the array, which is a list of the form var1=value1, var2=value2 etc.

normalize

Should the result be normalized to sum to 1.

Value

A multidimensional array.

Note

ardist is a recent addition and its functionality (and name) may change. ardist is based on calling arMarg and arSlice.

Author(s)

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

See Also

newar, armarg, arslice etc.

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
33
34
35
36
37
38
39
40
41
hec <- HairEyeColor

is.named.array( hec )
## We need dimnames, and names on the dimnames

## Marginalize:
ardist(hec, marg= ~Hair + Eye)
ardist(hec, marg= ~Hair:Eye)
ardist(hec, marg= c("Hair", "Eye"))
ardist(hec, marg= 1:2)

ardist(hec, marg= ~Hair + Eye, normalize=FALSE)

## Condition
ardist(hec, cond= ~Sex + Hair)
ardist(hec, cond= ~Sex:Hair)
ardist(hec, cond= c("Sex", "Hair"))
ardist(hec, cond= c(3,1))

ardist(hec, cond= list(Hair="Black"))
ardist(hec, cond= list(Hair=1))

## Not run: 
## This will fail
ardist(hec, cond= list(Hair=c("Black", "Brown")))
ardist(hec, cond= list(Hair=1:2))

## End(Not run)
## But this will do the trick
a <- arslice(hec, slice=list(Hair=c("Black", "Brown")))
ardist(a, cond=~Hair)

## Combined
ardist(hec, marg=~Hair+Eye, cond=~Sex)
ardist(hec, marg=~Hair+Eye, cond="Sex")

ardist(hec, marg=~Hair+Eye, cond=list(Sex="Male"))
ardist(hec, marg=~Hair+Eye, cond=list(Sex="Male"), normalize=FALSE)

ardist(hec, cond=list(Sex="Male"))
ardist(hec, cond=list(Sex="Male"), normalize=FALSE)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.