CrossTable {gregmisc} | R Documentation |
An implementation of a cross-tabulation function with output similar to S-Plus crosstabs() and SAS Proc Freq with Chi-square, Fisher and McNemar tests of the independence of all table factors.
CrossTable(x, y, digits=3, expected=FALSE, prop.r=TRUE, prop.c=TRUE, prop.t=TRUE, fisher=FALSE, mcnemar=FALSE)
x |
A vector in a matrix or a dataframe OR if y not specified, a two-dimensional matrix |
y |
A vector in a matrix or a dataframe |
digits |
Number of digits after the decimal point for cell proportions |
expected |
If TRUE , expected cell counts from the
Chi-Square will be included |
prop.r |
If TRUE , row proportions will be included |
prop.c |
If TRUE , column proportions will be included |
prop.t |
If TRUE , table proportions will be included |
fisher |
If TRUE , the results of a Fisher Exact test will
be included |
mcnemar |
If TRUE , the results of a McNemar test will
be included |
A summary table will be generated with cell row, column and table proportions and marginal totals and proportions. Expected cell counts can be printed if desired. In the case of a 2 x 2 table, both corrected and uncorrected values will be included for appropriate tests.
Note: Any unused factor levels will be dropped prior to tabulation.
A list with multiple components including key table data and
statistical test results, where performed.
t: An n by m matrix containing table cell counts
prop.col: An n by m matrix containing cell column proportions
prop.row: An n by m matrix containing cell row proportions
prop.tbl: An n by m matrix containing cell table proportions
chisq: Results from the Chi-Square test. A list with class
'htest'. See ?chisq.test for details
chisq.corr: Results from the corrected Chi-Square test. A list with
class 'htest'. See ?chisq.test for details. ONLY
included in the case of a 2 x 2 table.
fisher.ts: Results from the two-sided Fisher Exact test. A list
with class 'htest'. See ?fisher.test for details. ONLY
included if 'fisher' = TRUE.
fisher.lt: Results from the Fisher Exact test with HA = "less". A
list with class 'htest'. See ?fisher.test for details.
ONLY included if 'fisher' = TRUE and in the case of a
2 x 2 table.
fisher.gt: Results from the Fisher Exact test with HA = "greater".
A list with class 'htest'. See ?fisher.test for details.
ONLY included if 'fisher' = TRUE and in the case of a
2 x 2 table.
mcnemar: Results from the McNemar test. A list with class
'htest'. See ?mcnemar.test for details. ONLY included
if 'mcnemar' = TRUE.
mcnemar.corr: Results from the corrected McNemar test. A list with
class 'htest'. See ?mcnemar.test for details. ONLY
included if 'mcnemar' = TRUE and in the case of a
2 x 2 table.
Marc Schwartz mschwartz@medanalytics.com. Original version posted to r-devel on Jul 27, 2002.
# Simple cross tabulation of education versus prior induced abortions # using infertility data data(infert, package = "base") CrossTable(infert$education, infert$induced, expected = TRUE)