merge.table: Table merging

View source: R/merging.R

merge.tableR Documentation

Table merging

Description

Merges similar rows and columns of a contingency table.

Usage

## S3 method for class 'table'
merge(
  x,
  bins = rep(2, length(ds)),
  ds = 1:length(dim(x)),
  cost = homogeneity,
  trace = 12
)

Arguments

x

a table

bins

the desired number of levels for each dimension being merged. a numeric vector, the same length as ds.

ds

a vector of dimensions to merge, either by name or number. default is all of them.

Details

The desired table dimensions are achieved by successively merging the two most similar slices. (Slice' generalizes row' and ‘column’ to higher-dimensional tables.) The distance between slices is measured according to the chi-square statistic. Merging two slices means adding together their counts, and concatenating their labels with a comma in between. If a dimension is ordered (according to dim.ordered), only adjacent slices are considered for merging, and their labels are concatenated with a dash in between.

Value

A merged table. The total count is the same as x. A merging trace is plotted which shows, for each merge, the chi-square distance of the slices which were merged. This is useful for determining the appropriate dimensions. An interesting number is one that directly precedes a sudden jump in the chi-square distance.

Author(s)

Tom Minka

See Also

sort_table, mosaicplot, linechart

Examples


i <- factor(c(1,1,2,2,3,3,4,4))
j <- factor(c(3,4,3,4,1,2,1,2))
x <- table(i,j)
#merge.table(x,c(2,2))

i <- factor(c(1,1,3,3,2,2,4,4))
j <- factor(c(2,4,2,4,1,3,1,3))
x <- table(i,j)
#merge.table(x,c(2,2))

# one ordered dimension
data(education)
#merge.table(education,c(3,2))

data(occupation)
#merge.table(occupation,c(3,4))


paulemms/datamining documentation built on March 1, 2023, 4:01 p.m.