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

library(MASS)
library(vcd)
## Loading required package: grid
library(vcdExtra)
## Loading required package: gnm
data(DaytonSurvey)
attach(DaytonSurvey)
dta =aggregate(Freq~cigarette +alcohol +marijuana,data= DaytonSurvey, FUN=sum)
fit <- loglm(Freq ~ cigarette + alcohol + marijuana, data=dta, fitted=TRUE)

fit
## Call:
## loglm(formula = Freq ~ cigarette + alcohol + marijuana, data = dta, 
##     fitted = TRUE)
## 
## Statistics:
##                       X^2 df P(> X^2)
## Likelihood Ratio 1286.020  4        0
## Pearson          1411.386  4        0

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

mosaic(fit,labeling=labeling_residuals)

Here we see that there is a strong correlation between alcohol and cigarettes. If someone consumes alcohol it is very likely that they smoke cigarettes as well.

(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.

data.tabs <- xtabs(Freq ~ cigarette + alcohol + marijuana, data=dta)
#AC | M
df1 <- aperm(data.tabs, c(1,2,3))
fourfold(df1)

#AM | C
df2 <- aperm(data.tabs, c(2,3,1))
fourfold(df2)

#MC |A
data.tabs <- xtabs(Freq ~ cigarette + alcohol + marijuana, data=dta)
df3<- aperm(data.tabs, c(1,3,2))
fourfold(df3)

Overall there is a string association between alcohol, cigarettes and marijuana usage and students who intake one are likely to intake the others as well.