Exploratory data analysis

EXERCISE 1:

Instruction: Create a table1 and use GGally::ggpairs to explore your data.

## EXPLORE THE DATA
vars <- c("mj_lifetime", "alc_agefirst", "demog_age_cat6", "demog_sex", "demog_income")

# Create table1 using ggpairs
ggpairs(nsduh[, vars], 
        aes(color = mj_lifetime), 
        columnLabels = c("MJ use", "Age: Alcohol First Use", "Age_Group", "Sex", "Income"),
        upper = list(continuous = "density", combo = "box"),
        lower = list(continuous = "points", combo = "dot"),
        axisLabels = "show"
                )  + 
  theme(strip.text = element_text(face="bold", colour="black", size=10))

## TABLE 1 CUSTOMIZATION
## Labels
label(nsduh$demog_sex) <- "Sex"
label(nsduh$alc_agefirst) <- "Alcohol (age first used)" 
label(nsduh$demog_age_cat6) <- "Age"
label(nsduh$demog_income) <- "Income"
label(nsduh$mj_lifetime) <- "Lifetime marijuana use"

## Title
caption <- "Table 1: Demographic stratified by lifetime marijuana use"

# TABLE 1:
table1(~ demog_sex + alc_agefirst + demog_age_cat6 + demog_income | mj_lifetime, data=nsduh, overall = F, caption = caption)
Table 1: Demographic stratified by lifetime marijuana use
No
(N=491)
Yes
(N=509)
Sex
Female 285 (58.0%) 249 (48.9%)
Male 206 (42.0%) 260 (51.1%)
Alcohol (age first used)
Mean (SD) 19.7 (5.09) 16.0 (3.08)
Median [Min, Max] 19.0 [3.00, 45.0] 16.0 [3.00, 29.0]
Missing 145 (29.5%) 12 (2.4%)
Age
18-25 53 (10.8%) 80 (15.7%)
26-34 52 (10.6%) 87 (17.1%)
35-49 129 (26.3%) 136 (26.7%)
50-64 109 (22.2%) 132 (25.9%)
65+ 148 (30.1%) 74 (14.5%)
Income
Less than $20,000 76 (15.5%) 85 (16.7%)
$20,000 - $49,999 166 (33.8%) 127 (25.0%)
$50,000 - $74,999 64 (13.0%) 81 (15.9%)
$75,000 or more 185 (37.7%) 216 (42.4%)

Calculating odds ratio

EXERCISE 2:

Instruction: Use the contingency table below to calculate (a) probability of lifetime marijuana among sample subjects (independent of sex), among sample females and among sample males, (b) Odds of lifetime marijuana use among sample subjects, among sample females and among sample males. (c) What is the risk difference, the risk ratio and the odds ratio when comparing lifetime marijuana use among males and females in our sample?

Interpretation:

Risk Difference (RD): The risk difference of 0.092 suggests that the probability of lifetime marijuana use is 9.2% higher in males compared to females in our sample.

Risk Ratio (RR): With a risk ratio of 1.198, it indicates that the likelihood of lifetime marijuana use is approximately 1.2 times higher in males compared to females.

Odds Ratio (OR): The odds ratio of 1.445 suggests that the odds of lifetime marijuana use are 44.5% higher in males compared to females in our sample.

# REORDER CATEGORIES IN mj_lifetime
nsduh$mj_lifetimenew <- factor(nsduh$mj_lifetime, levels = c("Yes", "No"))


# Showing absolute numbers
nsduh |> 
  tabyl(demog_sex, mj_lifetimenew) |> 
  adorn_totals("row") |>
  adorn_totals("col") |>
  adorn_title()
##            mj_lifetimenew          
##  demog_sex            Yes  No Total
##     Female            249 285   534
##       Male            260 206   466
##      Total            509 491  1000
# Showing percentages
nsduh |> 
  tabyl(demog_sex, mj_lifetimenew) |> 
  adorn_percentages() |> 
  adorn_pct_formatting() |> 
  adorn_title()
