count-tables: Count Similarly Margined Contingency Tables

count-tablesR Documentation

Count Similarly Margined Contingency Tables

Description

Count the number of contingency tables with the same marginals as a given table.

Usage

count_tables(
  table,
  A = hmat(dim(table), as.list(1:length(dim(table)))),
  dir = tempdir(),
  quiet = TRUE,
  cache = TRUE,
  ...
)

Arguments

table

the table of interest

A

the configuration/transpose design matrix

dir

directory to place the files in, without an ending /

quiet

show latte output

cache

use count (default) or fcount

...

arguments to pass to latte_count()

Details

count_tables uses LattE's count function (via latte's latte_count()) to count the tables. In many cases, the number of such tables is enormous. In these cases, instead of giving back an integer count_tables provides a character string with the integer in it; see examples.

Value

an integer

See Also

latte_count(), count_fiber()

Examples



if (has_latte()) {


data(politics); politics
count_tables(politics)
(A <- hmat(c(2,2), list(1, 2)))
count_tables(politics, A)



data(handy); handy
count_tables(handy)



data(HairEyeColor); HairEyeColor
eyeHairColor <- margin.table(HairEyeColor, 2:1)
count_tables(eyeHairColor)

system.time(count_tables(eyeHairColor)) # it was computed above
system.time(count_tables(eyeHairColor)) # it was computed above
system.time(count_tables(eyeHairColor, cache = FALSE))
system.time(count_tables(eyeHairColor, cache = FALSE))


library(gmp)
as.bigz(count_tables(eyeHairColor))



# notice that even tables with small cells can have huge fibers
data(drugs); drugs
count_tables(drugs)




# 0-1 tables can be very hard and produce very large fibers
# the 4x4 table below has 154 elements in its independence fiber
# the 5x5 has 16830, and the compute times are on the order of
# 1 and 10 seconds, respectively.
# the following block is omited for faster R check time
if (FALSE) {
set.seed(1)
n <- 5
tab <- matrix(sample(0:1, n^2, replace = TRUE), nrow = n)
dimnames(tab) <- list(X = paste0("x", 1:n), Y = paste0("y", 1:n))
tab
count_tables(tab)
}



count_tables(eyeHairColor, quiet = FALSE)



}


dkahle/algstat documentation built on May 23, 2023, 12:29 a.m.