Tools for categorical variables

The examples below use a different data set: Click minarets or within R

Frequency tables and graphics depicting frequency tables

Several functions produce simple crosstabulations (contingency tables); table, ftable, xtabs.

Producing tables containing only frequencies (counts):

Proportions computed from a table of counts:

CrossTable (package {gmodels})

CrossTable produces crosstabs similar to the ones produced in the past by SPSS or SAS. By default the table cells show counts, chi-square contributions, row, column and total proportions (default, SAS) or percentages (SPSS format).

The following values can be displays in the cells (shown with default values)

prop.r=TRUErow proportions/percentages
prop.c=TRUEcolumn proportions
prop.t=TRUEtotal proportions
prop.chisq=TRUEcontribution to chi-square
expected=FALSEexpected value
sresid=FALSEstandardized residual
asresid=FALSE,adjusted standardized residual
Summary statistics: tests and association coefficients

For 2x2 tables:

More coefficients:

descr package

The descr package provides similar functions but with some additional options.

Note for SPSS users: descr has several functions that help you to read/write SPSS label and missing value commands.

Graphics for categorical variables

See on-line documentation for titles and legends.

You will find most of these graphics in packagesPackages lattice and ggplot with many more options and control on how charts are produced and displayed. See the documentation for details.

Graphics for categorical variables with lattice
Graphics for categorical variables with package ggplot2
Related documents