This function prints a 2-way table with optional cell statistics and measures of association
oii.xtab(r, c = NULL, s = NULL, row = FALSE, col = FALSE,
pctcell = FALSE, stats = FALSE, rescell = FALSE, chistd = FALSE,
expcell = FALSE, chicell = FALSE, warnings = FALSE, varnames = NULL,
include.missing = FALSE, ...)
the row variable. If r
is a table
, data.frame
, or matrix
, then c
and s
are ignored.
the column variable.
the split variable. The r
and c
will be separately tabulated for each unique value of s
.
Show row percentages? Defaults to FALSE.
Show column percentages? Defaults to FALSE.
Print cell percentages? Defaults to FALSE.
Print measures of association? Defaults to FALSE. This parameter is ignored either r
or c
has only one value. See association.measures
.
Print residual cell count under the null hypothesis? Defaults to FALSE.
Print cell standardized residuals to pearson chi-square? Defaults to FALSE.
Print expected cell count under the null hypothesis? Defaults to FALSE.
Print cell contribution to pearson chi-square? Defaults to FALSE.
a logical value indicating whether warnings should be shown (defaults to FALSE, no warnings).
Names used to refer to r
, c
, and s
in the printed output.
Set to TRUE to include factor levels with no instances in the output. Default (FALSE) excludes them.
Additional parameters to be passed to CrossTable
.
association.measures
, CrossTable
, likelihood.test
, lambda.test
# NOT RUN {
#Create var1 as 200 A's, B's, and C's
var1<-sample(LETTERS[1:3],size=200,replace=TRUE)
#Create var2 as 200 numbers in the range 1 to 4
var2<-sample(1:4,size=200,replace=TRUE)
#Print a simple 2-way table of var1 and var2
oii.xtab(var1,var2)
#Print the row and column percents
oii.xtab(var1,var2,row=TRUE,col=TRUE)
#Print measures of association statistics
oii.xtab(var1,var2,stats=TRUE)
#If the variables are part of a data.frame
my.data.frame<-data.frame(var1,var2)
#We can use the $ to get the variables
oii.xtab(my.data.frame$var1,my.data.frame$var2)
#or use the with(...) command to save some typing
with(my.data.frame,oii.xtab(var1,var2))
#Three-way tables are also possible
#Create var3 as 200 "I"'s, "II"'s, and "III"'s
var3<-sample(c("I","II","III"),size=200,replace=TRUE)
oii.xtab(var1,var2,var3)
#We can also pass in a data.frame directly as the first argument
my.data.frame<-data.frame(var1,var2,var3)
oii.xtab(my.data.frame,stats=TRUE)
#The variables in the data.frame are used in order;
#so, sometimes it is useful to re-order them. For example,
oii.xtab(my.data.frame[,c("var3","var1","var2")],stats=TRUE)
#Of course, it is also possible to pass in the variables one
#at a time or use with(...) as shown above.
# }
Run the code above in your browser using DataLab