Aug 11
Contingency Table for Categorical data and R
Posted by admin on Wednesday Aug 11, 2010 Under StatisticsHow to create contingency table from categorical data in r.
Example:
There are three categorical variables x1, x2, x3 measured from wild cats where
x1 = gender (male, female)
x2 = age (young, kitten, adult)
x3 = test result ( positive = 1, negative =0).
r table will generate two tables: 2by2 table for each of x3=0 and x3=1.
# r code
table(x1, x2, x3)
As shown below, the R output has two parts when x3=0 and x3=1.
Row represents Gender (x1) and the column represents Age (x2).
The numbers are counts of cats that fall into the corresponding categories.
, , = 0
A K Y
F 14 84 2
M 8 97 2
, , = 1
A K Y
F 1 12 0
M 1 36 0