## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## 
## Attaching package: 'table1'
## 
## 
## The following objects are masked from 'package:base':
## 
##     units, units<-
## 
## 
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## 
## Loading required package: carData
## 
## 
## Attaching package: 'car'
## 
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## 
## The following object is masked from 'package:purrr':
## 
##     some
## 
## 
## # Attaching packages: easystats 0.6.0 (red = needs update)
## ✔ bayestestR  0.13.1   ✔ correlation 0.8.4 
## ✔ datawizard  0.9.0    ✔ effectsize  0.8.6 
## ✖ insight     0.19.6   ✔ modelbased  0.8.6 
## ✖ performance 0.10.5   ✖ parameters  0.21.2
## ✔ report      0.5.7    ✖ see         0.8.0 
## 
## Restart the R-Session and update packages in red with `easystats::easystats_update()`.
## 
## 
## 
## Attaching package: 'janitor'
## 
## 
## The following object is masked from 'package:insight':
## 
##     clean_names
## 
## 
## The following objects are masked from 'package:datawizard':
## 
##     remove_empty, remove_empty_rows
## 
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
## 
## 
## Loading required package: zoo
## 
## 
## Attaching package: 'zoo'
## 
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## 
## Attaching package: 'modelsummary'
## 
## 
## The following object is masked from 'package:parameters':
## 
##     supported_models
## 
## 
## The following object is masked from 'package:insight':
## 
##     supported_models

Exercise 1

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

nsduh$mj_lifetime <- factor(nsduh$mj_lifetime, 
         levels=c("No", "Yes"))

nsduh$demog_age_cat6 <- factor(nsduh$demog_age_cat6,
          levels = c("18-25", "26-34", "35-49", "50-64", "65+"))

nsduh$demog_sex <- factor(nsduh$demog_sex,
          levels = c("Female", "Male"))

nsduh$demog_income <- factor(nsduh$demog_income,
          levels = c("Less than $20,000", "$20,000 - $49,999", "$50,000 - $74,999", "$75,000 or more"))

label(nsduh$alc_agefirst) <- "Alcohol (age first used)"
label(nsduh$demog_age_cat6) <- "Age"
label(nsduh$demog_sex) <- "Sex"
label(nsduh$demog_income) <- "Income"

caption = "Table 1: Demographic stratified by lifetime marijuana use."

table1(~ demog_sex + alc_agefirst + demog_age_cat6 + demog_income | mj_lifetime, overall=F, caption = caption, data = nsduh)
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%)
nsduh |>
  ggpairs(c("alc_agefirst", "demog_age_cat6", "demog_sex", "demog_income"), 
          mapping = ggplot2::aes(color = mj_lifetime), 
          title = "Lifetime marijuana use", 
          columnLabels = c("Alcohol (age first used)", "Age", "Sex", "Income"),
          proportions = "auto", legend = c(2,2))
## Warning: Removed 157 rows containing non-finite values (`stat_density()`).
## Warning: Removed 157 rows containing non-finite values (`stat_boxplot()`).
## Removed 157 rows containing non-finite values (`stat_boxplot()`).
## Removed 157 rows containing non-finite values (`stat_boxplot()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 157 rows containing non-finite values (`stat_bin()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 157 rows containing non-finite values (`stat_bin()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 157 rows containing non-finite values (`stat_bin()`).

Exercise 2

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?

# Showing absolute numbers
nsduh |> 
  tabyl(demog_sex, mj_lifetime) |> 
  adorn_title()
##            mj_lifetime    
##  demog_sex          No Yes
##     Female         285 249
##       Male         206 260
# Showing percentages
nsduh |>
  tabyl(demog_sex, mj_lifetime) |> 
  adorn_percentages() |> 
  adorn_pct_formatting() |> 
  adorn_title()
##            mj_lifetime      
##  demog_sex          No   Yes
##     Female       53.4% 46.6%
##       Male       44.2% 55.8%
# Replace the blankss below with appropriate values
nsduh_prob <- tribble(
  ~Status, ~Probability,
  "General", 0.509,
  "Female", 0.466,
  "Male", 0.558
) %>%
  mutate(Odds = Probability / (1 - Probability)) %>%
  mutate(logOdds = log(Odds))