##            mj_lifetimenew      
##  demog_sex            Yes    No
##     Female          46.6% 53.4%
##       Male          55.8% 44.2%
# Replace the blanks below with appropriate values
tribble(
  ~Prediction, ~General, ~Female, ~Male, 
  "Probability", 0.509, 0.466, 0.558, 
  "Odds",        1.037, 0.873, 1.262, 
  "Log Odds",    0.036, -0.136, 0.233
) |> gt()
Prediction General Female Male
Probability 0.509 0.466 0.558
Odds 1.037 0.873 1.262
Log Odds 0.036 -0.136 0.233
# Replace the blanks below with appropriate values
tribble(
  ~Contrast, ~`Males vs. Females`, 
  "Risk difference", 0.0916, 
  "Risk Ratio",      0.843,
  "Odds ratio",      0.692, 
  "Log odds ratio",  -0.3681693
) |> gt()
Contrast Males vs. Females
Risk difference 0.0916000
Risk Ratio 0.8430000
Odds ratio 0.6920000
Log odds ratio -0.3681693

EXERCISE 3

Instruction: You will now estimate the same measures from the previous question, but this time using two types of regressions: a logistic regression and a regular least squares linear regression. Show your code and present your results in a table adding the confidence intervals (see below). Explain your findings: what are the differences between the three approaches (using a contingency table as in the question above, using logistic regression and using linear regression)? What explains these differences (or lack thereof)? What are the advantages/drawbacks of using one approach over the other?

Answer: For all three approaches, the results are exactly the same. What differs is the way to get the results. When using the contingency table, it is possible to calculate all probabilities and odds by hand. However, you won’t get the confidence intervals and p-values. When using the logistic model, it is possible to also obtain the confidence intervals. When Females are set as reference, the intercept is giving the results for females. To obtain the results of male, you can calculate this by summing the intercept and the slope according to the rules on how to sum log values. However, with this approach you can’t calculate the confidence intervals. To also get the confidence intervals, the easiest option is to change the reference to Male, so the intercept is given the values and confidence intervals for males. When using the linear model, the results are the same with these binary variables. However, the assumptions that the outcome is continuous is not met, but that doesn’t give different results here.

For the odds ratio, you can take the ratio of the odds of the males over the odds of the females. Another option is to take the exponent of the slope of the logistic model, which also represents the ratio.

#################
# The null model 
#################

# Using logistic regression
mdl.glm.null <- glm(
  mj_lifetime ~ 1, 
  data = nsduh, 
  family = binomial
  )

summary(mdl.glm.null)
## 
## Call:
## glm(formula = mj_lifetime ~ 1, family = binomial, data = nsduh)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  0.03600    0.06326   0.569    0.569
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1386  on 999  degrees of freedom
## Residual deviance: 1386  on 999  degrees of freedom
## AIC: 1388
## 
## Number of Fisher Scoring iterations: 3
# Log - odds for lifetime marijuana (everyone)
null.logodds <- tidy(
  mdl.glm.null, 
  conf.int = TRUE
  )

# Odds of lifetime marijuana (everyone)
null.odds <- tidy(
  mdl.glm.null, 
  exponentiate = TRUE,
  conf.int = TRUE
  )

# Probability of lifetime marijuana (everyone)
null.prob <- tidy(
  mdl.glm.null, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high) |> 
  mutate_all(plogis)


#################
# Now let us use a linear regression
# Notice: we will be violating assumptions. Oh no! 😱
mdl.lm.null <- lm(mj_lifetime.numeric ~ 1, data = nsduh )

# Probability of lifetime marijuana (everyone) using linear regression
lm.null.prob <- tidy(
  mdl.lm.null, 
  conf.int = TRUE
  ) 

########################
# The unadjusted model
#######################
#Using female as reference
nsduh$demog_sex <- factor(nsduh$demog_sex, levels=c("Female","Male"))
mdl.glm <- glm(
  mj_lifetime ~ demog_sex, 
  data = nsduh, 
  family = binomial
  )

summary(mdl.glm)
## 
## Call:
## glm(formula = mj_lifetime ~ demog_sex, family = binomial, data = nsduh)
## 
## Coefficients:
##               Estimate Std. Error z value Pr(>|z|)   
## (Intercept)   -0.13504    0.08675  -1.557  0.11954   
## demog_sexMale  0.36784    0.12738   2.888  0.00388 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1386.0  on 999  degrees of freedom
## Residual deviance: 1377.6  on 998  degrees of freedom
## AIC: 1381.6
## 
## Number of Fisher Scoring iterations: 3
# Log - odds for lifetime marijuana (everyone)
glm.logodds <- tidy(
  mdl.glm, 
  conf.int = TRUE
  )

# Odds of lifetime marijuana (everyone)
glm.odd <- tidy(
  mdl.glm, 
  exponentiate = TRUE,
  conf.int = TRUE
  )

