crosstab {descr}R Documentation

Cross tabulation with mosaic plot

Description

This function is a wrapper for CrossTable, adding a mosaic plot and making it easier to do a weighted cross-tabulation.

Usage

crosstab(dep, indep, weight = NULL, digits = 3, max.width = NA, expected = FALSE,
         prop.r = FALSE, prop.c = FALSE, prop.t = FALSE, prop.chisq = FALSE,
         chisq = FALSE, fisher = FALSE, mcnemar = FALSE, resid = FALSE,
         sresid = FALSE, asresid = FALSE, missing.include = FALSE,
         drop.levels = TRUE, format = "SPSS", cell.layout = TRUE,
         dnn = NULL, xlab = NULL, ylab = NULL, main = "",
         user.missing.dep, user.missing.indep,
         plot = getOption("descr.plot"), ...)

Arguments

dep, indep

Vectors in a matrix or a dataframe. dep should be the dependent variable, and indep should be the independent one.

weight

An optional vector for a weighted cross tabulation.

digits

See CrossTable.

max.width

See CrossTable.

expected

See CrossTable.

prop.r

See CrossTable.

prop.c

See CrossTable.

prop.t

See CrossTable.

prop.chisq

See CrossTable.

chisq

See CrossTable.

fisher

See CrossTable.

mcnemar

See CrossTable.

resid

See CrossTable.

sresid

See CrossTable.

asresid

See CrossTable.

missing.include

See CrossTable.

drop.levels

See CrossTable.

format

See CrossTable.

cell.layout

See CrossTable.

dnn

See CrossTable.

xlab

See plot.default.

ylab

See plot.default.

main

An overall title for the plot (see plot.default and title).

user.missing.dep

An optional character vector with the levels of dep that should be treated as missing values.

user.missing.indep

An optional character vector with the levels of indep that should be treated as missing values.

plot

Logical: if TRUE (default), a mosaic plot is produced. You may put

options(descr.plot = FALSE)

in your ‘.Rprofile’ to change the default function behavior.

...

Further arguments to be passed to mosaicplot.

Details

crosstab invokes the CrossTable with all boolean options set to FALSE and "SPSS" as the default format option. The returned CrossTable object can be plotted as a mosaicplot. Note that the gray scale colors used by default in the mosaic plot do not have any statistical meaning. The colors are used only to ease the plot interpretation.

Author(s)

Jakson A. Aquino jalvesaq@gmail.com

See Also

CrossTable, plot.CrossTable, xtable.CrossTable.

Examples

educ <- sample(c(1, 2), 200, replace = TRUE, prob = c(0.3, 0.7))
educ <- factor(educ, levels = c(1, 2), labels = c("Low", "High"))
income <- sample(c(1, 2, 3), 200, replace = TRUE,
                 prob = c(0.3, 0.4, 0.3))
income <- factor(income, levels = c(1, 2, 3),
                 labels = c("Low", "Middle", "High"))
attr(educ, "label") <- "Education level"
attr(income, "label") <- "Income level"
w <- sample(c(10, 15, 19), 200, replace = TRUE)

crosstab(income, educ, xlab = "Income", ylab = "Education")
ct <- crosstab(income, educ, w, dnn = c("Income", "Education"),
               expected = TRUE, plot = FALSE)
ct
plot(ct, inv.y = TRUE)

library(xtable)
print(xtable(ct))

# Add to the preamble of your Rnoweb document:
# \usepackage{booktabs}
# \usepackage{multirow}
print(xtable(ct, decimal.mark = ",", multirow = TRUE, hline = TRUE),
      booktabs = TRUE, include.rownames = FALSE,
      sanitize.text.function = function(x) x)

[Package descr version 1.1.1 Index]