Crosstable: Cross-tabulation

Description Usage Arguments Value See Also Examples

Description

Crosstable produces all possible two-way and three-way tabulations of variables.

Usage

1
2
3
4
5
6
7
Crosstable(..., digits = 2, chisq = FALSE, fisher = FALSE,
  mcnemar = FALSE, latex = FALSE, alt = "two.sided", deparse.level = 2)

## Default S3 method:
Crosstable(..., digits = 2, chisq = FALSE,
  fisher = FALSE, mcnemar = FALSE, alt = "two.sided", latex = FALSE,
  deparse.level = 2)

Arguments

digits

number of digits after the decimal point.

chisq

if TRUE, the results of a chi-square test will be shown below the table.

fisher

if TRUE, the results of a Fisher Exact test will be shown below the table.

mcnemar

if TRUE, the results of a McNemar test will be shown below the table.

latex

if the output is to be printed in latex format.

alt

the alternative hypothesis and must be one of "two.sided", "greater" or "less". Only used in the 2 by 2 case.

deparse.level

an integer controlling the construction of labels in the case of non-matrix-like arguments. If 0, middle 2 rownames, if 1, 3 rownames, if 2, 4 rownames (default).

...

the variables for the cross tabulation.

Value

A cross-tabulated object.

See Also

xtabs, Frequency, table, prop.table

Other Crosstables: summary.Crosstable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
with(titanic, Crosstable( SEX, AGE, SURVIVED))

#' # Agresti (2002), table 3.10, p. 106
# 1992 General Social Survey--Race and Party affiliation
gss <- data.frame(
   expand.grid(Race=c("black", "white"),
   party=c("dem", "indep", "rep")),
   count=c(103,341,15,105,11,405))

df <- gss[rep(1:nrow(gss), gss[["count"]]), ]

with(df, Crosstable(Race, party))

# Agresti (1990, p. 61f; 2002, p. 91) Fisher's Tea Drinker
 tea <- data.frame(
   expand.grid(poured=c("Yes", "No"),
   guess=c("Yes", "No")),
   count=c(3,1,1,3))

# nicer way of recreating long tables
data = Untable(tea, freq="count")

with(data, Crosstable(poured, guess, fisher=TRUE, alt="greater")) # fisher=TRUE

SciencesPo documentation built on May 29, 2017, 9:28 p.m.