# Probability of lifetime marijuana (everyone)
glm.prob <- tidy(
  mdl.glm, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high) |> 
  mutate_all(plogis)

#Using male as reference
nsduh$demog_sex <- factor(nsduh$demog_sex, levels=c("Male","Female"))

mdl.glm_male <- glm(
  mj_lifetime ~ demog_sex, 
  data = nsduh, 
  family = binomial
  )

summary(mdl.glm_male)
## 
## Call:
## glm(formula = mj_lifetime ~ demog_sex, family = binomial, data = nsduh)
## 
## Coefficients:
##                 Estimate Std. Error z value Pr(>|z|)   
## (Intercept)      0.23281    0.09328   2.496  0.01256 * 
## demog_sexFemale -0.36784    0.12738  -2.888  0.00388 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1386.0  on 999  degrees of freedom
## Residual deviance: 1377.6  on 998  degrees of freedom
## AIC: 1381.6
## 
## Number of Fisher Scoring iterations: 3
# Log - odds for lifetime marijuana (everyone)
glm.logodds.male <- tidy(
  mdl.glm_male, 
  conf.int = TRUE
  )

# Odds of lifetime marijuana (everyone)
glm.odd.male <- tidy(
  mdl.glm_male, 
  exponentiate = TRUE,
  conf.int = TRUE
  )

# Probability of lifetime marijuana (everyone)
glm.prob.male <- tidy(
  mdl.glm_male, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high) |> 
  mutate_all(plogis)

#MAKE SURE TO CHANGE THE REFERENCE AGAIN FOR CORRECT COMPARISON
nsduh$demog_sex <- factor(nsduh$demog_sex, levels=c("Female","Male"))

library(marginaleffects)
RD <- avg_comparisons(
  model = mdl.glm_male, 
  variables = "demog_sex", # This is the exposure variable
  comparison = "difference"
)

RR <- avg_comparisons(
  model = mdl.glm, 
  variables = "demog_sex", # This is the exposure variable
  comparison = "ratio"
)

OR <- avg_comparisons(
  model = mdl.glm, 
  variables = "demog_sex", # This is the exposure variable
  comparison = "lnor"
)


# Linear model 
mdl.lm <- lm(mj_lifetime.numeric ~ demog_sex, data = nsduh )

# Probability of lifetime marijuana (everyone) using linear regression
mdl.lm.prob <- tidy(
  mdl.lm, 
  conf.int = TRUE
  ) 


# Replace the blanks below with appropriate values
tribble(
  ~Prediction, ~General, ~Female, ~Male, 
  "Probability", "0.509 CI [0.478, 0.540]", "0.466 CI [0.424, 0.509]", "0.558 CI [0.513, 0.603]", 
  "Odds",        "1.04 CI [0.916, 1.17]", "0.874 CI [0.737, 1.04]", "1.26 CI [1.05, 1.52]", 
  "Log Odds",    "0.0360 CI [-0.880, 0.160]", "-0.135 CI [-0.305, 0.0348]", "0.233 CI [0.0505, 0.416]"
) |> gt()
Prediction General Female Male
Probability 0.509 CI [0.478, 0.540] 0.466 CI [0.424, 0.509] 0.558 CI [0.513, 0.603]
Odds 1.04 CI [0.916, 1.17] 0.874 CI [0.737, 1.04] 1.26 CI [1.05, 1.52]
Log Odds 0.0360 CI [-0.880, 0.160] -0.135 CI [-0.305, 0.0348] 0.233 CI [0.0505, 0.416]
tribble(
  ~Contrast, ~`Males vs. Females`, 
  "Risk difference", "0.0916 CI [0.0298, 0.153]", 
  "Risk Ratio",      "1.2 CI [1.05, 1.34]",
  "Odds ratio",      "1.44 CI [1.13, 1.86]", 
  "Log odds ratio",  "0.368 CI [0.118, 0.617]"
) |> gt()
Contrast Males vs. Females
Risk difference 0.0916 CI [0.0298, 0.153]
Risk Ratio 1.2 CI [1.05, 1.34]
Odds ratio 1.44 CI [1.13, 1.86]
Log odds ratio 0.368 CI [0.118, 0.617]

EXERCISE 4

Instruction: Write up your results using the template shown below. Conclusion: Males have significantly ___ (higher/lower) odds of lifetime marijuana use than females (OR = ___ ; 95% CI = ___ , ___ p = ___ ). Males have ___% (higher/lower) odds of lifetime marijuana use than females.

