# [R] contingency tables in R

Patrick Ball lookout_20005 at yahoo.com
Sun Apr 15 22:59:50 CEST 2001

```Dear List:

Most of the analysis I do involves contingency tables.
I am migrating to R from Stata and I have a number of
questions about using contingency tables in R.  I
suspect that most of the things I want to do are very
short R scripts that people on this list probably
have.  I wonder if you would be willing to share them.

First, the presentation of tables by table() is not
analysis-ready.  Is there a way to output the table
with the marginals, by cell, row or column
proportions,  with the test statistics (especially the
chi^2 and the log-likelihood chi^2), residuals, cross
product, and odds ratio?

I also like to make tables that have summary
statistics of a given variable in the columns (mean,
s.d., etc.)  with each row being the value for a sub
group of the data.  How do you do this in R?

The most complicated piece of this is contingency
tables done with sample data.  The sampling involves
several strata with different sampling weights.
Calculating the cell (or row or column) probabilities
is relatively easy, but the other statistics can be
complicated (the design effect, the finite population
correction, the various chi^2s, and the standard
errors and confidence intervals). Also, I sometimes
make these tables with summary statistics in place of
counts or population proportions.

Is there any way to do this stuff in R without hacking
it all myself?

Best.

- PB

Patrick Ball, PhD.
Deputy Director
AAAS Science and Human Rights Program
http://shr.aaas.org

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```