tribble(
  ~`Indicators of chance`, ~General, ~Female, ~Male, 
  "Probability", 0.509, 0.466, 0.558, 
  "Odds",        1.0366599, 0.8726592, 1.2624434, 
  "Log Odds",    0.03600389, -0.13621020, 0.23304908
) |> gt()
Indicators of chance General Female Male
Probability 0.50900000 0.4660000 0.5580000
Odds 1.03665990 0.8726592 1.2624434
Log Odds 0.03600389 -0.1362102 0.2330491
# Replace the 0's below with appropriate values
tribble(
  ~`Indicators of contrast`, ~`Males vs. Females`, 
  "Risk difference", 0.092, 
  "Risk Ratio",      1.197425,
  "Odds ratio",      1.446663, 
  "Log odds ratio",  0.3692595
) |> gt()
Indicators of contrast Males vs. Females
Risk difference 0.0920000
Risk Ratio 1.1974250
Odds ratio 1.4466630
Log odds ratio 0.3692595

To conclude, the risk difference is 0.09, the risk ratio is 1.2 and the odds ratio is 1.45. Interpretation: The probability results show that, in the sample, males have a higher likelihood of reporting lifetime marijuana use compared to females. The odds results indicate that the odds of reporting marijuana use are higher in the general sample and among males, while females have lower odds. The log odds results suggest positive log odds for both the general sample and males, indicating a higher likelihood of marijuana use, while females have negative log odds, indicating a lower likelihood.

Exercise 3

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?