Answer: Conclusion: Males have significantly higher odds of lifetime marijuana use than females (OR=1.44; 95% CI = 1.13, 1,86; p=0.00388). Males have 44% higher odds of lifetime marijuana use than females.

EXERCISE 5

Instruction: Whereas in the previous questions we explored the relationship between lifetime marijuana use and sex, we will now explore the association between lifetime marijuana use (mj_lifetime) and age at first use of alcohol (alc_agefirst)? Fit a logistic regression and interpret the results, using the template shown below.

Age at first alcohol use is significantly ___ (negatively/positively) associated with lifetime marijuana use (OR = ___ ; 95% CI = ___ , ___ ; p < ___ ). Individuals who first used alcohol at age 19 years have ___ % ___ (lower/higher) odds of having ever used marijuana than those who first used alcohol at age 18 years. In contrast, the reduction in odds associated with starting drinking alcohol 3 years later is ___ % ___ (lower/higher) odds.

Answer: Age at first alcohol use is significantly negatively associated with lifetime marijuana use (OR = 0.753 ; 95% CI = 0.713 , 0.792 ; p < 2.46e-26). Individuals who first used alcohol at age 19 years have 24.7 % lower odds of having ever used marijuana than those who first used alcohol at age 18 years. In contrast, the reduction in odds associated with starting drinking alcohol 3 years later is 57.3 % lower odds.

mdl.glm2 <- glm(
  mj_lifetime ~ alc_agefirst, 
  data = nsduh, 
  family = binomial
  )

summary(mdl.glm2)
## 
## Call:
## glm(formula = mj_lifetime ~ alc_agefirst, family = binomial, 
##     data = nsduh)
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept)    5.3407     0.4747   11.25   <2e-16 ***
## alc_agefirst  -0.2835     0.0267  -10.62   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1141.45  on 842  degrees of freedom
## Residual deviance:  968.44  on 841  degrees of freedom
##   (157 observations deleted due to missingness)
## AIC: 972.44
## 
## Number of Fisher Scoring iterations: 5
Odds_mdl2 <- tidy(
  mdl.glm2, 
  exponentiate = TRUE,
  conf.int = TRUE
  )

Adjusted logistic regression

The main reason for combining multiple predictors is to address the problem of confounding bias. Confounding bias occurs when a predictor affects both outcome and exposure. Adding a confounder to as a predictor to the model removes this bias.

With multiple predictors in a logistic regression model, the resulting odds ratios are called Adjusted Odds Ratio (AOR).

EXERCISE 6

Instruction: What is the association between lifetime marijuana use (mj_lifetime) and age at first use of alcohol (alc_agefirst), adjusted for age (demog_age_cat6), sex (demog_sex), and income (demog_income)? Fit a model with and without an interaction term (alc_agefirst:demog_sex) and compute the AOR, its 95% CI, and the p-value that tests the significance of age at first use of alcohol. Report also their AORs of the other predictors, their 95% CIs and p-values. Since there are some categorical predictors with more than two levels, use car::Anova(model, type = 3) function to compute p-values for multiple degrees of freedom. In your answer, fill in the template below.

Interpreting the output:

The AOR for our primary predictor alc_agefirst is ___. This represents the OR for lifetime marijuana use comparing those with a one-year difference in age at first use of alcohol, adjusted for age, sex, and income.

The remaining AORs compare levels of categorical predictors to their reference level, adjusted for the other predictors in the model. For example, comparing individuals with the same age of first alcohol use, sex, and income, 35-49 year-olds have ___ % (lower/higher) odds of lifetime marijuana use than 18-25 year-olds (OR = ___ ; 95% CI = ___ , ___ ; p = ___ ). An overall 4 df p-value for age can be read from the Type III Test table. It (is/is not) significant at p = ___ . An overall, 3 df p-value for income (is/is not) significant at (p = ___ ).

Conclusion: After adjusting for age, sex, and income, age at first alcohol use is significantly ___ (negatively/positively) associated with lifetime marijuana use (AOR = ___ ; 95% CI = ___ , ___ ; p < ___ ). Individuals who first used alcohol at a given age have ___ % (lower/higher) odds of having ever used marijuana than those who first used alcohol one year earlier. The association between age of first alcohol use and lifetime marijuana use differs significantly between males and females (p = ___ ). A likelihood ratio test shows that the adjusted model with the interaction is ___ (superior/not superior) to the one without the interaction (p = ___)

