In: Math
The R code is as follows
require(graphics)
data("HairEyeColor")
HairEyeColor
sum(HairEyeColor)
## Full mosaic
mosaicplot(HairEyeColor)
## Aggregate over sex (as in Snee's original data)
x <- apply(HairEyeColor, c(1, 2), sum)
x
mosaicplot(x, main = "Relation between hair and eye color")
# Mosaic Plot using VCD
library(vcd)
mosaic(HairEyeColor, shade=TRUE, legend=TRUE,main = "Relation
between hair and eye color")
The results are
HairEyeColor
, , Sex = Male
Eye
Hair Brown Blue Hazel Green
Black 32 11 10 3
Brown 53 50 25 15
Red 10 10 7 7
Blond 3 30 5 8
, , Sex = Female
Eye
Hair Brown Blue Hazel Green
Black 36 9 5 2
Brown 66 34 29 14
Red 16 7 7 7
Blond 4 64 5 8
> sum(HairEyeColor)
[1] 592
The colors represent the level of the residual for that cell / combination of levels. The legend is presented at the plot's right. More specifically, blue means there are more observations in that cell than would be expected under the null model (independence). Red means there are fewer observations than would have been expected.
we see that the values are signficant for all hair colors within the male and female combinations , hence there is a relationship
read 2 rows from the graph at a time