Load data

library(vcd)
data("UCBAdmissions")

rearrange dimensions

UCB <- aperm(UCBAdmissions, c(2,1,3))
# marginal table, collapsing over Dept
(UCB2 <- margin.table(UCB, c(1,2)))
##         Admit
## Gender   Admitted Rejected
##   Male       1198     1493
##   Female      557     1278

Chisquare test

chisq.test(UCB2)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  UCB2
## X-squared = 91.61, df = 1, p-value < 2.2e-16

Fourfold plots

fourfold(UCB2)

# unstandardized version
fourfold(UCB2, std="ind.max")

3-way table, stratified by Dept

fourfold(UCB, mfrow=c(2,3))

test homogeneity of odds ratios over Dept

woolf_test(UCB)
## 
##  Woolf-test on Homogeneity of Odds Ratios (no 3-Way assoc.)
## 
## data:  UCB
## X-squared = 17.902, df = 5, p-value = 0.003072

calculate odds ratios

oddsratio(UCBAdmissions, log=FALSE)
##  odds ratios for Admit and Gender by Dept 
## 
##         A         B         C         D         E         F 
## 0.3492120 0.8025007 1.1330596 0.9212838 1.2216312 0.8278727
# plot log odds ratios
plot(oddsratio(UCBAdmissions), xlab="Department", ylab="Log Odds Ratio (Admit|Gender)")