1. Mosaic Plots

Using the Mosaic plots, display Punishment dataset in the vcd package. Discuss patterns of association between independent and dependent variables. Discuss single factor patterns as well as two and three factor interactions.

str(Punishment)
'data.frame':   36 obs. of  5 variables:
 $ Freq     : num  1 3 20 2 8 4 2 6 1 26 ...
 $ attitude : Factor w/ 2 levels "no","moderate": 1 1 1 1 1 1 1 1 1 1 ...
 $ memory   : Factor w/ 2 levels "yes","no": 1 1 1 1 1 1 1 1 1 2 ...
 $ education: Factor w/ 3 levels "elementary","secondary",..: 1 1 1 2 2 2 3 3 3 1 ...
 $ age      : Factor w/ 3 levels "15-24","25-39",..: 1 2 3 1 2 3 1 2 3 1 ...

Brief observation on association between variables:

To see the patterns between the independent and dependent variables, we can first check the relationship between each variable in the dataset using the scatterplot matrix as follows. The dependent variable is frequency (Freq), and the independent variables are attitude, memory, education, and age.

Based on our quick observation above, the frequency tends to go higher with attitude factor indicating moderate and memory factor indicating no, implying more people had no memories of corporal punishment as a child. For the three-level variables, the frequency tends to decrease as education level increases from elementary to middle to high school. Frequency also tends to increase as age increases as well.

Single factor pattern:

The dataset represents the corporal punishment data from a study of the Gallup Institute in Denmark in 1979 about the attitude of a random sample of 1,456 persons towards corporal punishment of children. In terms of frequency, we see clearly in the plot above that there are more people with attitudes indicating moderate punishment of children than no punishment.

Two factor interactions:

mosaicplot(xtabs(Freq ~ attitude + education, data=Punishment),
           main="Attitude and Education Factors in Punishment Dataset", legend=TRUE, shade=TRUE)
In mosaicplot.default(xtabs(Freq ~ attitude + education, data = Punishment), 
    main = "Attitude and Education Factors in Punishment Dataset", 
    legend = TRUE, shade = TRUE) :
 extra argument ‘legend’ will be disregarded