nsduh_table<-nsduh
label(nsduh_table$demog_sex)<- "Sex"
label(nsduh_table$alc_agefirst)<- "Alcohol (age first used)"
label(nsduh_table$demog_age_cat6)<-"Age"
label(nsduh_table$demog_income)<- "Income"
table1(~ demog_sex + alc_agefirst + demog_age_cat6 + demog_income | mj_lifetime, data=nsduh_table, overall = F)| 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_figure <- nsduh[, c(1, 3, 4, 5, 6)]
nsduh_figure$mj_lifetime <- factor(nsduh_figure$mj_lifetime, levels = c("Yes", "No"))
ggpairs(nsduh_figure, columns = 2:5, aes(color = mj_lifetime), legend = 1,
columnLabels = c("Alcohol (age first used)", "Age", "Sex", "Income"),
upper = list(continuous = wrap("density"), combo = wrap("box", outlier.size=0.5), discrete = wrap("colbar", fontface = "bold", size=2)),
lower = list(continuous = wrap("cor"), combo = wrap("dot", size=0.2, alpha=0.5), discrete = wrap("crosstable", fontface = "bold", size=2, cells = "col.prop", fill = "std.resid")),
diag = list(continuous = wrap("densityDiag", alpha = 0.5, color=NA), discrete = wrap("densityDiag", alpha = 0.5))) +
theme_minimal() +
theme(legend.position = 'bottom', legend.direction = "horizontal", axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(fill='Marijuana use')## Warning: Removed 157 rows containing non-finite values (`stat_density()`).
## 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()`).
## Warning: Removed 157 rows containing missing values (`geom_point()`).
## Removed 157 rows containing missing values (`geom_point()`).
## Removed 157 rows containing missing values (`geom_point()`).
###
Exercise 2
## mj_lifetime
## demog_sex No Yes
## Female 285 249
## Male 206 260
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%
tribble(
~Prediction, ~General, ~Female, ~Male,
"Probability", "50.90%", "46.63%","55.79%" ,
"Odds", "1.037", "0.873","1.262",
"Log Odds", "0.036", "-0.136", "0.233"
) |> gt()| Prediction | General | Female | Male |
|---|---|---|---|
| Probability | 50.90% | 46.63% | 55.79% |
| Odds | 1.037 | 0.873 | 1.262 |
| Log Odds | 0.036 | -0.136 | 0.233 |
tribble(
~Contrast, ~`Males vs. Females`,
"Risk difference", "9.16%",
"Risk Ratio", "1.196",
"Odds ratio", "1.446",
"Log odds ratio", "0.368"
) |> gt()| Contrast | Males vs. Females |
|---|---|
| Risk difference | 9.16% |
| Risk Ratio | 1.196 |
| Odds ratio | 1.446 |
| Log odds ratio | 0.368 |
#null_logistic model for all samples
null.log <- glm(
mj_lifetime ~ 1,
data = nsduh,
family = binomial
)
summary(null.log)##
## 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
## # A tibble: 1 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 0.0360 0.0633 0.569 0.569 -0.0880 0.160
## # A tibble: 1 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 1.04 0.0633 0.569 0.569 0.916 1.17
#probability
tidy(
null.log,
conf.int = TRUE
) |>
select(estimate, conf.low, conf.high) |>
mutate_all(plogis) #probability## # A tibble: 1 × 3
## estimate conf.low conf.high
## <dbl> <dbl> <dbl>
## 1 0.509 0.478 0.540
#sex_logistic model
sex.log <- glm(
mj_lifetime ~ demog_sex,
data = nsduh,
family = binomial
)
summary(sex.log)##
## 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
#to calculate female's data (female as default), use similar code like above
#log odds [femal=intercept, male = intercept + demog_sexMale]
logodds.log<-tidy(
sex.log,
conf.int = TRUE
)
#odds [femal=intercept, male = intercept + demog_sexMale]
odds.log<-tidy(
sex.log,
exponentiate = TRUE,
conf.int = TRUE
)
#probability [femal=intercept, male = intercept + demog_sexMale]
probability.log<-tidy(
sex.log,
conf.int = TRUE
) |>
select(estimate, conf.low, conf.high) |>
mutate_all(plogis)
print(logodds.log)## # A tibble: 2 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) -0.135 0.0867 -1.56 0.120 -0.305 0.0348
## 2 demog_sexMale 0.368 0.127 2.89 0.00388 0.119 0.618
## # A tibble: 2 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 0.874 0.0867 -1.56 0.120 0.737 1.04
## 2 demog_sexMale 1.44 0.127 2.89 0.00388 1.13 1.86
## # 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
#to calculate the male data
male.logodds.log.estimate <- logodds.log$estimate[1] + logodds.log$estimate[2]
male.logodds.log.conf.low <- logodds.log$conf.low[1] + logodds.log$conf.low[2]
male.logodds.log.conf.high <- logodds.log$conf.high[1] + logodds.log$conf.high[2]
#note:e^(b0+b1*X1)=e^b0 * e^b1*X1, use * but not +
male.odds.log.estimate <- odds.log$estimate[1] * odds.log$estimate[2]
male.odds.log.conf.low <- odds.log$conf.low[1] * odds.log$conf.low[2]
male.odds.log.conf.high <- odds.log$conf.high[1] * odds.log$conf.high[2]
male.probability.log.estimate <- plogis(male.logodds.log.estimate)
male.probability.log.conf.low <- plogis(male.logodds.log.conf.low)
male.probability.log.conf.high <- plogis(male.logodds.log.conf.high)
#for test the results: probability = odds/(1+odds), you could try it if you want
#test1<- male.odds.log.estimate/(1+male.odds.log.estimate)
#test2<- male.odds.log.conf.low/(1+male.odds.log.conf.low)
#test3<- male.odds.log.conf.high/(1+male.odds.log.conf.high)
#based on sex logistic regression model
tribble(
~Prediction, ~General, ~Female, ~Male,
"Probability", "50.90% CI [47.80%, 53.99%]", "46.63% CI [42.42%, 50.87%]", "55.79% CI [45.34%, 65.77%]",
"Odds", "1.04 CI [0.92, 1.17]", "0.87 CI [0.74, 1.04]", "1.26 CI [0.83, 1.92]",
"Log Odds", "0.04 CI [-0.09, 0.16]", "-0.14 CI [-0.31, 0.03]", " 0.23 CI [-0.19, 0.65]"
) %>%
gt() %>%
tab_header(
title = "Estimate results from logstic regression model [Prediction]"
)| Estimate results from logstic regression model [Prediction] | |||
| Prediction | General | Female | Male |
|---|---|---|---|
| Probability | 50.90% CI [47.80%, 53.99%] | 46.63% CI [42.42%, 50.87%] | 55.79% CI [45.34%, 65.77%] |
| Odds | 1.04 CI [0.92, 1.17] | 0.87 CI [0.74, 1.04] | 1.26 CI [0.83, 1.92] |
| Log Odds | 0.04 CI [-0.09, 0.16] | -0.14 CI [-0.31, 0.03] | 0.23 CI [-0.19, 0.65] |
library(marginaleffects)
avg_comparisons(
model = sex.log,
variables = "demog_sex",
comparison = "difference") #risk difference##
## Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
## demog_sex Male - Female 0.0916 0.0315 2.9 0.00367 8.1 0.0298 0.153
##
## Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
## Type: response
##
## Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
## demog_sex Male / Female 1.2 0.0742 16.1 <0.001 192.0 1.05 1.34
##
## Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
## Type: response
##
## Term Contrast Estimate Std. Error z Pr(>|z|) S
## demog_sex ln(odds(Male) / odds(Female)) 0.368 0.127 2.89 0.00388 8.0
## 2.5 % 97.5 %
## 0.118 0.617
##
## Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
## Type: response
tribble(
~Contrast, ~`Males vs. Females`,
"Risk difference", "9.16% CI [2.98%, 15.30%]",
"Risk Ratio", "1.20 CI [1.05, 1.34]",
"Odds ratio", "1.44 CI [1.13, 1.86]", #e^b1
"Log odds ratio", "0.37 CI [0.12, 0.62]" #b1
) %>%
gt() %>%
tab_header(
title = "Estimate results from logistic regression model [Contrast]"
)| Estimate results from logistic regression model [Contrast] | |
| Contrast | Males vs. Females |
|---|---|
| Risk difference | 9.16% CI [2.98%, 15.30%] |
| Risk Ratio | 1.20 CI [1.05, 1.34] |
| Odds ratio | 1.44 CI [1.13, 1.86] |
| Log odds ratio | 0.37 CI [0.12, 0.62] |
#null_linear
null.line <- lm(mj_lifetime.numeric ~ 1, data = nsduh)
#sex_linear
sex.line <- lm(mj_lifetime.numeric ~ demog_sex, data = nsduh)
tribble(
~Prediction, ~General, ~Female, ~Male,
"Probability", "50.90% CI [47.80%, 54.00%]", "46.63% CI [42.40%, 50.86%]", "55.79% CI [45.36%, 66.22%]",
"Odds", "1.04 CI [0.92, 1.17]", "0.87 CI [0.74, 1.04]", "1.26 CI [0.83, 1.96]",
"Log Odds", "0.04 CI [-0.09, 0.16]", "-0.14 CI [-0.31, 0.03]", " 0.23 CI [-0.19, 0.67]"
) %>%
gt() %>%
tab_header(title = "Estimate results from linear regression model [Prediction]"
)| Estimate results from linear regression model [Prediction] | |||
| Prediction | General | Female | Male |
|---|---|---|---|
| Probability | 50.90% CI [47.80%, 54.00%] | 46.63% CI [42.40%, 50.86%] | 55.79% CI [45.36%, 66.22%] |
| Odds | 1.04 CI [0.92, 1.17] | 0.87 CI [0.74, 1.04] | 1.26 CI [0.83, 1.96] |
| Log Odds | 0.04 CI [-0.09, 0.16] | -0.14 CI [-0.31, 0.03] | 0.23 CI [-0.19, 0.67] |
avg_comparisons(
model = sex.line,
variables = "demog_sex",
comparison = "difference") #risk difference##
## Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
## demog_sex Male - Female 0.0916 0.0316 2.9 0.00372 8.1 0.0297 0.154
##
## Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
## Type: response
##
## Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
## demog_sex Male / Female 1.2 0.0742 16.1 <0.001 191.7 1.05 1.34
##
## Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
## Type: response
##
## Term Contrast Estimate Std. Error z Pr(>|z|) S
## demog_sex ln(odds(Male) / odds(Female)) 0.368 0.128 2.88 0.00393 8.0
## 2.5 % 97.5 %
## 0.118 0.618
##
## Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
## Type: response
tribble(
~Contrast, ~`Males vs. Females`,
"Risk difference", "9.16% CI [2.97%, 15.40%]",
"Risk Ratio", "1.20 CI [1.05, 1.34]",
"Odds ratio", "1.44 CI [1.13, 1.86]", # !!!not sure about this one, please check!
"Log odds ratio", "0.37 CI [0.12, 0.62]"
) %>%
gt() %>%
tab_header(
title = "Estimate results from linear regression model [Contrast]"
)| Estimate results from linear regression model [Contrast] | |
| Contrast | Males vs. Females |
|---|---|
| Risk difference | 9.16% CI [2.97%, 15.40%] |
| Risk Ratio | 1.20 CI [1.05, 1.34] |
| Odds ratio | 1.44 CI [1.13, 1.86] |
| Log odds ratio | 0.37 CI [0.12, 0.62] |
Answer: Q1:what are the differences between the three approaches (using a contingency table as in the question above, using logistic regression and using linear regression)? A1: In this case, we did not found importance difference in results from different approach, only a little differences in CI.
Q2: What explains these differences (or lack thereof)? A2: The possible reason could be: 1) Strong Association: If there is a strong and straightforward association between the variables, all three methods might similarly capture this relationship. 2)Limited Variability: With limited variability or very distinct grouping in the data, the patterns might be evident enough to be similarly captured by all methods. 3)Homogeneity: If the dataset is not diverse and exhibits homogeneity in responses, different analytical approaches might converge on similar results.
Q3: What are the advantages/drawbacks of using one approach over the other? A3: Contingency table is best for preliminary analysis to detect the presence of an association, because it is easy to create and understand. However, it does not model the relationship or provide predictive insights. For logistic regression, it can model relationships and quantify the effect of predictors on the outcome, so that it is useful for prediction and understanding the influence of predictors. Comparing with contigency table, it is less intuitive to understand compared to contingency tables. For linear regression, it is inappropriate for categorical outcomes; can lead to nonsensical predictions.
Answer Conclusion: Males have significantly higher odds of lifetime marijuana use than females (OR = 1.44; 95% CI = 1.13 , 1.86 p = 0.004 ). Males have 44% higher odds of lifetime marijuana use than females.
Q: 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? A: When the predictor is continuous, the odds ratio reflects the change in odds associated with a one-unit increase in the predictor, unlike the simpler case of binary predictors where it reflects the odds of the outcome in one group versus the other. This difference makes the interpretation of odds ratios with continuous predictors less intuitive and requires careful consideration of the scale and nature of the continuous variable.
agefirst.log<-glm(
mj_lifetime ~ alc_agefirst,
data = nsduh,
family = binomial
)
summary(agefirst.log)##
## 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
## # A tibble: 2 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 209. 0.475 11.3 2.29e-29 84.7 545.
## 2 alc_agefirst 0.753 0.0267 -10.6 2.46e-26 0.713 0.792
Answer Age at first alcohol use is significantly negatively associated with lifetime marijuana use (OR = 0.75; 95% CI = 0.71, 0.79 ; p < 0.001 ). Individuals who first used alcohol at age 19 years have 25% lower (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 57.81% lower odds.
adjusted.log <- glm(
mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income,
data = nsduh,
family = binomial
)
inter.log <- glm(
mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex,
data = nsduh,
family = binomial
)
lr_test <- anova(adjusted.log, inter.log, test = "Chisq")
print(lr_test)## 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
## # A tibble: 10 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 520. 0.591 10.6 3.85e-26 169. 1722.
## 2 alc_agefirst 0.759 0.0276 -9.99 1.65e-23 0.718 0.800
## 3 demog_age_cat626-34 0.744 0.329 -0.901 3.67e- 1 0.387 1.41
## 4 demog_age_cat635-49 0.447 0.297 -2.71 6.69e- 3 0.247 0.791
## 5 demog_age_cat650-64 0.502 0.299 -2.31 2.08e- 2 0.275 0.891
## 6 demog_age_cat665+ 0.279 0.304 -4.19 2.80e- 5 0.152 0.502
## 7 demog_sexMale 0.941 0.162 -0.376 7.07e- 1 0.684 1.29
## 8 demog_income$20,000… 0.588 0.266 -1.99 4.63e- 2 0.347 0.987
## 9 demog_income$50,000… 0.924 0.305 -0.260 7.95e- 1 0.507 1.68
## 10 demog_income$75,000… 0.697 0.253 -1.43 1.54e- 1 0.421 1.14
## 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
## # A tibble: 11 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 1593. 0.829 8.89 5.99e-19 337. 8717.
## 2 alc_agefirst 0.713 0.0423 -7.99 1.38e-15 0.654 0.772
## 3 demog_age_cat626-34 0.744 0.331 -0.890 3.73e- 1 0.385 1.42
## 4 demog_age_cat635-49 0.442 0.299 -2.73 6.30e- 3 0.243 0.785
## 5 demog_age_cat650-64 0.503 0.301 -2.28 2.24e- 2 0.275 0.897
## 6 demog_age_cat665+ 0.284 0.306 -4.11 3.91e- 5 0.153 0.511
## 7 demog_sexMale 0.118 0.985 -2.17 2.99e- 2 0.0167 0.800
## 8 demog_income$20,000… 0.588 0.268 -1.98 4.80e- 2 0.346 0.991
## 9 demog_income$50,000… 0.911 0.307 -0.303 7.62e- 1 0.498 1.66
## 10 demog_income$75,000… 0.696 0.255 -1.42 1.54e- 1 0.419 1.14
## 11 alc_agefirst:demog_… 1.13 0.0555 2.14 3.22e- 2 1.01 1.26
## Analysis of Deviance Table (Type III tests)
##
## Response: mj_lifetime
## LR Chisq Df Pr(>Chisq)
## alc_agefirst 108.028 1 < 2.2e-16 ***
## demog_age_cat6 23.248 4 0.000113 ***
## demog_sex 4.797 1 0.028506 *
## demog_income 5.296 3 0.151361
## alc_agefirst:demog_sex 4.656 1 0.030953 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Answer The AOR for our primary predictor alc_agefirst is 0.76. 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.26%(lower/higher) odds of lifetime marijuana use than 18-25 year-olds (OR = 0.45 ; 95% CI = 0.25 , 0.79 ; p = 0.007 ). An overall 4 df p-value for age can be read from the Type III Test table. It (is/is not) significant at p =0.00008). An overall, 3 df p-value for income (is/is not) significant at (p = 0.138)
Conclusion: After adjusting for age, sex, and income, age at first alcohol use is significantly negatively (negatively/positively) associated with lifetime marijuana use (AOR = 0.76; 95% CI = 0.72 , 0.80 ; p < 0.001 ). Individuals who first used alcohol at a given age have 24 % (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 = 0.031). A likelihood ratio test shows that the adjusted model with the interaction is superior (superior/not superior) to the one without the interaction (p =0.031)
modelsummary(
list(
Unadjasted = agefirst.log,
Adjusted = adjusted.log,
Interaction = inter.log
),
stars = TRUE
)| Unadjasted | 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 | |||
## 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
## Analysis of Deviance Table (Type III tests)
##
## Response: mj_lifetime
## LR Chisq Df Pr(>Chisq)
## alc_agefirst 108.028 1 < 2.2e-16 ***
## demog_age_cat6 23.248 4 0.000113 ***
## demog_sex 4.797 1 0.028506 *
## demog_income 5.296 3 0.151361
## alc_agefirst:demog_sex 4.656 1 0.030953 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## # A tibble: 11 × 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 7.37 0.829 8.89 5.99e-19 5.82 9.07
## 2 alc_agefirst -0.338 0.0423 -7.99 1.38e-15 -0.425 -0.259
## 3 demog_age_cat626-34 -0.295 0.331 -0.890 3.73e- 1 -0.954 0.350
## 4 demog_age_cat635-49 -0.816 0.299 -2.73 6.30e- 3 -1.42 -0.242
## 5 demog_age_cat650-64 -0.687 0.301 -2.28 2.24e- 2 -1.29 -0.108
## 6 demog_age_cat665+ -1.26 0.306 -4.11 3.91e- 5 -1.87 -0.671
## 7 demog_sexMale -2.14 0.985 -2.17 2.99e- 2 -4.09 -0.224
## 8 demog_income$20,000… -0.530 0.268 -1.98 4.80e- 2 -1.06 -0.00916
## 9 demog_income$50,000… -0.0931 0.307 -0.303 7.62e- 1 -0.697 0.510
## 10 demog_income$75,000… -0.363 0.255 -1.42 1.54e- 1 -0.869 0.131
## 11 alc_agefirst:demog_… 0.119 0.0555 2.14 3.22e- 2 0.0109 0.229
Answer Q1: Use the likelihood ratio test to determine which model is best? A1: The interatction model is best, comparing with adjusted model (p = 0.03).
Q2: Discuss the association between age of first alcohol and lifetime marijuana use, when comparing males to females. A2: When other predictors have been considered as default (except age of first alcohol and sex). Odds_female =e^ (b0 + b_age of first alcohol * X_age of first alcohol) Odds_male =e^ (b0 + b_age of first alcohol * X_age of first alcohol + b_sex * 1[male] + b_(age of first alcohol * sex) * X_age of first alcohol1[male]) Odds ratio (male/female) = e^ (b_(sex + b_age of first alcohol sex) * Xage of first alcohol) According to the interaction model, odds ratio (male/female) = e^ (-2.138 + 0.119* X_age of first alcohol). When age of first alcohol > 17.97, odds ratio (male/female) > 1, male report higher odds on lifetime marijuana use. When age of first alcohol < 17.97, odds ratio (male/female) < 1, male report lower odds on lifetime marijuana use.
nsduh.ctr <- nsduh |>
standardize(two_sd = TRUE) #centeral all variables
inter.log.ctr <- glm(
mj_lifetime ~ alc_agefirst + demog_age_cat6 + demog_sex + demog_income + alc_agefirst:demog_sex,
data = nsduh.ctr,
family = binomial
)
inter.log.ctr %>%
model_parameters() %>%
plot()Answer Q: What is the advantage of this plot compared to the model summary tables shown above? A: The plot is based on the centered data, so comparing different predictor’s effect is possible. Comparing with the summary table, the plot directly shows negative and positive effect, effect size and CI.
#probability difference
plot_comparisons(
inter.log,
variables = list(
demog_sex = c("Male", "Female")
),
comparison = "difference",
condition = "alc_agefirst")#log odds ratio
plot_comparisons(
inter.log,
variables = list(
demog_sex = c("Male", "Female")
),
comparison = "lnor",
condition = "alc_agefirst")#risk ratio
plot_comparisons(
inter.log,
variables = list(
demog_sex = c("Male", "Female")
),
comparison = "ratio",
condition = "alc_agefirst")Answer Q1: What is special about that age, according to the two graphs? A1: When alcohol first used age is under 18, female is more likely to reported higher lifetime marijuana use probability than male if they have same alcohol first used age. When alcohol first used age is aove 18, male is more likely to reported higher lifetime marijuana use probability than female if they have same alcohol first used age. Q2: Is the difference between the predicted outcomes of males and females significant at any age bracket? If so, what is the age bracket? A2: According to the probability difference plot, female at male do not report significant probability difference at most of time. However, when alcohol first used age is between 8-13, female report significant higher marijuana use probability than male (95%CI are always above 0).