Answer: The AOR for our primary predictor alc_agefirst is 0.759. This represents the OR for lifetime marijuana use comparing those with a one-year difference in age at first use of alcohol, adjusted for age, sex, and income.

The remaining AORs compare levels of categorical predictors to their reference level, adjusted for the other predictors in the model. For example, comparing individuals with the same age of first alcohol use, sex, and income, 35-49 year-olds have 55.3 % lower odds of lifetime marijuana use than 18-25 year-olds (OR = 0.447 ; 95% CI = 0.247 , 0.791 ; p = 6.69e-3 ). An overall 4 df p-value for age can be read from the Type III Test table. It is significant at p = 8.12e-05. An overall, 3 df p-value for income is not significant at (p = 0.1380).

Conclusion: After adjusting for age, sex, and income, age at first alcohol use is significantly negatively associated with lifetime marijuana use (AOR = 0.759; 95% CI = 0.718 , 0.800 ; p < 3.85e-26). Individuals who first used alcohol at a given age have 24.1 % lower odds of having ever used marijuana than those who first used alcohol one year earlier. The association between age of first alcohol use and lifetime marijuana use differs significantly between males and females (p = 0.0322). A likelihood ratio test shows that the adjusted model with the interaction is superior to the one without the interaction (p = 0.03095).

To avoid misinterpretation of the answer: for the interpretation, the model without the interaction is used. The interaction is only used to answer the question for the difference between males and females.

mdl.full <- glm(
  mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income, 
  data = nsduh, 
  family = binomial
  )

summary(mdl.full)
## 
## Call:
## glm(formula = mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + 
##     demog_income, family = binomial, data = nsduh)
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    6.25417    0.59136  10.576  < 2e-16 ***
## alc_agefirst                  -0.27541    0.02756  -9.992  < 2e-16 ***
## demog_age_cat626-34           -0.29619    0.32865  -0.901  0.36746    
## demog_age_cat635-49           -0.80427    0.29656  -2.712  0.00669 ** 
## demog_age_cat650-64           -0.68991    0.29854  -2.311  0.02084 *  
## demog_age_cat665+             -1.27475    0.30429  -4.189  2.8e-05 ***
## demog_sexMale                 -0.06089    0.16181  -0.376  0.70669    
## demog_income$20,000 - $49,999 -0.53088    0.26641  -1.993  0.04629 *  
## demog_income$50,000 - $74,999 -0.07931    0.30488  -0.260  0.79476    
## demog_income$75,000 or more   -0.36120    0.25323  -1.426  0.15376    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1141.45  on 842  degrees of freedom
## Residual deviance:  935.55  on 833  degrees of freedom
##   (157 observations deleted due to missingness)
## AIC: 955.55
## 
## Number of Fisher Scoring iterations: 5
Odds_full <- tidy(
  mdl.full, 
  exponentiate = TRUE,
  conf.int = TRUE
  )

car::Anova(mdl.full, type = 3)
## Analysis of Deviance Table (Type III tests)
## 
## Response: mj_lifetime
##                LR Chisq Df Pr(>Chisq)    
## alc_agefirst    149.610  1  < 2.2e-16 ***
## demog_age_cat6   23.964  4   8.12e-05 ***
## demog_sex         0.142  1     0.7066    
## demog_income      5.510  3     0.1380    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tribble(
  ~Full_model, ~AOR,  ~pvalue, 
  "alc_agefirst", "0.759 CI [0.718, 0.800]", "1.65e-23",
  "demog_age_cat626-34", "0.744 CI [0.387, 1.41]", "3.67e-1",  
  "demog_age_cat635-49", "0.447 CI [0.247, 0.791]", "6.69e-3",  
  "demog_age_cat650-64", "0.502 CI [0.275, 0.160]", "2.08e-2 ",
  "demog_age_cat665+", "0.279 CI [0.152, 0.502]", "2.80e-5", 
  "demog_sexMale", "0.941 CI [0.684, 1.29]", "7.07e-1",
  "demog_income$20,000 - $49,999", "0.588 CI [0.347, 0.987]", "4.63e-2",
  "demog_income$50,000 - $74,999", "0.924 CI [0.507, 1.68]", "7.95e-1",
  "demog_income$75,000 or more", "0.697 CI [0.421, 1.14]", "1.54e-1"
) |> gt()
Full_model AOR pvalue
alc_agefirst 0.759 CI [0.718, 0.800] 1.65e-23
demog_age_cat626-34 0.744 CI [0.387, 1.41] 3.67e-1
demog_age_cat635-49 0.447 CI [0.247, 0.791] 6.69e-3
demog_age_cat650-64 0.502 CI [0.275, 0.160] 2.08e-2
demog_age_cat665+ 0.279 CI [0.152, 0.502] 2.80e-5
demog_sexMale 0.941 CI [0.684, 1.29] 7.07e-1
demog_income$20,000 - $49,999 0.588 CI [0.347, 0.987] 4.63e-2
demog_income$50,000 - $74,999 0.924 CI [0.507, 1.68] 7.95e-1
demog_income$75,000 or more 0.697 CI [0.421, 1.14] 1.54e-1
mdl.int <- glm(
  mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex, 
  data = nsduh, 
  family = binomial
  )

