help for tabchi, tabchii

Two-way tables of frequencies with chi-square and residuals

tabchi
rowvar colvar
[weight]
[if exp]
[in range]
[
,
raw
pearson
cont
adjust
noo
noe
tabdisp_options
]

tabchii
#11 #12 [...]
\
#21 #22 [...]
[\ ...]
[,
replace
raw
pearson
cont
adjust
noo
noe
tabdisp_options
]

Description

tabchi displays information derived from the r x
c table of frequencies for categorical variables rowvar and
colvar.

The display contains

row and column identifiers,

(by default) observed frequencies and expected frequencies on a
null hypothesis of no association between the row and column variables,

and (if desired)

raw residuals, observed - expected,

Pearson residuals, (observed - expected) / sqrt(expected),

contributions to chi-square, (observed - expected)^2 / expected

and adjusted residuals, Pearson residuals divided by an
estimate of their standard error.

The Pearson and likelihood-ratio chi-square statistics and
their P-values are also given.

tabchii displays the same information derived from the
r x c table using the counts or frequencies specified; rows
are separated by the backslash \.

Discussion

A chi-squared test for association of the row and column
variables in a two-way table of frequencies is featured in most first
courses in statistics. In Stata, this test is provided by the command
tabulate or the immediate command tabi. When tabchi
and tabchii were first published, tabulate and tabi
did not support output of expected (fitted, predicted) frequencies, but
that has been added since. As of 2020, neither official command allows
output of residuals. Most data analysts wish to glance at least briefly
at such results.

These commands supersede tab2i (Cox 1996), but the
account there remains pertinent.

The residuals produced by these commands come in two flavours.
First, Pearson residuals (also called standardized or chi-residuals) are
the (appropriately signed) square roots of each cell's contribution to
the Pearson chi-squared statistic. Under the null hypothesis, the
Pearson residuals approximately follow Gaussian (normal) distributions
with mean 0 and variance less than 1. Consequently, one rough rule of
thumb is to look especially carefully at any residual greater than 2 in
magnitude. Second, adjusted residuals are Pearson residuals divided by
an estimate of their standard error so that they are distributed more
like Gaussians with mean 0 and variance 1.

There are several other possible definitions of residuals in
the literature. For more information on this or other points, see a
standard text on categorical data analysis. For example, Gilbert (1993)
and Agresti (2019) assume a modest background in statistics, whereas
Bishop, Fienberg, and Holland (1975) and Agresti (2013) are more
advanced. Haberman (1973) is a key paper introducing adjusted residuals.

For more advanced work with two-way tables, you might use the
more general glm command, which allows many models other than
that of independence to be fitted and tested. On the other hand,
people not familiar with these methods might
find these commands more accessible at an elementary level.

Options

replace indicates that the variables listed by the
tabchii command are to be left as the current data in place of
whatever data were there.

raw, pearson, cont and adjust produce
displays of raw residuals, Pearson residuals, contributions to
chi-square and adjusted residuals respectively.

noo, noe suppress display of observed and expected
frequencies. These options may be useful when the focus is on
residuals. noo and noe without at least one of raw,
pearson, cont and adjust suppress the tabular display.

tabdisp_options are options of tabdisp other than
cellvar(), which may be used to tune the tabular display.

Examples

. sysuse auto, clear

. tabchi foreign rep78, adj

. tabchi foreign rep78, adj noo noe

Jacqueline Tivers (1985, p.173) interviewed 400 women with young
children in the London Borough of Merton in September 1977. In one
analysis, she looked at the cross-tabulation of the age at which women
finished full-time education (below 16, 16, 17-18, 19 or older) and
whether they used a library regularly. The table of frequencies did not
come with a chi-squared statistic or residuals.

. tabchii 124 21 \ 73 30 \ 55 29 \ 27 41

. tabchii 124 21 \ 73 30 \ 55 29 \ 27 41, replace

Saved results

tabchi and tabchii leave behind appropriate r-class
results produced by tabulate.

Author

Nicholas J. Cox, Durham University, U.K.

n.j.cox@durham.ac.uk

Acknowledgments

William Gould provided much help in the early development of
tabchi. Torbjorn Messner and Eric Zbinden pointed out bugs in
earlier versions of tabchi. Martyn Sherriff reported a bug in
tabchii.

References

Agresti, A. 2013. Categorical Data Analysis. Hoboken, NJ: John Wiley.

Agresti, A. 2019. An Introduction to Categorical Data Analysis. Hoboken, NJ: John Wiley.

Bishop, Y.M.M., S.E. Fienberg, and P.W. Holland. 1975. Discrete Multivariate Analysis. Cambridge, MA: MIT Press.

Cox, N.J. 1996. An immediate command for two-way tables. Stata Technical Bulletin 33: 7-9.

Gilbert, N. 1993. Analyzing Tabular Data: Loglinear and Logistic Models for Social Researchers. London: UCL Press.

Haberman, S.J. 1973. The analysis of residuals in cross-classified tables. Biometrics 29: 205-220.

Tivers, J. 1985. Women Attached: The Daily Lives of Women with Young Children. Beckenham, UK: Croom Helm.

Also see

Manual: [U] 19 Immediate commands, [R] glm, [R] tabdisp, [R] tabulate

On-line: help for immed, tabdisp, tabulate,
chitest (if installed)