install.packages(“vcdExtra”)

Exercise 9.1 Consider the data set DaytonSurvey (described in Example 2.6), giving results of a survey of use of alcohol (A), cigarettes (C), and marijuana (M) among high school seniors. For this exercise, ignore the variables sex and race, by working with the marginal table Dayton.ACM, a 2 × 2 × 2 table in frequency data frame form.

data(DaytonSurvey, package = "vcdExtra")
str(DaytonSurvey)
## 'data.frame':    32 obs. of  6 variables:
##  $ cigarette: Factor w/ 2 levels "Yes","No": 1 2 1 2 1 2 1 2 1 2 ...
##  $ alcohol  : Factor w/ 2 levels "Yes","No": 1 1 2 2 1 1 2 2 1 1 ...
##  $ marijuana: Factor w/ 2 levels "Yes","No": 1 1 1 1 2 2 2 2 1 1 ...
##  $ sex      : Factor w/ 2 levels "female","male": 1 1 1 1 1 1 1 1 2 2 ...
##  $ race     : Factor w/ 2 levels "white","other": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Freq     : num  405 13 1 1 268 218 17 117 453 28 ...
Dayton.ACM <- aggregate(Freq ~ cigarette + alcohol + marijuana, data = DaytonSurvey, FUN = sum)
Dayton.ACM
##   cigarette alcohol marijuana Freq
## 1       Yes     Yes       Yes  911
## 2        No     Yes       Yes   44
## 3       Yes      No       Yes    3
## 4        No      No       Yes    2
## 5       Yes     Yes        No  538
## 6        No     Yes        No  456
## 7       Yes      No        No   43
## 8        No      No        No  279

(a)Use loglm () to fit the model of mutual independence, [A][C][M].

Dayton.loglm <- loglm(Freq ~ cigarette + alcohol + marijuana, data= Dayton.ACM, param= TRUE, fitted= TRUE)

Dayton.loglm

(b)Prepare mosaic display(s) for associations among these variables. Give a verbal description of the association between cigarette and alcohol use.

mosaic(Dayton.loglm, shade = TRUE, labeling = labeling_residuals)

The mosaic plot indicated strong association among users of all three substances, and non-users for all three substances. It shows when people consume one type of substance they are more likely to consume other substances, and vice versa - people who stay clear from one stype of substance are more likely to stay clear of all types of substance.

(c)Use fourfold () to produce fourfold plots for each pair of variables, AC, AM, and CM, stratified by the remaining one. Describe these associations verbally.

See verbal description at the end of all plots

fourfold(xtabs(Freq ~ alcohol + cigarette + marijuana, data = DaytonSurvey), main = 'Fourfold Plot Stratified by Marijuana')

fourfold(xtabs(Freq ~ alcohol + marijuana + cigarette, data = DaytonSurvey), main = 'Fourfold Plot Stratified by Cigarette')

fourfold(xtabs(Freq ~ cigarette + marijuana + alcohol, data = DaytonSurvey), main = 'Fourfold Plot Stratified by Alcohol')

All the fourfold plots above validate our findings from the mosaic plot - that people who consume one stype of substance tend to consume type of substance as well. We could see from the three sets of plots above, that regardless of the variable the plot is stradified by, the remaining two substances show significant association - people tend to either consume both of them or stay clean from both of them.