summary(mdl.int)
## 
## Call:
## glm(formula = mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + 
##     demog_income + alc_agefirst:demog_sex, family = binomial, 
##     data = nsduh)
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    7.37354    0.82921   8.892  < 2e-16 ***
## alc_agefirst                  -0.33782    0.04229  -7.988 1.38e-15 ***
## demog_age_cat626-34           -0.29506    0.33145  -0.890   0.3733    
## demog_age_cat635-49           -0.81603    0.29870  -2.732   0.0063 ** 
## demog_age_cat650-64           -0.68657    0.30071  -2.283   0.0224 *  
## demog_age_cat665+             -1.26004    0.30636  -4.113 3.91e-05 ***
## demog_sexMale                 -2.13813    0.98473  -2.171   0.0299 *  
## demog_income$20,000 - $49,999 -0.53035    0.26822  -1.977   0.0480 *  
## demog_income$50,000 - $74,999 -0.09306    0.30727  -0.303   0.7620    
## demog_income$75,000 or more   -0.36288    0.25466  -1.425   0.1542    
## alc_agefirst:demog_sexMale     0.11893    0.05552   2.142   0.0322 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1141.5  on 842  degrees of freedom
## Residual deviance:  930.9  on 832  degrees of freedom
##   (157 observations deleted due to missingness)
## AIC: 952.9
## 
## Number of Fisher Scoring iterations: 5
Odds_int <- tidy(
  mdl.int, 
  exponentiate = TRUE,
  conf.int = TRUE
  )

tribble(
  ~Full_model, ~AOR,  ~pvalue, 
  "alc_agefirst", "0.713 CI [0.654, 0.772]", "1.38e-15",
  "demog_age_cat626-34", "0.744 CI [0.385, 1.42]", "3.73e-1",  
  "demog_age_cat635-49", "0.442 CI [0.243, 0.785]", "6.30e-3",  
  "demog_age_cat650-64", "0.503 CI [0.275, 0.897]", "2.24e-2",
  "demog_age_cat665+", "0.284 CI [0.153, 0.511]", "3.91e-5", 
  "demog_sexMale", "0.118 CI [0.0167, 0.800]", "2.99e-2 ",
  "demog_income$20,000 - $49,999", "0.588 CI [0.346, 0.991]", "4.80e-2",
  "demog_income$50,000 - $74,999", "0.911 CI [0.496, 1.66]", "7.62e-1",
  "demog_income$75,000 or more", "0.696 CI [0.419, 1.14]", "1.54e-1",
  "alc_agefirst:demog_sexMale", "1.13 CI [1.01, 1.26]", "3.22e-2"
) |> gt()
Full_model AOR pvalue
alc_agefirst 0.713 CI [0.654, 0.772] 1.38e-15
demog_age_cat626-34 0.744 CI [0.385, 1.42] 3.73e-1
demog_age_cat635-49 0.442 CI [0.243, 0.785] 6.30e-3
demog_age_cat650-64 0.503 CI [0.275, 0.897] 2.24e-2
demog_age_cat665+ 0.284 CI [0.153, 0.511] 3.91e-5
demog_sexMale 0.118 CI [0.0167, 0.800] 2.99e-2
demog_income$20,000 - $49,999 0.588 CI [0.346, 0.991] 4.80e-2
demog_income$50,000 - $74,999 0.911 CI [0.496, 1.66] 7.62e-1
demog_income$75,000 or more 0.696 CI [0.419, 1.14] 1.54e-1
alc_agefirst:demog_sexMale 1.13 CI [1.01, 1.26] 3.22e-2
lrtest(mdl.full,mdl.int)
## Likelihood ratio test
## 
## Model 1: mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income
## Model 2: mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + 
##     alc_agefirst:demog_sex
##   #Df  LogLik Df  Chisq Pr(>Chisq)  
## 1  10 -467.78                       
## 2  11 -465.45  1 4.6556    0.03095 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

