merge.table | R Documentation |
Merges similar rows and columns of a contingency table.
## S3 method for class 'table' merge( x, bins = rep(2, length(ds)), ds = 1:length(dim(x)), cost = homogeneity, trace = 12 )
x |
a |
bins |
the desired number of levels for each dimension being merged. a
numeric vector, the same length as |
ds |
a vector of dimensions to merge, either by name or number. default is all of them. |
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.
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.
Tom Minka
sort_table
, mosaicplot
,
linechart
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.