library(ggplot2)
library(dplyr)
coefs<-data.frame(coefs=c(coef(fit1)[-1], coef(fit3)[-1]),
mod=c(rep("Non Survey Model", 11),rep("Survey Model", 11)),
effect=rep(names(coef(fit1)[-1]), 2))
coefs%>%
ggplot()+
geom_point(aes( x=effect,
y=coefs,
group=effect,
color=effect,
shape=mod),
position=position_jitterdodge(jitter.width = 1),
size=2)+
ylab("Regression Coefficient")+
xlab("Beta")+
geom_abline(intercept = 0, slope=0)+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
ggtitle(label = "Comparison of Survey and Non-Survey Regression effects")
prop.table(table(dawn2011$NUMSUBS))
##
## 1 2 3 4 5
## 0.64194572131 0.23812953723 0.07515813460 0.02482134828 0.00900134016
## 6 7 8 9 10
## 0.00366252395 0.00196877033 0.00116554696 0.00088616491 0.00065480166
## 11 12 13 14 15
## 0.00051074530 0.00047145720 0.00034486221 0.00027938204 0.00024882463
## 16 17 18 19 20
## 0.00041907306 0.00006111482 0.00004801879 0.00006548017 0.00006548017
## 21 22
## 0.00006548017 0.00002619207
prop.table(svytable(~NUMSUBS,
design = des))
## NUMSUBS
## 1 2 3 4 5
## 0.663261994472 0.212895252977 0.072157956350 0.027315062163 0.010626180557
## 6 7 8 9 10
## 0.004878337188 0.002273223187 0.001516999879 0.001285819703 0.000600102817
## 11 12 13 14 15
## 0.000557468715 0.000607745688 0.000319773604 0.000139870676 0.000560444990
## 16 17 18 19 20
## 0.000580488545 0.000069988831 0.000172696735 0.000015285094 0.000116820791
## 21 22
## 0.000042477023 0.000006010015
mean(dawn2011$NUMSUBS)
## [1] 1.584092
svymean(~NUMSUBS,
design = des)
## mean SE
## NUMSUBS 1.588 0.0538
cat<-svyby(formula = ~morethanonesub,
by = ~age,
design = des,
FUN = svymean,
na.rm=T)
svychisq(~morethanonesub+age,
design = des)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~morethanonesub + age, design = des)
## F = 85.242, ndf = 3.2842, ddf = 597.7269, p-value < 0.00000000000000022
cat%>%
ggplot()+
geom_point(aes(x=age,y=morethanonesub))+
geom_errorbar(aes(x=age, ymin = morethanonesub-1.96*se,
ymax= morethanonesub+1.96*se),
width=.25)+
labs(title = "Percent % of cases with ore than one substance",
caption = "Source: DAWN 2011",
x = "Age",
y = "% More than one Substance")+
theme_minimal()
dog<-svyby(formula = ~morethanonesub,
by = ~SEX,
design = des,
FUN = svymean,
na.rm=T)
svychisq(~morethanonesub+SEX,
design = des)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~morethanonesub + SEX, design = des)
## F = 135.42, ndf = 1, ddf = 182, p-value < 0.00000000000000022
dog%>%
ggplot()+
geom_point(aes(x=SEX,y=morethanonesub))+
geom_errorbar(aes(x=SEX, ymin = morethanonesub-1.96*se,
ymax= morethanonesub+1.96*se),
width=.25)+
labs(title = "Percent % of cases with more than one substance by sex",
caption = "Source: DAWN Data 2011",
x = "Sex",
y = "% more than one substance")+
theme_minimal()
catdog<-svyby(formula = ~morethanonesub,
by = ~age+SEX,
design = des,
FUN = svymean,
na.rm=T)
catdog%>%
ggplot()+
geom_errorbar(aes(x=age,y = morethanonesub,
ymin = morethanonesub-1.96*se,
ymax= morethanonesub+1.96*se,
color=SEX,
group=SEX),
width=.25,
position="dodge")+
labs(title = "Percent % of cases with more than one substance by Sex and Age",
caption = "Source: DAWN Data 2011",
x = "age",
y = "% more than one substance")+
theme_minimal()
fit.logit<-svyglm(morethanonesub ~ age + SEX,
design = des,
family = binomial)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
summary(fit.logit)
##
## Call:
## svyglm(formula = morethanonesub ~ age + SEX, design = des, family = binomial)
##
## Survey design:
## svydesign(ids = ~PSU, strata = ~STRATA, weights = ~CASEWGT, nest = TRUE,
## data = dawn2011)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.00855 0.08218 -24.441 < 0.0000000000000002
## age(02) 6 TO 11:(2) 0.42767 0.13411 3.189 0.0017
## age(03) 12 TO 17:(3) 1.27097 0.11974 10.615 < 0.0000000000000002
## age(04) 18 TO 20:(4) 1.35699 0.11944 11.361 < 0.0000000000000002
## age(05) 21 TO 24:(5) 1.97817 0.09840 20.104 < 0.0000000000000002
## age(06) 25 TO 29:(6) 1.92360 0.11194 17.184 < 0.0000000000000002
## age(07) 30 TO 34:(7) 1.95377 0.12997 15.032 < 0.0000000000000002
## age(08) 35 TO 44:(8) 1.76244 0.09800 17.984 < 0.0000000000000002
## age(09) 45 TO 54:(9) 1.72504 0.08674 19.888 < 0.0000000000000002
## age(10) 55 TO 64:(10) 1.34163 0.11630 11.536 < 0.0000000000000002
## age(11) AGE 65 OR OLDER:(11) 0.83656 0.14227 5.880 0.000000021
## SEX(2) FEMALE:(2) -0.33897 0.02688 -12.612 < 0.0000000000000002
##
## (Intercept) ***
## age(02) 6 TO 11:(2) **
## age(03) 12 TO 17:(3) ***
## age(04) 18 TO 20:(4) ***
## age(05) 21 TO 24:(5) ***
## age(06) 25 TO 29:(6) ***
## age(07) 30 TO 34:(7) ***
## age(08) 35 TO 44:(8) ***
## age(09) 45 TO 54:(9) ***
## age(10) 55 TO 64:(10) ***
## age(11) AGE 65 OR OLDER:(11) ***
## SEX(2) FEMALE:(2) ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1.002533)
##
## Number of Fisher Scoring iterations: 5
library(gtsummary)
fit.logit%>%
tbl_regression(exponentiate=TRUE )
| Characteristic | OR1 | 95% CI1 | p-value |
|---|---|---|---|
| age | |||
| (01) AGE 5 OR YOUNGER:(1) | — | — | |
| (02) 6 TO 11:(2) | 1.53 | 1.18, 2.00 | 0.002 |
| (03) 12 TO 17:(3) | 3.56 | 2.81, 4.51 | <0.001 |
| (04) 18 TO 20:(4) | 3.88 | 3.07, 4.92 | <0.001 |
| (05) 21 TO 24:(5) | 7.23 | 5.95, 8.78 | <0.001 |
| (06) 25 TO 29:(6) | 6.85 | 5.49, 8.54 | <0.001 |
| (07) 30 TO 34:(7) | 7.06 | 5.46, 9.12 | <0.001 |
| (08) 35 TO 44:(8) | 5.83 | 4.80, 7.07 | <0.001 |
| (09) 45 TO 54:(9) | 5.61 | 4.73, 6.66 | <0.001 |
| (10) 55 TO 64:(10) | 3.83 | 3.04, 4.81 | <0.001 |
| (11) AGE 65 OR OLDER:(11) | 2.31 | 1.74, 3.06 | <0.001 |
| SEX | |||
| (1) MALE:(1) | — | — | |
| (2) FEMALE:(2) | 0.71 | 0.68, 0.75 | <0.001 |
|
1
OR = Odds Ratio, CI = Confidence Interval
|
|||
library(sjPlot)
plot_model(fit.logit,
axis.lim = c(.1, 15),
title = "Odds ratios for More than one substance")
library(emmeans)
rg<-ref_grid(fit.logit)
marg_logit<-emmeans(object = rg,
specs = c( "age", "SEX"),
type="more than one substance" )
knitr::kable(marg_logit, digits = 4)
| age | SEX | emmean | SE | df | asymp.LCL | asymp.UCL |
|---|---|---|---|---|---|---|
| (01) AGE 5 OR YOUNGER:(1) | (1) MALE:(1) | -2.0085 | 0.0822 | Inf | -2.1696 | -1.8475 |
| (02) 6 TO 11:(2) | (1) MALE:(1) | -1.5809 | 0.1268 | Inf | -1.8293 | -1.3324 |
| (03) 12 TO 17:(3) | (1) MALE:(1) | -0.7376 | 0.1045 | Inf | -0.9423 | -0.5328 |
| (04) 18 TO 20:(4) | (1) MALE:(1) | -0.6516 | 0.0933 | Inf | -0.8345 | -0.4687 |
| (05) 21 TO 24:(5) | (1) MALE:(1) | -0.0304 | 0.0810 | Inf | -0.1892 | 0.1284 |
| (06) 25 TO 29:(6) | (1) MALE:(1) | -0.0850 | 0.0833 | Inf | -0.2482 | 0.0783 |
| (07) 30 TO 34:(7) | (1) MALE:(1) | -0.0548 | 0.1202 | Inf | -0.2903 | 0.1808 |
| (08) 35 TO 44:(8) | (1) MALE:(1) | -0.2461 | 0.0819 | Inf | -0.4066 | -0.0856 |
| (09) 45 TO 54:(9) | (1) MALE:(1) | -0.2835 | 0.0464 | Inf | -0.3744 | -0.1926 |
| (10) 55 TO 64:(10) | (1) MALE:(1) | -0.6669 | 0.0778 | Inf | -0.8193 | -0.5145 |
| (11) AGE 65 OR OLDER:(11) | (1) MALE:(1) | -1.1720 | 0.1199 | Inf | -1.4069 | -0.9371 |
| (01) AGE 5 OR YOUNGER:(1) | (2) FEMALE:(2) | -2.3475 | 0.0848 | Inf | -2.5137 | -2.1814 |
| (02) 6 TO 11:(2) | (2) FEMALE:(2) | -1.9199 | 0.1203 | Inf | -2.1557 | -1.6840 |
| (03) 12 TO 17:(3) | (2) FEMALE:(2) | -1.0766 | 0.0873 | Inf | -1.2477 | -0.9055 |
| (04) 18 TO 20:(4) | (2) FEMALE:(2) | -0.9905 | 0.0857 | Inf | -1.1586 | -0.8225 |
| (05) 21 TO 24:(5) | (2) FEMALE:(2) | -0.3693 | 0.0645 | Inf | -0.4957 | -0.2430 |
| (06) 25 TO 29:(6) | (2) FEMALE:(2) | -0.4239 | 0.0649 | Inf | -0.5511 | -0.2968 |
| (07) 30 TO 34:(7) | (2) FEMALE:(2) | -0.3938 | 0.1036 | Inf | -0.5968 | -0.1907 |
| (08) 35 TO 44:(8) | (2) FEMALE:(2) | -0.5851 | 0.0683 | Inf | -0.7190 | -0.4511 |
| (09) 45 TO 54:(9) | (2) FEMALE:(2) | -0.6225 | 0.0353 | Inf | -0.6916 | -0.5533 |
| (10) 55 TO 64:(10) | (2) FEMALE:(2) | -1.0059 | 0.0665 | Inf | -1.1363 | -0.8755 |
| (11) AGE 65 OR OLDER:(11) | (2) FEMALE:(2) | -1.5110 | 0.1088 | Inf | -1.7243 | -1.2977 |
comps<-as.data.frame(marg_logit)
comps[comps$age=="(02) 6 TO 11:(2)" | comps$age== "(03) 12 TO 17:(3)" | comps$age=="(01) AGE 5 OR YOUNGER:(1)", ]
## age SEX emmean SE df asymp.LCL
## 1 (01) AGE 5 OR YOUNGER:(1) (1) MALE:(1) -2.0085490 0.08217979 Inf -2.169618
## 2 (02) 6 TO 11:(2) (1) MALE:(1) -1.5808767 0.12675949 Inf -1.829321
## 3 (03) 12 TO 17:(3) (1) MALE:(1) -0.7375776 0.10445828 Inf -0.942312
## 12 (01) AGE 5 OR YOUNGER:(1) (2) FEMALE:(2) -2.3475236 0.08476492 Inf -2.513660
## 13 (02) 6 TO 11:(2) (2) FEMALE:(2) -1.9198513 0.12033272 Inf -2.155699
## 14 (03) 12 TO 17:(3) (2) FEMALE:(2) -1.0765522 0.08729726 Inf -1.247652
## asymp.UCL
## 1 -1.8474795
## 2 -1.3324327
## 3 -0.5328431
## 12 -2.1813874
## 13 -1.6840035
## 14 -0.9054527
comps[comps$age=="(05) 21 TO 24:(5)" | comps$age == "(06) 25 to 29:(6)" & comps$SEX == "(1) MALE:(1)" , ]
## age SEX emmean SE df asymp.LCL
## 5 (05) 21 TO 24:(5) (1) MALE:(1) -0.03037434 0.08101976 Inf -0.1891701
## 16 (05) 21 TO 24:(5) (2) FEMALE:(2) -0.36934892 0.06448762 Inf -0.4957423
## asymp.UCL
## 5 0.1284215
## 16 -0.2429555
comps[comps$age=="(09) 45 TO 54:(9)" & comps$SEX == "(2) FEMALE:(2)" | comps$SEX == "(1) MALE:(1)", ]
## age SEX emmean SE df
## 1 (01) AGE 5 OR YOUNGER:(1) (1) MALE:(1) -2.00854897 0.08217979 Inf
## 2 (02) 6 TO 11:(2) (1) MALE:(1) -1.58087670 0.12675949 Inf
## 3 (03) 12 TO 17:(3) (1) MALE:(1) -0.73757758 0.10445828 Inf
## 4 (04) 18 TO 20:(4) (1) MALE:(1) -0.65155765 0.09331716 Inf
## 5 (05) 21 TO 24:(5) (1) MALE:(1) -0.03037434 0.08101976 Inf
## 6 (06) 25 TO 29:(6) (1) MALE:(1) -0.08495205 0.08328404 Inf
## 7 (07) 30 TO 34:(7) (1) MALE:(1) -0.05477837 0.12019006 Inf
## 8 (08) 35 TO 44:(8) (1) MALE:(1) -0.24611145 0.08189529 Inf
## 9 (09) 45 TO 54:(9) (1) MALE:(1) -0.28350707 0.04638464 Inf
## 10 (10) 55 TO 64:(10) (1) MALE:(1) -0.66691925 0.07775252 Inf
## 11 (11) AGE 65 OR OLDER:(11) (1) MALE:(1) -1.17198710 0.11985176 Inf
## 20 (09) 45 TO 54:(9) (2) FEMALE:(2) -0.62248166 0.03528506 Inf
## asymp.LCL asymp.UCL
## 1 -2.1696184 -1.84747953
## 2 -1.8293207 -1.33243266
## 3 -0.9423120 -0.53284311
## 4 -0.8344559 -0.46865938
## 5 -0.1891701 0.12842147
## 6 -0.2481858 0.07828167
## 7 -0.2903466 0.18078981
## 8 -0.4066233 -0.08559963
## 9 -0.3744193 -0.19259485
## 10 -0.8193114 -0.51452711
## 11 -1.4068922 -0.93708196
## 20 -0.6916391 -0.55332420
Once again, I am interested in looking at age and sex as my predictors for whether or not there is more than one substance involved in the case. Are men or women more likely to use more than one substance at a time? Does the likelihood of using more than one substance increase with age?