lights

references:
- ISI, example 4.1, p.232

data

lights <- c(18, 154, 78, 154, 41, 34)
dim(lights) <- c(2, 3)
dimnames(lights) <- list(nearsighted = c("yes", "no"),
                         light = c("darkness", "night light", "room light"))
lights
##            light
## nearsighted darkness night light room light
##         yes       18          78         41
##         no       154         154         34
addmargins(lights)     # marginal sums
##            light
## nearsighted darkness night light room light Sum
##         yes       18          78         41 137
##         no       154         154         34 342
##         Sum      172         232         75 479
prop.table(lights, 2)  # conditional proportions
##            light
## nearsighted  darkness night light room light
##         yes 0.1046512   0.3362069  0.5466667
##         no  0.8953488   0.6637931  0.4533333

mosaicplot

mosaicplot(t(lights), col = c("green", "yellow"))