#################
# 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)
tidy(
  mdl.glm.null, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 1 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1   0.0360  -0.0880     0.160
# Odds of lifetime marijuana (everyone)
tidy(
  mdl.glm.null, 
  exponentiate = TRUE,
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 1 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1     1.04    0.916      1.17
# Probability of lifetime marijuana (everyone)
tidy(
  mdl.glm.null, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high) |> 
  mutate_all(plogis)
## # A tibble: 1 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1    0.509    0.478     0.540
#################
# 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 )
summary(mdl.lm.null)
## 
## Call:
## lm(formula = mj_lifetime.numeric ~ 1, data = nsduh)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -0.509 -0.509  0.491  0.491  0.491 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.50900    0.01582   32.18   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5002 on 999 degrees of freedom
# Probability of lifetime marijuana (everyone) using linear regression
tidy(
  mdl.lm.null, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 1 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1    0.509    0.478     0.540
########################
# The unadjusted model
#######################

# Now use the logistic and linear model, but this time 
# Using the formula `mj_lifetime.numeric ~ demog_sex` 
# Logistic Regression
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 (Male vs. Female)
tidy(
  mdl.glm, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 2 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1   -0.135   -0.305    0.0348
## 2    0.368    0.119    0.618
# Odds of lifetime marijuana (Male vs. Female)
tidy(
  mdl.glm, 
  exponentiate = TRUE,
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 2 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1    0.874    0.737      1.04
## 2    1.44     1.13       1.86
# Probability of lifetime marijuana (Male vs. Female)
tidy(
  mdl.glm, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high) |> 
  mutate_all(plogis)
## # A tibble: 2 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1    0.466    0.424     0.509
## 2    0.591    0.530     0.650
# Linear Regression
mdl.lm  <- mdl.lm <- lm(mj_lifetime.numeric ~ demog_sex, data = nsduh )
summary(mdl.lm)
## 
## Call:
## lm(formula = mj_lifetime.numeric ~ demog_sex, data = nsduh)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5579 -0.4663  0.4421  0.4421  0.5337 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    0.46629    0.02156  21.623   <2e-16 ***
## demog_sexMale  0.09165    0.03159   2.901   0.0038 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4983 on 998 degrees of freedom
## Multiple R-squared:  0.008363,   Adjusted R-squared:  0.00737 
## F-statistic: 8.417 on 1 and 998 DF,  p-value: 0.003799
# Probability of lifetime marijuana (Male vs. Female) using linear regression
tidy(
  mdl.lm, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 2 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1   0.466    0.424      0.509
## 2   0.0916   0.0297     0.154
# Comparisons
# Risk difference glm
mdl.glm |> 
  tidy(conf.int = TRUE) %>%
  avg_comparisons(
  model = mdl.glm,
  variables = "demog_sex",
  comparison = "difference"
) |> 
  select(estimate, conf.low, conf.high)
## Warning: The `demog_sex` variable is treated as a categorical (factor) variable,
##   but the original data is of class NULL. It is safer and faster to
##   convert such variables to factor before fitting the model and calling
##   `slopes` functions.
##   
##   This warning appears once per session.
## 
##  Estimate CI low CI high
##    0.0916 0.0298   0.153
## 
## Columns: estimate, conf.low, conf.high
# Risk ratio glm
mdl.glm |> 
  tidy(conf.int = TRUE) %>%
  avg_comparisons(
  model = mdl.glm,
  variables = "demog_sex",
  comparison = "ratio"
) |> 
  select(estimate, conf.low, conf.high)
## 
##  Estimate CI low CI high
##       1.2   1.05    1.34
## 
## Columns: estimate, conf.low, conf.high
# Risk difference lm
mdl.lm |> 
  tidy(conf.int = TRUE) %>%
  avg_comparisons(
  model = mdl.lm,
  variables = "demog_sex",
  comparison = "difference"
) |> 
  select(estimate, conf.low, conf.high)
## 
##  Estimate CI low CI high
##    0.0916 0.0297   0.154
## 
## Columns: estimate, conf.low, conf.high
# Risk ratio lm
mdl.lm |> 
  tidy(conf.int = TRUE) %>%
  avg_comparisons(
  model = mdl.lm,
  variables = "demog_sex",
  comparison = "ratio"
) |> 
  select(estimate, conf.low, conf.high)
## 
##  Estimate CI low CI high
##       1.2   1.05    1.34
## 
## Columns: estimate, conf.low, conf.high
# Log Odds Ratio
mdl.glm |> 
  tidy(conf.int = TRUE) %>%
  avg_comparisons(
  model = mdl.glm, 
  variables = "demog_sex",
  comparison = "lnor"
) |> 
  select(estimate, conf.low, conf.high)
## 
##  Estimate CI low CI high
##     0.368  0.118   0.617
## 
## Columns: estimate, conf.low, conf.high
# Odds Ratio
  avg_comparisons(
  model = mdl.glm, 
  variables = "demog_sex",
  comparison = "lnor",
  transform = "exp"
) |> 
  select(estimate, conf.low, conf.high, p.value)
## 
##  Estimate Pr(>|z|) CI low CI high
##      1.44  0.00388   1.13    1.85
## 
## Columns: estimate, conf.low, conf.high, p.value
# 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.591 CI [0.530, 0.650]", 
  "Odds",        "1.04 CI [0.916, 1.17]", "0.874 CI [0.737, 1.04]", "1.44 CI [1.13, 1.86]", 
  "Log Odds",    "0.0360 CI [-0.088, 0.160]", "-0.135 CI [-0.305, 0.0348]", "0.368 CI [0.119, 0.618]"
) |> gt()
Prediction General Female Male
Probability 0.509 CI [0.478, 0.540] 0.466 CI [0.424, 0.509] 0.591 CI [0.530, 0.650]
Odds 1.04 CI [0.916, 1.17] 0.874 CI [0.737, 1.04] 1.44 CI [1.13, 1.86]
Log Odds 0.0360 CI [-0.088, 0.160] -0.135 CI [-0.305, 0.0348] 0.368 CI [0.119, 0.618]
# Replace the blanks below with appropriate values
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.85]", 
  "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.85]
Log odds ratio 0.368 CI [0.118, 0.617]

The contingency table presents and summarize data well especially in categories, but it is not suitable to model or predict anything, because it is calculated by hand and therefore no complex associations can be done. With logistic regression specifically binary outcomes can be modeled and odds/probability can easily be calculated within a range from 0 to 1. Linear regression assumes a continuous outcome variable and predicting the probability of this.

Exercise 4

Write up your results using the template shown below.

Conclusion: Males have significantly higher odds of lifetime marijuana use than females (OR = 1.44 ; 95% CI = 1.13 , 1.85 p = 0.004 ). Males have 1.2% higher odds of lifetime marijuana use than females.

For this simple case with a binary outcome and a binary predictor, the odds ratio you calculated should be the same as the odds ratio obtained via the cross-product from a 2 x 2 contingency table. But what if your predictor variable is not binary, but continuous?

For a continuous predictor it becomes a bit more nuanced compared to the binary predictor case. In logistic regression, the odds ratio is associated with a one-unit change in the predictor variable. For a continuous predictor, such as age, the odds ratio represents the change in odds associated with a one-unit increase in the predictor variable. The interpretation becomes more meaningful when the continuous predictor has a meaningful unit. For example, if age is measured in years, the odds ratio represents the change in odds associated with a one-year increase in age.

Exercise 5

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.

mdl.glm <- glm(mj_lifetime ~ alc_agefirst, data = nsduh, family = "binomial")
summary(mdl.glm)
## 
## 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
# Log - odds for lifetime marijuana
tidy(
  mdl.glm, 
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 2 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1    5.34     4.44      6.30 
## 2   -0.284   -0.338    -0.233
# Odds of lifetime marijuana =
tidy(
  mdl.glm, 
  exponentiate = TRUE,
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high)
## # A tibble: 2 × 3
##   estimate conf.low conf.high
##      <dbl>    <dbl>     <dbl>
## 1  209.      84.7     545.   
## 2    0.753    0.713     0.792
# Odds Ratio
  avg_comparisons(
  model = mdl.glm, 
  variables = "alc_agefirst",
  comparison = "lnor",
  transform = "exp"
) |> 
  select(estimate, conf.low, conf.high, p.value)
## 
##  Estimate Pr(>|z|) CI low CI high
##     0.753   <0.001  0.715   0.794
## 
## Columns: estimate, conf.low, conf.high, p.value
# Log Odds Ratio
Log_odds_ratio <- avg_comparisons(
  model = mdl.glm, 
  variables = "alc_agefirst",
  comparison = "lnor"
) |> 
  select(estimate, conf.low, conf.high, p.value)

(1 - exp(Log_odds_ratio * 3)) * 100
##   estimate conf.low conf.high p.value
## 1 57.28384 63.49065  50.02184       0

Age at first alcohol use is significantly negatively associated with lifetime marijuana use (OR = 0.753 ; 95% CI = 0.715 , 0.794 ; p < 0.001 ). 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.

Exercise 6

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.

# Unadjusted
summary(mdl.glm)
## 
## 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
# Adjusted
mdl.glm.null.adj <- glm(mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income, family = "binomial", data = nsduh)
summary(mdl.glm.null.adj)
## 
## 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
# Interaction
mdl.glm.int <- glm(mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex, family = "binomial", data = nsduh)
summary(mdl.glm.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
car::Anova(mdl.glm.null.adj, 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
# Odds of lifetime marijuana (alc_agefirst)
tidy(
  mdl.glm.null.adj, 
  exponentiate = TRUE,
  conf.int = TRUE
  ) |> 
  select(estimate, conf.low, conf.high, p.value)
## # A tibble: 10 × 4
##    estimate conf.low conf.high  p.value
##       <dbl>    <dbl>     <dbl>    <dbl>
##  1  520.     169.     1722.    3.85e-26
##  2    0.759    0.718     0.800 1.65e-23
##  3    0.744    0.387     1.41  3.67e- 1
##  4    0.447    0.247     0.791 6.69e- 3
##  5    0.502    0.275     0.891 2.08e- 2
##  6    0.279    0.152     0.502 2.80e- 5
##  7    0.941    0.684     1.29  7.07e- 1
##  8    0.588    0.347     0.987 4.63e- 2
##  9    0.924    0.507     1.68  7.95e- 1
## 10    0.697    0.421     1.14  1.54e- 1
#Odds ratio of lifetime marijuana
avg_comparisons(
  model = mdl.glm.null.adj, 
  variables = c("alc_agefirst", "demog_age_cat6", "demog_sex", "demog_income"),
  comparison = "lnor",
  transform = "exp"
) |> 
  select(estimate, conf.low, conf.high, p.value)
## 
##  Estimate Pr(>|z|) CI low CI high
##     0.759  < 0.001  0.719   0.801
##     0.744  0.36746  0.391   1.416
##     0.447  0.00669  0.250   0.800
##     0.502  0.02084  0.279   0.901
##     0.279  < 0.001  0.154   0.507
##     0.588  0.04629  0.349   0.991
##     0.924  0.79476  0.508   1.679
##     0.697  0.15376  0.424   1.145
##     0.941  0.70669  0.685   1.292
## 
## Columns: estimate, conf.low, conf.high, p.value
tribble(
  ~Contrast, ~`AOR`, ~`P-value`,
  "Age at first use of Alcohol ", "0.759 CI [0.719, 0.801]", "p <0.001 ",
  "Age 26-34",      "0.744 CI [0.391, 1.416]", "p = 0.36746",
  "Age 35-49",      "0.447 CI [0.250, 0.800]", "p = 0.00669",
  "Age 50-64",  "0.502 CI [0.279, 0.901]", "p = 0.02084",
  "Age 65+",  "0.279 CI [0.154, 0.507]", "p <0.001",
  "Sex",  "0.588 CI [0.349, 0.991]", "p = 0.04629",
  "Income $20,000 - $49,999",  "0.924 CI [0.508, 1.679]", "p = 0.79476",
  "Income $50,000 - $74,999",  "0.697 CI [0.424, 1.145]", "p = 0.15376",
  "Income $75,000 or more",  "0.941 CI [0.685, 1.292]", "p = 0.70669",
) |> gt()
Contrast AOR P-value
Age at first use of Alcohol 0.759 CI [0.719, 0.801] p <0.001
Age 26-34 0.744 CI [0.391, 1.416] p = 0.36746
Age 35-49 0.447 CI [0.250, 0.800] p = 0.00669
Age 50-64 0.502 CI [0.279, 0.901] p = 0.02084
Age 65+ 0.279 CI [0.154, 0.507] p <0.001
Sex 0.588 CI [0.349, 0.991] p = 0.04629
Income $20,000 - $49,999 0.924 CI [0.508, 1.679] p = 0.79476
Income $50,000 - $74,999 0.697 CI [0.424, 1.145] p = 0.15376
Income $75,000 or more 0.941 CI [0.685, 1.292] p = 0.70669
anova(mdl.glm.null.adj, mdl.glm.int, test = "LRT")
## Analysis of Deviance Table
## 
## 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
##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)  
## 1       833     935.55                       
## 2       832     930.90  1   4.6556  0.03095 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Interpreting the output: 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 30,9% lower odds of lifetime marijuana use than 18-25 year-olds (OR = 0.447 ; 95% CI = 0.250 , 0.800 ; p = 0.00669 ). An overall 4 df p-value for age can be read from the Type III Test table. It is significant at p < 0.0001 . An overall, 3 df p-value for income is not significant at (p = 0.138 ). 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.719 , 0.801 ; p < 0.001 ). Individuals who first used alcohol at a given age have 43,2% 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 = 0299). A likelihood ratio test shows that the adjusted model with the interaction is superior to the one without the interaction (p = 0.03095)

Exercise 7

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.

modelsummary(
  list(
    undadjusted = mdl.glm,
    adjusted = mdl.glm.null.adj,
    interaction = mdl.glm.int
    ),
  coef_rename = c("alc_agefirst" = "Alcohol (age first used)", "demog_age_cat626-34" = "Age [26-34]", "demog_age_cat635-49" = "Age [35-49]", "demog_age_cat650-64" = "Age [50-64]", "demog_age_cat665+" = "Age [65+]", "demog_sexMale" = "Sex [Male]", "demog_income20,000−
49,999" = "Income [$20,000 - $49,999]", "demog_income50,000−
74,999" = "Income [$50,000 - $74,999]", "demog_income$75,000 or more" = "Income [$75,000 or more]", "Alcohol (age first used):demog_sexMale" = "Alcohol (age first used) × Sex [Male]"),
  stars = TRUE
  )
undadjusted adjusted interaction
(Intercept) 5.341*** 6.254*** 7.374***
(0.475) (0.591) (0.829)
Alcohol (age first used) −0.284*** −0.275*** −0.338***
(0.027) (0.028) (0.042)
Age [26-34] −0.296 −0.295
(0.329) (0.331)
Age [35-49] −0.804** −0.816**
(0.297) (0.299)
Age [50-64] −0.690* −0.687*
(0.299) (0.301)
Age [65+] −1.275*** −1.260***
(0.304) (0.306)
Sex [Male] −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)
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
anova(mdl.glm, mdl.glm.null.adj, mdl.glm.int, test = "LRT")
## Analysis of Deviance Table
## 
## Model 1: mj_lifetime ~ alc_agefirst
## Model 2: mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income
## Model 3: mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + 
##     alc_agefirst:demog_sex
##   Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
## 1       841     968.44                          
## 2       833     935.55  8   32.886 6.457e-05 ***
## 3       832     930.90  1    4.656   0.03095 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

In all models there is a significantly negative association between marijuana use and the age alcohol was first used. Certain age categories are significantly associated, while others are not. Only when a interaction term is added, being a male is significantly associated. The LRT shows that the interaction model fits best, what is also reflected by the AIC, but not the BIC. This indicates that lifetime marijuana use is associated with age of first use of alcohol and being a male.

Exercise 8

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?

# Scaling
nsduh.ctr <- nsduh |>
  datawizard::standardize(two_sd = TRUE)

# Fitting the model
mdl.glm.int.ctr <- glm(mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex, family = "binomial", data = nsduh.ctr)
summary(mdl.glm.int.ctr)
## 
## Call:
## glm(formula = mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + 
##     demog_income + alc_agefirst:demog_sex, family = "binomial", 
##     data = nsduh.ctr)
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    1.46357    0.31860   4.594 4.35e-06 ***
## alc_agefirst                  -2.98057    0.37315  -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                 -0.05751    0.16240  -0.354   0.7232    
## 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     1.04932    0.48987   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
# creating a forest plot
mdl.glm.int.ctr %>% 
  model_parameters() %>%
  plot()

It provides a visual summary of the model coefficients, which makes it easier to compare the magnitude and directions of effects. Condense complex information is transformed into a compact form, which makes provides a quick overview. The length of each bar represents the confidence interval for each coefficient. Wider bars indicate higher uncertainty, while narrower bars suggest more precision in the estimate. This visual representation makes it easier to identify predictors with wide confidence intervals, highlighting areas of uncertainty in the model. For models with interaction terms, forest plots can effectively illustrate the main effects and interaction effects, providing a comprehensive view of how predictors influence the outcome.

Exercise 9

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?

# First Graph
mdl.int <- glm(mj_lifetime ~ alc_agefirst + demog_sex + alc_agefirst:demog_sex, family = "binomial", data = nsduh)

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

# Second Graph
fig_b <- plot_comparisons(
  mdl.int, 
  variables = list(
    demog_sex = c("Male", "Female")
    ), 
  condition = "alc_agefirst")

# Final graph
library(cowplot)
## 
## Attaching package: 'cowplot'
## The following object is masked from 'package:lubridate':
## 
##     stamp
plot_grid(fig_a, fig_b,
          nrow = 2, align = "hv", axis = "tblr", labels = c("A", "B"), 
          label_size = 15, hjust = -0.1, vjust = 1.2)

From the predicted probability graph and the probability difference graph, it appears that age 18 is the critical point where there is a change in the predicted outcome for both males and females.Before age 18, females have a higher probability of lifetime marijuana use, but after age 18, males surpass females in predicted probabilities.From the probability difference graph you see this as well where the point of inflection changes at 18 years of first alcohol use and that it is steeper.The significant difference between predicted outcomes for males and females is suggested by the change in the direction of the curves at the age of 18. As mentioned this can be seen at the intersection of the slopes in the predicted probability graph and the point of inflection in the probability difference graph.This is also seen when you look at the age of 18 that the outcome changes in all other graphs as well.