EXERCISE 7

Instruction: Replicate the model summary shown below, and discuss its main features. Use the likelihood ratio test to determine which model is best, and discuss the association between age of first alcohol and lifetime marijuana use, when comparing males to females.

Answer: Lifetime marijuana use is associated with age at first use of alcohol, sex, and current age. According the AIC, log-likelihood, and F-statistics, the best fitting model is the interaction model. addition of interaction terms significantly improve the model, and this model showed significant interaction between age at first of alcohol use and sex on lifetime marijuana use. Although singular effect of sex shows lower risk in males compare to female, since there is positive interaction effect of sex and age at first alcohol use, males still have higher risk of lifetime marijuana use at every increase of age at firs alcohol use than female.

M.unadjusted <- glm(mj_lifetime ~ alc_agefirst, family=binomial, data=nsduh)
summary(M.unadjusted)
## 
## Call:
## glm(formula = mj_lifetime ~ alc_agefirst, family = binomial, 
##     data = nsduh)
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept)    5.3407     0.4747   11.25   <2e-16 ***
## alc_agefirst  -0.2835     0.0267  -10.62   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1141.45  on 842  degrees of freedom
## Residual deviance:  968.44  on 841  degrees of freedom
##   (157 observations deleted due to missingness)
## AIC: 972.44
## 
## Number of Fisher Scoring iterations: 5
M.adjusted <- glm(mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income, family=binomial, data =nsduh)
summary(M.adjusted)
## 
## Call:
## glm(formula = mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + 
##     demog_income, family = binomial, data = nsduh)
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    6.25417    0.59136  10.576  < 2e-16 ***
## alc_agefirst                  -0.27541    0.02756  -9.992  < 2e-16 ***
## demog_age_cat626-34           -0.29619    0.32865  -0.901  0.36746    
## demog_age_cat635-49           -0.80427    0.29656  -2.712  0.00669 ** 
## demog_age_cat650-64           -0.68991    0.29854  -2.311  0.02084 *  
## demog_age_cat665+             -1.27475    0.30429  -4.189  2.8e-05 ***
## demog_sexMale                 -0.06089    0.16181  -0.376  0.70669    
## demog_income$20,000 - $49,999 -0.53088    0.26641  -1.993  0.04629 *  
## demog_income$50,000 - $74,999 -0.07931    0.30488  -0.260  0.79476    
## demog_income$75,000 or more   -0.36120    0.25323  -1.426  0.15376    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1141.45  on 842  degrees of freedom
## Residual deviance:  935.55  on 833  degrees of freedom
##   (157 observations deleted due to missingness)
## AIC: 955.55
## 
## Number of Fisher Scoring iterations: 5
M.interaction <- glm(mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex, family=binomial, data =nsduh)
summary(M.interaction)
## 
## Call:
## glm(formula = mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + 
##     demog_income + alc_agefirst:demog_sex, family = binomial, 
##     data = nsduh)
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    7.37354    0.82921   8.892  < 2e-16 ***
## alc_agefirst                  -0.33782    0.04229  -7.988 1.38e-15 ***
## demog_age_cat626-34           -0.29506    0.33145  -0.890   0.3733    
## demog_age_cat635-49           -0.81603    0.29870  -2.732   0.0063 ** 
## demog_age_cat650-64           -0.68657    0.30071  -2.283   0.0224 *  
## demog_age_cat665+             -1.26004    0.30636  -4.113 3.91e-05 ***
## demog_sexMale                 -2.13813    0.98473  -2.171   0.0299 *  
## demog_income$20,000 - $49,999 -0.53035    0.26822  -1.977   0.0480 *  
## demog_income$50,000 - $74,999 -0.09306    0.30727  -0.303   0.7620    
## demog_income$75,000 or more   -0.36288    0.25466  -1.425   0.1542    
## alc_agefirst:demog_sexMale     0.11893    0.05552   2.142   0.0322 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1141.5  on 842  degrees of freedom
## Residual deviance:  930.9  on 832  degrees of freedom
##   (157 observations deleted due to missingness)
## AIC: 952.9
## 
## Number of Fisher Scoring iterations: 5
modelsummary(
  list(
    Unadjusted = M.unadjusted,
    Adjusted = M.adjusted,
    Interaction = M.interaction
  ),
  stars = TRUE
)
Unadjusted Adjusted Interaction
(Intercept) 5.341*** 6.254*** 7.374***
(0.475) (0.591) (0.829)
alc_agefirst -0.284*** -0.275*** -0.338***
(0.027) (0.028) (0.042)
demog_age_cat626-34 -0.296 -0.295
(0.329) (0.331)
demog_age_cat635-49 -0.804** -0.816**
(0.297) (0.299)
demog_age_cat650-64 -0.690* -0.687*
(0.299) (0.301)
demog_age_cat665+ -1.275*** -1.260***
(0.304) (0.306)
demog_sexMale -0.061 -2.138*
(0.162) (0.985)
demog_income$20,000 - $49,999 -0.531* -0.530*
(0.266) (0.268)
demog_income$50,000 - $74,999 -0.079 -0.093
(0.305) (0.307)
demog_income$75,000 or more -0.361 -0.363
(0.253) (0.255)
alc_agefirst × demog_sexMale 0.119*
(0.056)
Num.Obs. 843 843 843
AIC 972.4 955.6 952.9
BIC 981.9 1002.9 1005.0
Log.Lik. -484.219 -467.776 -465.448
F 112.743 14.804 13.139
RMSE 0.44 0.43 0.43
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

