library(pacman)
pacman::p_load(MASS, tidyverse, magrittr, vcd, vcdExtra)
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.
Dayton.ACM <- aggregate(Freq ~ cigarette + alcohol + marijuana, data = DaytonSurvey, FUN = sum)
Dayton.ACM
Dayton.loglm <- loglm(Freq ~ cigarette + alcohol + marijuana, data= Dayton.ACM, param= TRUE, fitted= TRUE)
Dayton.loglm
## Call:
## loglm(formula = Freq ~ cigarette + alcohol + marijuana, data = Dayton.ACM,
## param = TRUE, fitted = TRUE)
##
## Statistics:
## X^2 df P(> X^2)
## Likelihood Ratio 1286.020 4 0
## Pearson 1411.386 4 0
mosaic(Dayton.loglm, shade = TRUE, labeling = labeling_residuals)
From the mosaic plot we can see a strong positive association between alcohol and cigarette, which means that if a person is drinking alcohol there is more possible that he/she smoke cigarette as well.
# Fourfold of AC stratified by M
fourfold(xtabs(Freq ~ alcohol + cigarette + marijuana, data = DaytonSurvey), main = 'Fourfold Plot AC | M')
Observation: Irrespective of marijuana usage, there is strong association between use of alcohol and cigarette.
# Fourfold of AM stratified by C
fourfold(xtabs(Freq ~ alcohol + marijuana + cigarette, data = DaytonSurvey), main = 'Fourfold Plot AM | c')
Observation: Irrespective of cigarette usage, there is strong association between use of alcohol and marijuana.
# Fourfold of CM stratified by A
fourfold(xtabs(Freq ~ cigarette + marijuana + alcohol, data = DaytonSurvey), main = 'Fourfold Plot CM | A')
Observation: Irrespective of drinking alcohol, there is strong association between use of marijuana and smoking cigarette.