EXERCISE 8

Instruction: Replicate the forest plot shown below, using centralized variables scaled such that standard deviations are 0.5 (you can use the function datawizard::standardize(two_sd = TRUE). What is the advantage of this plot compared to the model summary tables shown above?

Answer: This forest plot helps to visualize the effect of independent variables on the outcome. Also, we can clearly see how far it is from zero. We can see which variable is the most influential on the outcome.

nsduh.ctr <- nsduh |> standardize(two_sd = TRUE)


# Fitting the model
M.interaction.ctr <- glm(mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex, family=binomial, data =nsduh.ctr)

# creating a forest plot
M.interaction.ctr %>% 
  model_parameters() %>% 
  plot() + xlab("Log-Odds (standardize)")

EXERCISE 9

Question: We want to continue exploring the association between age of first alcohol use and lifetime marijuana use, and how this association varies between males and females. Try to replicate the following graphs, and interpret what you see. Note also that something interesting happens at the age of 18. What is special about that age, according to the two graphs? Is the difference between the predicted outcomes of males and females significant at any age bracket? If so, what is the age bracket?

Answer: There is a significant interaction between age at first use of alcohol and sex. The probability of lifetime use of marijuana is higher in female if they start drink alcohol at early age (before ~18 y.o), but then the probability decreases as the age at first use of alcohol increases. If they start drink alcohol after age ~18, males have higher probability of lifetime marijuana use compare to female (Figure 1). There is no probability difference between male and female if starting alcohol drinking at age 18 (Figure 2). As in figure 3 and 4, the (log) odds ratio of lifetime marijuana use decreases as age at first use of alcohol increases. after 18 years, the (log) odds in female is lower than males. The risk ratio also shows lower risk of lifetime marijuana use in female compare to male after 18 years. If we look at the confidence interval, the age brackets would be between 12 to 25 years old.

mdl.int <- glm(mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex, family = binomial, data = nsduh)


plot_predictions(mdl.int, 
                 condition = c("alc_agefirst", "demog_sex"))

plot_comparisons(
  mdl.int, 
  variables = list(
    demog_sex = c("Male", "Female")
    ), 
  comparison = "difference",
  condition = "alc_agefirst")

plot_comparisons(
  mdl.int,
  variables = list(
     demog_sex = c("Male", "Female")
   ),
  comparison = "lnor",
  transform= "exp",
  conf_level = 0.95,
  condition = c("alc_agefirst"))

plot_comparisons(
  mdl.int, 
  variables = list(
    demog_sex = c("Male", "Female")
    ), 
  comparison = "lnor",
  condition = "alc_agefirst")

plot_comparisons(
  mdl.int, 
  variables = list(
    demog_sex = c("Male", "Female")
    ), 
  comparison = "ratio",
  condition = "alc_agefirst")