## Data
ddi <- read_ipums_ddi("/Volumes/Jyoti/Stat 2 /PROJECT/nhis_00012.xml")
data <- read_ipums_micro(ddi)
## Use of data from IPUMS NHIS is subject to conditions including that users
## should cite the data appropriately. Use command `ipums_conditions()` for more
## details.
data<- haven::zap_labels(data)
names(data) <- tolower(gsub(pattern = "_",replacement = "",x = names(data)))
data$age_cat<-Recode(data$age, recodes= "18:24='18-24'; 25:29='25-29'; 30:39='30-39'; 40:49='40-49'; 50:85='50 and above'; else=NA", as.factor=T)
#Age cut into intervals
data$ageinterval<-cut(data$age, breaks=c(18,29,39,59,79,99))
#depression level
data$depfeelevl<-as.factor(data$depfeelevl)
data$depfeelevl<- car::Recode(data$depfeelevl,
recodes="1='A Lot'; 2='A Little';
3='Between a Little and a Lot'; 7:9=NA; else=NA",
as.factor=T)
data$depfeelevl<- as.ordered(data$depfeelevl)
# medication for depression
data$deprx <- as.factor(data$deprx)
data$deprx<- car::Recode(data$deprx,
recodes="1=0; 2=1;else=NA",
as.factor=T)
#currently Pregnant
data$pregnantnow<-as.factor(data$pregnantnow)
data$curpreg<-car::Recode(data$pregnantnow,
recodes="0='Yes';else=NA",
as.factor=T)
#education level
data$educ<-Recode(data$educ,
recodes="100:116 ='Less than HS'; 200:202='HS Diploma/GED'; 300:303='Some college';400= 'Undergraduate Degree'; 500:503:= 'Graduate Degree';else=NA", as.factor = T)
data$educ<-as.factor(data$educ)
#employment status
data$empstat<- car::Recode(data$empstat,
recodes="100='Employed'; 200='Unemployed';else=NA",
as.factor=T)
# income grouping
data$famtotinc_cat<-Recode(data$famtotinc, recodes = "0:49999='Less than 50k'; 50000:99999='50-100k';100000:149999='100-150k';150000:199999='150-200k';200000:250000='200-250k';else=NA", as.factor = T)
data$famtotinc_cat<-as.ordered(data$famtotinc)
##race
data$race<- car::Recode(data$racea,
recodes="100 ='White'; 200 ='African American';
400:590= 'Asian/Others'; else=NA",
as.factor=T)
#race/ethnicity
data$black<- car::Recode(data$hisprace,
recodes="03=1; 99=NA; else=0")
data$white<- car::Recode(data$hisprace,
recodes="02=1; 99=NA; else=0")
data$other<- car::Recode(data$hisprace,
recodes="4:7=1; 99=NA; else=0")
data$hispanic<- car::Recode(data$hisprace,
recodes="01=1; 99=NA; else=0")
data$hisprace<- as.factor(data$hisprace)
data$race_eth<-car::Recode(data$hisprace,
recodes="01='Hispanic'; 02='NH_White'; 03='NH_Black';04:07='NH_Other'; else=NA",
as.factor = T)
data$race_eth<-relevel(data$race_eth,
ref = "NH_White")
## marital status
data$mars<- car::Recode(data$marstat,
recodes ="10:13='Married'; 20='Widowed'; 30:40='Divorced/Separated';
; 50='Never Married'; else=NA",
as.factor=T)
## Filter data
data<-data%>%
filter(is.na(curpreg)==F)
data<-data%>%
filter(is.na(educ)==F)
data<-data%>%
filter(is.na(deprx)==F)
data<-data%>%
filter(is.na(depfeelevl)==F)
data<-data%>%
filter(is.na(empstat)==F)
data<-data%>%
filter(is.na(race)==F)
data<-data%>%
filter(is.na(marstat)==F)
data<-data%>%
filter(is.na(race_eth)==F)
data<-data%>%
filter(is.na(age_cat)==F)
options(survey.lonely.psu = "adjust")
des<-svydesign(ids=~1, strata=~strata, weights=~sampweight, data = data, , nest=T )
des
## Stratified Independent Sampling design (with replacement)
## svydesign(ids = ~1, strata = ~strata, weights = ~sampweight,
## data = data, , nest = T)
## Table 1: Demographic properties of pregnant women with depression (who are either taking or not taking prescription medication for depression)
label(data$depfeelevl) <- "Depression Level"
label(data$deprx) <- "Medication for Depression"
label(data$pregnantnow) <-"Currently Pregnant"
label(data$educ) <- "Education Level"
label(data$empstat)<- "Employment Status"
label(data$race_eth)<- "Race/Ethnicity"
label(data$mars)<- "Marital Status"
label(data$age_cat)<- "Age"
I ran my outcome variable with all my predictor variables to see if they are significant. I will then nest them.
fit1 <- svyglm(deprx~ educ+age_cat+race_eth+empstat+mars, design=des, family=binomial(link="logit"))
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
# Take a look at the output
gtsummary::tbl_regression(fit1, exp = TRUE)
| Characteristic | OR1 | 95% CI1 | p-value |
|---|---|---|---|
| educ | |||
| Graduate Degree | — | — | |
| HS Diploma/GED | 1.09 | 0.95, 1.25 | 0.2 |
| Less than HS | 1.05 | 0.87, 1.27 | 0.6 |
| Some college | 1.20 | 1.05, 1.37 | 0.008 |
| Undergraduate Degree | 0.97 | 0.85, 1.12 | 0.7 |
| age_cat | |||
| 18-24 | — | — | |
| 25-29 | 1.42 | 0.96, 2.12 | 0.082 |
| 30-39 | 1.37 | 0.98, 1.91 | 0.065 |
| 40-49 | 1.93 | 1.38, 2.70 | <0.001 |
| 50 and above | 2.46 | 1.81, 3.35 | <0.001 |
| race_eth | |||
| NH_White | — | — | |
| Hispanic | 0.67 | 0.54, 0.83 | <0.001 |
| NH_Black | 0.64 | 0.55, 0.76 | <0.001 |
| NH_Other | 0.37 | 0.27, 0.49 | <0.001 |
| empstat | |||
| Employed | — | — | |
| Unemployed | 1.99 | 1.80, 2.19 | <0.001 |
| mars | |||
| Divorced/Separated | — | — | |
| Married | 0.75 | 0.68, 0.83 | <0.001 |
| Never Married | 0.76 | 0.66, 0.88 | <0.001 |
| Widowed | 0.80 | 0.69, 0.92 | 0.001 |
|
1
OR = Odds Ratio, CI = Confidence Interval
|
|||
## Survey design #First we tell R our survey design
options(survey.lonely.psu = "adjust")
library(dplyr)
sub<-data%>%
select(depfeelevl, age_cat, curpreg, educ, deprx, empstat, race_eth, mars,depfeelevl, sampweight,strata) %>%
filter( complete.cases(.))
options(survey.lonely.psu = "adjust")
des<-svydesign(ids=~1,
strata=~strata,
weights=~sampweight,
data =sub)
table<-table1(~ educ + empstat + race_eth + mars + depfeelevl + age_cat | deprx, data=sub)
table
| 0 (N=14268) |
1 (N=4863) |
Overall (N=19131) |
|
|---|---|---|---|
| Education Level | |||
| Graduate Degree | 2128 (14.9%) | 643 (13.2%) | 2771 (14.5%) |
| HS Diploma/GED | 3502 (24.5%) | 1307 (26.9%) | 4809 (25.1%) |
| Less than HS | 1140 (8.0%) | 448 (9.2%) | 1588 (8.3%) |
| Some college | 4214 (29.5%) | 1570 (32.3%) | 5784 (30.2%) |
| Undergraduate Degree | 3284 (23.0%) | 895 (18.4%) | 4179 (21.8%) |
| Employment Status | |||
| Employed | 7670 (53.8%) | 1676 (34.5%) | 9346 (48.9%) |
| Unemployed | 6598 (46.2%) | 3187 (65.5%) | 9785 (51.1%) |
| Race/Ethnicity | |||
| NH_White | 11248 (78.8%) | 4197 (86.3%) | 15445 (80.7%) |
| Hispanic | 847 (5.9%) | 224 (4.6%) | 1071 (5.6%) |
| NH_Black | 1352 (9.5%) | 350 (7.2%) | 1702 (8.9%) |
| NH_Other | 821 (5.8%) | 92 (1.9%) | 913 (4.8%) |
| Marital Status | |||
| Divorced/Separated | 2834 (19.9%) | 1280 (26.3%) | 4114 (21.5%) |
| Married | 6144 (43.1%) | 1961 (40.3%) | 8105 (42.4%) |
| Never Married | 3295 (23.1%) | 772 (15.9%) | 4067 (21.3%) |
| Widowed | 1995 (14.0%) | 850 (17.5%) | 2845 (14.9%) |
| Depression Level | |||
| A Little | 1123 (7.9%) | 1176 (24.2%) | 2299 (12.0%) |
| A Lot | 8507 (59.6%) | 1666 (34.3%) | 10173 (53.2%) |
| Between a Little and a Lot | 4638 (32.5%) | 2021 (41.6%) | 6659 (34.8%) |
| Age | |||
| 18-24 | 620 (4.3%) | 78 (1.6%) | 698 (3.6%) |
| 25-29 | 729 (5.1%) | 105 (2.2%) | 834 (4.4%) |
| 30-39 | 1513 (10.6%) | 248 (5.1%) | 1761 (9.2%) |
| 40-49 | 1240 (8.7%) | 264 (5.4%) | 1504 (7.9%) |
| 50 and above | 10166 (71.3%) | 4168 (85.7%) | 14334 (74.9%) |
#Logit model
fit.logit<-svyglm(deprx~educ+race_eth+empstat+mars,
design= des,
family=binomial)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
summary(fit.logit)
##
## Call:
## svyglm(formula = deprx ~ educ + race_eth + empstat + mars, design = des,
## family = binomial)
##
## Survey design:
## svydesign(ids = ~1, strata = ~strata, weights = ~sampweight,
## data = sub)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.22252 0.07092 -17.237 < 2e-16 ***
## educHS Diploma/GED 0.05230 0.06889 0.759 0.44776
## educLess than HS 0.02342 0.09534 0.246 0.80595
## educSome college 0.13679 0.06733 2.031 0.04222 *
## educUndergraduate Degree -0.05155 0.07188 -0.717 0.47329
## race_ethHispanic -0.44134 0.10704 -4.123 3.75e-05 ***
## race_ethNH_Black -0.42271 0.08159 -5.181 2.23e-07 ***
## race_ethNH_Other -1.04345 0.14642 -7.127 1.07e-12 ***
## empstatUnemployed 0.80749 0.04605 17.534 < 2e-16 ***
## marsMarried -0.31549 0.05222 -6.042 1.55e-09 ***
## marsNever Married -0.64373 0.07065 -9.112 < 2e-16 ***
## marsWidowed -0.20725 0.07079 -2.928 0.00342 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 0.9959921)
##
## Number of Fisher Scoring iterations: 4
Here, we only see coefficients, the direction of relationship, and the significance. Now, we need to calculate odds ratios and confidence intervals.
library(gtsummary)
fit.logit%>%
tbl_regression(exponentiate=TRUE )
| Characteristic | OR1 | 95% CI1 | p-value |
|---|---|---|---|
| Education Level | |||
| Graduate Degree | — | — | |
| HS Diploma/GED | 1.05 | 0.92, 1.21 | 0.4 |
| Less than HS | 1.02 | 0.85, 1.23 | 0.8 |
| Some college | 1.15 | 1.00, 1.31 | 0.042 |
| Undergraduate Degree | 0.95 | 0.82, 1.09 | 0.5 |
| Race/Ethnicity | |||
| NH_White | — | — | |
| Hispanic | 0.64 | 0.52, 0.79 | <0.001 |
| NH_Black | 0.66 | 0.56, 0.77 | <0.001 |
| NH_Other | 0.35 | 0.26, 0.47 | <0.001 |
| Employment Status | |||
| Employed | — | — | |
| Unemployed | 2.24 | 2.05, 2.45 | <0.001 |
| Marital Status | |||
| Divorced/Separated | — | — | |
| Married | 0.73 | 0.66, 0.81 | <0.001 |
| Never Married | 0.53 | 0.46, 0.60 | <0.001 |
| Widowed | 0.81 | 0.71, 0.93 | 0.003 |
|
1
OR = Odds Ratio, CI = Confidence Interval
|
|||
library(sjPlot)
## #refugeeswelcome
plot_model(fit.logit,
axis.lim = c(.1, 10),
title = " Figure 1. Odds Ratios for Depression")
The figure above shows that women with some college education have higher odds of taking depression medication. In case of race and ethnicity, Whites have higher odds of taking depression medication compared to other groups. In terms of employment status, unemployed women are more likely to take depression medication. Finally, divorced/separated have higher odds of taking depression medication.
knitr::kable(data.frame(OR = exp(coef(fit.logit)), ci = exp(confint(fit.logit))))
| OR | ci.2.5.. | ci.97.5.. | |
|---|---|---|---|
| (Intercept) | 0.2944862 | 0.2562664 | 0.3384061 |
| educHS Diploma/GED | 1.0536946 | 0.9205934 | 1.2060399 |
| educLess than HS | 1.0236982 | 0.8491989 | 1.2340550 |
| educSome college | 1.1465826 | 1.0048191 | 1.3083466 |
| educUndergraduate Degree | 0.9497590 | 0.8249500 | 1.0934506 |
| race_ethHispanic | 0.6431729 | 0.5214499 | 0.7933098 |
| race_ethNH_Black | 0.6552702 | 0.5584242 | 0.7689120 |
| race_ethNH_Other | 0.3522372 | 0.2643607 | 0.4693247 |
| empstatUnemployed | 2.2422786 | 2.0487447 | 2.4540946 |
| marsMarried | 0.7294344 | 0.6584710 | 0.8080455 |
| marsNever Married | 0.5253274 | 0.4573956 | 0.6033484 |
| marsWidowed | 0.8128203 | 0.7075174 | 0.9337959 |
#get a series of predicted probabilities for different "types" of people for each model
#ref_grid will generate all possible combinations of predictors from a model
library(emmeans)
rg<-ref_grid(fit.logit)
marg_logit<-emmeans(object = rg,
specs = c( "educ", "race_eth", "empstat", "mars"),
type="response" )
knitr::kable(marg_logit, digits = 4)
| educ | race_eth | empstat | mars | prob | SE | df | asymp.LCL | asymp.UCL |
|---|---|---|---|---|---|---|---|---|
| Graduate Degree | NH_White | Employed | Divorced/Separated | 0.2275 | 0.0125 | Inf | 0.2040 | 0.2528 |
| HS Diploma/GED | NH_White | Employed | Divorced/Separated | 0.2368 | 0.0114 | Inf | 0.2152 | 0.2599 |
| Less than HS | NH_White | Employed | Divorced/Separated | 0.2316 | 0.0163 | Inf | 0.2013 | 0.2650 |
| Some college | NH_White | Employed | Divorced/Separated | 0.2524 | 0.0111 | Inf | 0.2312 | 0.2749 |
| Undergraduate Degree | NH_White | Employed | Divorced/Separated | 0.2186 | 0.0111 | Inf | 0.1976 | 0.2410 |
| Graduate Degree | Hispanic | Employed | Divorced/Separated | 0.1592 | 0.0166 | Inf | 0.1293 | 0.1945 |
| HS Diploma/GED | Hispanic | Employed | Divorced/Separated | 0.1664 | 0.0163 | Inf | 0.1368 | 0.2009 |
| Less than HS | Hispanic | Employed | Divorced/Separated | 0.1624 | 0.0163 | Inf | 0.1329 | 0.1969 |
| Some college | Hispanic | Employed | Divorced/Separated | 0.1784 | 0.0173 | Inf | 0.1469 | 0.2149 |
| Undergraduate Degree | Hispanic | Employed | Divorced/Separated | 0.1525 | 0.0154 | Inf | 0.1246 | 0.1853 |
| Graduate Degree | NH_Black | Employed | Divorced/Separated | 0.1618 | 0.0138 | Inf | 0.1365 | 0.1907 |
| HS Diploma/GED | NH_Black | Employed | Divorced/Separated | 0.1690 | 0.0132 | Inf | 0.1447 | 0.1964 |
| Less than HS | NH_Black | Employed | Divorced/Separated | 0.1650 | 0.0162 | Inf | 0.1356 | 0.1993 |
| Some college | NH_Black | Employed | Divorced/Separated | 0.1812 | 0.0135 | Inf | 0.1562 | 0.2092 |
| Undergraduate Degree | NH_Black | Employed | Divorced/Separated | 0.1549 | 0.0128 | Inf | 0.1314 | 0.1817 |
| Graduate Degree | NH_Other | Employed | Divorced/Separated | 0.0940 | 0.0132 | Inf | 0.0711 | 0.1233 |
| HS Diploma/GED | NH_Other | Employed | Divorced/Separated | 0.0985 | 0.0138 | Inf | 0.0746 | 0.1290 |
| Less than HS | NH_Other | Employed | Divorced/Separated | 0.0960 | 0.0144 | Inf | 0.0712 | 0.1282 |
| Some college | NH_Other | Employed | Divorced/Separated | 0.1063 | 0.0149 | Inf | 0.0805 | 0.1392 |
| Undergraduate Degree | NH_Other | Employed | Divorced/Separated | 0.0897 | 0.0127 | Inf | 0.0678 | 0.1178 |
| Graduate Degree | NH_White | Unemployed | Divorced/Separated | 0.3977 | 0.0173 | Inf | 0.3644 | 0.4320 |
| HS Diploma/GED | NH_White | Unemployed | Divorced/Separated | 0.4103 | 0.0141 | Inf | 0.3830 | 0.4382 |
| Less than HS | NH_White | Unemployed | Divorced/Separated | 0.4033 | 0.0205 | Inf | 0.3639 | 0.4441 |
| Some college | NH_White | Unemployed | Divorced/Separated | 0.4309 | 0.0138 | Inf | 0.4041 | 0.4581 |
| Undergraduate Degree | NH_White | Unemployed | Divorced/Separated | 0.3854 | 0.0155 | Inf | 0.3555 | 0.4162 |
| Graduate Degree | Hispanic | Unemployed | Divorced/Separated | 0.2981 | 0.0263 | Inf | 0.2493 | 0.3520 |
| HS Diploma/GED | Hispanic | Unemployed | Divorced/Separated | 0.3092 | 0.0248 | Inf | 0.2627 | 0.3598 |
| Less than HS | Hispanic | Unemployed | Divorced/Separated | 0.3030 | 0.0245 | Inf | 0.2572 | 0.3531 |
| Some college | Hispanic | Unemployed | Divorced/Separated | 0.3275 | 0.0259 | Inf | 0.2788 | 0.3802 |
| Undergraduate Degree | Hispanic | Unemployed | Divorced/Separated | 0.2874 | 0.0247 | Inf | 0.2415 | 0.3382 |
| Graduate Degree | NH_Black | Unemployed | Divorced/Separated | 0.3020 | 0.0217 | Inf | 0.2613 | 0.3461 |
| HS Diploma/GED | NH_Black | Unemployed | Divorced/Separated | 0.3131 | 0.0195 | Inf | 0.2762 | 0.3527 |
| Less than HS | NH_Black | Unemployed | Divorced/Separated | 0.3070 | 0.0241 | Inf | 0.2619 | 0.3561 |
| Some college | NH_Black | Unemployed | Divorced/Separated | 0.3316 | 0.0198 | Inf | 0.2939 | 0.3716 |
| Undergraduate Degree | NH_Black | Unemployed | Divorced/Separated | 0.2913 | 0.0203 | Inf | 0.2531 | 0.3327 |
| Graduate Degree | NH_Other | Unemployed | Divorced/Separated | 0.1887 | 0.0242 | Inf | 0.1458 | 0.2407 |
| HS Diploma/GED | NH_Other | Unemployed | Divorced/Separated | 0.1968 | 0.0246 | Inf | 0.1531 | 0.2494 |
| Less than HS | NH_Other | Unemployed | Divorced/Separated | 0.1923 | 0.0256 | Inf | 0.1470 | 0.2475 |
| Some college | NH_Other | Unemployed | Divorced/Separated | 0.2105 | 0.0262 | Inf | 0.1638 | 0.2664 |
| Undergraduate Degree | NH_Other | Unemployed | Divorced/Separated | 0.1809 | 0.0233 | Inf | 0.1396 | 0.2312 |
| Graduate Degree | NH_White | Employed | Married | 0.1768 | 0.0090 | Inf | 0.1599 | 0.1952 |
| HS Diploma/GED | NH_White | Employed | Married | 0.1846 | 0.0085 | Inf | 0.1685 | 0.2018 |
| Less than HS | NH_White | Employed | Married | 0.1803 | 0.0132 | Inf | 0.1558 | 0.2076 |
| Some college | NH_White | Employed | Married | 0.1976 | 0.0084 | Inf | 0.1818 | 0.2145 |
| Undergraduate Degree | NH_White | Employed | Married | 0.1694 | 0.0079 | Inf | 0.1545 | 0.1856 |
| Graduate Degree | Hispanic | Employed | Married | 0.1214 | 0.0127 | Inf | 0.0985 | 0.1487 |
| HS Diploma/GED | Hispanic | Employed | Married | 0.1271 | 0.0128 | Inf | 0.1041 | 0.1542 |
| Less than HS | Hispanic | Employed | Married | 0.1239 | 0.0129 | Inf | 0.1007 | 0.1515 |
| Some college | Hispanic | Employed | Married | 0.1367 | 0.0136 | Inf | 0.1121 | 0.1658 |
| Undergraduate Degree | Hispanic | Employed | Married | 0.1160 | 0.0119 | Inf | 0.0947 | 0.1413 |
| Graduate Degree | NH_Black | Employed | Married | 0.1234 | 0.0108 | Inf | 0.1038 | 0.1461 |
| HS Diploma/GED | NH_Black | Employed | Married | 0.1292 | 0.0105 | Inf | 0.1099 | 0.1512 |
| Less than HS | NH_Black | Employed | Married | 0.1259 | 0.0131 | Inf | 0.1024 | 0.1540 |
| Some college | NH_Black | Employed | Married | 0.1390 | 0.0109 | Inf | 0.1189 | 0.1618 |
| Undergraduate Degree | NH_Black | Employed | Married | 0.1179 | 0.0100 | Inf | 0.0997 | 0.1390 |
| Graduate Degree | NH_Other | Employed | Married | 0.0703 | 0.0098 | Inf | 0.0534 | 0.0922 |
| HS Diploma/GED | NH_Other | Employed | Married | 0.0738 | 0.0104 | Inf | 0.0559 | 0.0969 |
| Less than HS | NH_Other | Employed | Married | 0.0719 | 0.0109 | Inf | 0.0532 | 0.0965 |
| Some college | NH_Other | Employed | Married | 0.0798 | 0.0112 | Inf | 0.0604 | 0.1048 |
| Undergraduate Degree | NH_Other | Employed | Married | 0.0670 | 0.0094 | Inf | 0.0508 | 0.0880 |
| Graduate Degree | NH_White | Unemployed | Married | 0.3251 | 0.0138 | Inf | 0.2987 | 0.3526 |
| HS Diploma/GED | NH_White | Unemployed | Married | 0.3367 | 0.0113 | Inf | 0.3150 | 0.3591 |
| Less than HS | NH_White | Unemployed | Married | 0.3302 | 0.0183 | Inf | 0.2954 | 0.3671 |
| Some college | NH_White | Unemployed | Married | 0.3558 | 0.0112 | Inf | 0.3341 | 0.3780 |
| Undergraduate Degree | NH_White | Unemployed | Married | 0.3139 | 0.0122 | Inf | 0.2905 | 0.3382 |
| Graduate Degree | Hispanic | Unemployed | Married | 0.2365 | 0.0218 | Inf | 0.1964 | 0.2819 |
| HS Diploma/GED | Hispanic | Unemployed | Married | 0.2461 | 0.0210 | Inf | 0.2074 | 0.2894 |
| Less than HS | Hispanic | Unemployed | Married | 0.2408 | 0.0210 | Inf | 0.2021 | 0.2843 |
| Some college | Hispanic | Unemployed | Married | 0.2621 | 0.0222 | Inf | 0.2210 | 0.3079 |
| Undergraduate Degree | Hispanic | Unemployed | Married | 0.2273 | 0.0205 | Inf | 0.1897 | 0.2699 |
| Graduate Degree | NH_Black | Unemployed | Married | 0.2399 | 0.0183 | Inf | 0.2059 | 0.2775 |
| HS Diploma/GED | NH_Black | Unemployed | Married | 0.2496 | 0.0169 | Inf | 0.2180 | 0.2841 |
| Less than HS | NH_Black | Unemployed | Married | 0.2442 | 0.0212 | Inf | 0.2051 | 0.2880 |
| Some college | NH_Black | Unemployed | Married | 0.2657 | 0.0174 | Inf | 0.2330 | 0.3012 |
| Undergraduate Degree | NH_Black | Unemployed | Married | 0.2306 | 0.0171 | Inf | 0.1988 | 0.2659 |
| Graduate Degree | NH_Other | Unemployed | Married | 0.1450 | 0.0189 | Inf | 0.1118 | 0.1862 |
| HS Diploma/GED | NH_Other | Unemployed | Married | 0.1517 | 0.0195 | Inf | 0.1173 | 0.1939 |
| Less than HS | NH_Other | Unemployed | Married | 0.1480 | 0.0205 | Inf | 0.1122 | 0.1927 |
| Some college | NH_Other | Unemployed | Married | 0.1628 | 0.0210 | Inf | 0.1258 | 0.2082 |
| Undergraduate Degree | NH_Other | Unemployed | Married | 0.1388 | 0.0182 | Inf | 0.1067 | 0.1785 |
| Graduate Degree | NH_White | Employed | Never Married | 0.1340 | 0.0092 | Inf | 0.1170 | 0.1529 |
| HS Diploma/GED | NH_White | Employed | Never Married | 0.1402 | 0.0084 | Inf | 0.1246 | 0.1573 |
| Less than HS | NH_White | Employed | Never Married | 0.1367 | 0.0117 | Inf | 0.1153 | 0.1614 |
| Some college | NH_White | Employed | Never Married | 0.1507 | 0.0088 | Inf | 0.1342 | 0.1687 |
| Undergraduate Degree | NH_White | Employed | Never Married | 0.1281 | 0.0079 | Inf | 0.1134 | 0.1444 |
| Graduate Degree | Hispanic | Employed | Never Married | 0.0905 | 0.0108 | Inf | 0.0714 | 0.1141 |
| HS Diploma/GED | Hispanic | Employed | Never Married | 0.0949 | 0.0107 | Inf | 0.0759 | 0.1180 |
| Less than HS | Hispanic | Employed | Never Married | 0.0924 | 0.0108 | Inf | 0.0733 | 0.1160 |
| Some college | Hispanic | Employed | Never Married | 0.1024 | 0.0116 | Inf | 0.0818 | 0.1275 |
| Undergraduate Degree | Hispanic | Employed | Never Married | 0.0863 | 0.0099 | Inf | 0.0688 | 0.1079 |
| Graduate Degree | NH_Black | Employed | Never Married | 0.0920 | 0.0091 | Inf | 0.0756 | 0.1116 |
| HS Diploma/GED | NH_Black | Employed | Never Married | 0.0965 | 0.0087 | Inf | 0.0807 | 0.1151 |
| Less than HS | NH_Black | Employed | Never Married | 0.0940 | 0.0107 | Inf | 0.0750 | 0.1172 |
| Some college | NH_Black | Employed | Never Married | 0.1041 | 0.0093 | Inf | 0.0872 | 0.1238 |
| Undergraduate Degree | NH_Black | Employed | Never Married | 0.0878 | 0.0083 | Inf | 0.0728 | 0.1056 |
| Graduate Degree | NH_Other | Employed | Never Married | 0.0517 | 0.0077 | Inf | 0.0385 | 0.0691 |
| HS Diploma/GED | NH_Other | Employed | Never Married | 0.0543 | 0.0080 | Inf | 0.0405 | 0.0724 |
| Less than HS | NH_Other | Employed | Never Married | 0.0528 | 0.0085 | Inf | 0.0385 | 0.0721 |
| Some college | NH_Other | Employed | Never Married | 0.0588 | 0.0088 | Inf | 0.0437 | 0.0786 |
| Undergraduate Degree | NH_Other | Employed | Never Married | 0.0492 | 0.0073 | Inf | 0.0367 | 0.0657 |
| Graduate Degree | NH_White | Unemployed | Never Married | 0.2575 | 0.0160 | Inf | 0.2275 | 0.2900 |
| HS Diploma/GED | NH_White | Unemployed | Never Married | 0.2677 | 0.0136 | Inf | 0.2419 | 0.2951 |
| Less than HS | NH_White | Unemployed | Never Married | 0.2620 | 0.0187 | Inf | 0.2271 | 0.3003 |
| Some college | NH_White | Unemployed | Never Married | 0.2846 | 0.0144 | Inf | 0.2573 | 0.3135 |
| Undergraduate Degree | NH_White | Unemployed | Never Married | 0.2478 | 0.0140 | Inf | 0.2214 | 0.2763 |
| Graduate Degree | Hispanic | Unemployed | Never Married | 0.1824 | 0.0202 | Inf | 0.1461 | 0.2253 |
| HS Diploma/GED | Hispanic | Unemployed | Never Married | 0.1903 | 0.0193 | Inf | 0.1554 | 0.2310 |
| Less than HS | Hispanic | Unemployed | Never Married | 0.1859 | 0.0194 | Inf | 0.1509 | 0.2269 |
| Some college | Hispanic | Unemployed | Never Married | 0.2037 | 0.0208 | Inf | 0.1660 | 0.2475 |
| Undergraduate Degree | Hispanic | Unemployed | Never Married | 0.1748 | 0.0186 | Inf | 0.1412 | 0.2144 |
| Graduate Degree | NH_Black | Unemployed | Never Married | 0.1852 | 0.0170 | Inf | 0.1541 | 0.2210 |
| HS Diploma/GED | NH_Black | Unemployed | Never Married | 0.1932 | 0.0156 | Inf | 0.1644 | 0.2257 |
| Less than HS | NH_Black | Unemployed | Never Married | 0.1888 | 0.0190 | Inf | 0.1544 | 0.2288 |
| Some college | NH_Black | Unemployed | Never Married | 0.2067 | 0.0166 | Inf | 0.1761 | 0.2412 |
| Undergraduate Degree | NH_Black | Unemployed | Never Married | 0.1776 | 0.0157 | Inf | 0.1489 | 0.2103 |
| Graduate Degree | NH_Other | Unemployed | Never Married | 0.1089 | 0.0157 | Inf | 0.0817 | 0.1437 |
| HS Diploma/GED | NH_Other | Unemployed | Never Married | 0.1141 | 0.0160 | Inf | 0.0862 | 0.1494 |
| Less than HS | NH_Other | Unemployed | Never Married | 0.1112 | 0.0168 | Inf | 0.0823 | 0.1485 |
| Some college | NH_Other | Unemployed | Never Married | 0.1229 | 0.0174 | Inf | 0.0926 | 0.1613 |
| Undergraduate Degree | NH_Other | Unemployed | Never Married | 0.1040 | 0.0149 | Inf | 0.0781 | 0.1371 |
| Graduate Degree | NH_White | Employed | Widowed | 0.1931 | 0.0133 | Inf | 0.1684 | 0.2206 |
| HS Diploma/GED | NH_White | Employed | Widowed | 0.2014 | 0.0125 | Inf | 0.1781 | 0.2270 |
| Less than HS | NH_White | Employed | Widowed | 0.1968 | 0.0157 | Inf | 0.1678 | 0.2295 |
| Some college | NH_White | Employed | Widowed | 0.2153 | 0.0128 | Inf | 0.1914 | 0.2414 |
| Undergraduate Degree | NH_White | Employed | Widowed | 0.1852 | 0.0121 | Inf | 0.1626 | 0.2102 |
| Graduate Degree | Hispanic | Employed | Widowed | 0.1334 | 0.0160 | Inf | 0.1051 | 0.1679 |
| HS Diploma/GED | Hispanic | Employed | Widowed | 0.1396 | 0.0158 | Inf | 0.1114 | 0.1735 |
| Less than HS | Hispanic | Employed | Widowed | 0.1361 | 0.0155 | Inf | 0.1086 | 0.1694 |
| Some college | Hispanic | Employed | Widowed | 0.1500 | 0.0169 | Inf | 0.1198 | 0.1863 |
| Undergraduate Degree | Hispanic | Employed | Widowed | 0.1276 | 0.0149 | Inf | 0.1011 | 0.1597 |
| Graduate Degree | NH_Black | Employed | Widowed | 0.1356 | 0.0135 | Inf | 0.1112 | 0.1643 |
| HS Diploma/GED | NH_Black | Employed | Widowed | 0.1418 | 0.0130 | Inf | 0.1181 | 0.1694 |
| Less than HS | NH_Black | Employed | Widowed | 0.1384 | 0.0151 | Inf | 0.1113 | 0.1707 |
| Some college | NH_Black | Employed | Widowed | 0.1524 | 0.0136 | Inf | 0.1276 | 0.1811 |
| Undergraduate Degree | NH_Black | Employed | Widowed | 0.1297 | 0.0126 | Inf | 0.1069 | 0.1564 |
| Graduate Degree | NH_Other | Employed | Widowed | 0.0778 | 0.0118 | Inf | 0.0575 | 0.1044 |
| HS Diploma/GED | NH_Other | Employed | Widowed | 0.0816 | 0.0123 | Inf | 0.0605 | 0.1092 |
| Less than HS | NH_Other | Employed | Widowed | 0.0795 | 0.0127 | Inf | 0.0579 | 0.1081 |
| Some college | NH_Other | Employed | Widowed | 0.0882 | 0.0134 | Inf | 0.0652 | 0.1181 |
| Undergraduate Degree | NH_Other | Employed | Widowed | 0.0741 | 0.0113 | Inf | 0.0548 | 0.0996 |
| Graduate Degree | NH_White | Unemployed | Widowed | 0.3493 | 0.0178 | Inf | 0.3152 | 0.3849 |
| HS Diploma/GED | NH_White | Unemployed | Widowed | 0.3612 | 0.0147 | Inf | 0.3329 | 0.3906 |
| Less than HS | NH_White | Unemployed | Widowed | 0.3546 | 0.0198 | Inf | 0.3168 | 0.3943 |
| Some college | NH_White | Unemployed | Widowed | 0.3810 | 0.0150 | Inf | 0.3520 | 0.4107 |
| Undergraduate Degree | NH_White | Unemployed | Widowed | 0.3376 | 0.0161 | Inf | 0.3068 | 0.3700 |
| Graduate Degree | Hispanic | Unemployed | Widowed | 0.2566 | 0.0256 | Inf | 0.2096 | 0.3100 |
| HS Diploma/GED | Hispanic | Unemployed | Widowed | 0.2667 | 0.0244 | Inf | 0.2217 | 0.3172 |
| Less than HS | Hispanic | Unemployed | Widowed | 0.2611 | 0.0237 | Inf | 0.2174 | 0.3101 |
| Some college | Hispanic | Unemployed | Widowed | 0.2836 | 0.0258 | Inf | 0.2359 | 0.3367 |
| Undergraduate Degree | Hispanic | Unemployed | Widowed | 0.2469 | 0.0242 | Inf | 0.2027 | 0.2972 |
| Graduate Degree | NH_Black | Unemployed | Widowed | 0.2602 | 0.0212 | Inf | 0.2208 | 0.3039 |
| HS Diploma/GED | NH_Black | Unemployed | Widowed | 0.2704 | 0.0193 | Inf | 0.2342 | 0.3099 |
| Less than HS | NH_Black | Unemployed | Widowed | 0.2647 | 0.0228 | Inf | 0.2226 | 0.3117 |
| Some college | NH_Black | Unemployed | Widowed | 0.2874 | 0.0200 | Inf | 0.2498 | 0.3281 |
| Undergraduate Degree | NH_Black | Unemployed | Widowed | 0.2504 | 0.0199 | Inf | 0.2134 | 0.2914 |
| Graduate Degree | NH_Other | Unemployed | Widowed | 0.1590 | 0.0219 | Inf | 0.1207 | 0.2067 |
| HS Diploma/GED | NH_Other | Unemployed | Widowed | 0.1661 | 0.0222 | Inf | 0.1270 | 0.2143 |
| Less than HS | NH_Other | Unemployed | Widowed | 0.1622 | 0.0228 | Inf | 0.1222 | 0.2120 |
| Some college | NH_Other | Unemployed | Widowed | 0.1781 | 0.0239 | Inf | 0.1360 | 0.2298 |
| Undergraduate Degree | NH_Other | Unemployed | Widowed | 0.1522 | 0.0210 | Inf | 0.1154 | 0.1982 |
Since the author is interested in how SES (Marital status, employment status, and race and ethnicity) mediates the effects of educational differences on prenatal depression on women, the author used nested model comparison.
Predictor variables are entered into the model in “blocks”, for example, in the study’s outcome variable, prenatal depression and instead of entering all variables in the model simultaneously, the author begins with the effect of educational attainment, then add the effect of other socio-demographic variables such as race and ethnicity, employment and marital status.
fit.logit1<-svyglm(I(deprx==1)~educ, design=des, family=binomial) #educational attainment only
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
fit.logit2<-svyglm(I(deprx==1)~educ +race_eth+ empstat, design=des, family=binomial) #educational attainment only +race/ethnicity+employment status
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
fit.logit3<-svyglm(I(deprx==1)~educ +race_eth++empstat+mars, design=des, family=binomial) #educational attainment only +race/ethnicity+employment status+ marital status
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
In model 1 we see women with some college education have higher odds (0.22) of taking medication for depression, compared to women with graduate degree, while women with undergraduate degree show the lower odds (-0.09) of taking medication for depression.
summary(fit.logit1)
##
## Call:
## svyglm(formula = I(deprx == 1) ~ educ, design = des, family = binomial)
##
## Survey design:
## svydesign(ids = ~1, strata = ~strata, weights = ~sampweight,
## data = sub)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.32345 0.05360 -24.690 < 2e-16 ***
## educHS Diploma/GED 0.19199 0.06675 2.876 0.004030 **
## educLess than HS 0.22090 0.08989 2.457 0.014005 *
## educSome college 0.22449 0.06533 3.436 0.000591 ***
## educUndergraduate Degree -0.09690 0.07035 -1.377 0.168423
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1.000052)
##
## Number of Fisher Scoring iterations: 4
regTermTest(fit.logit1, test.terms = ~educ, method="Wald", df = NULL)
## Wald test for educ
## in svyglm(formula = I(deprx == 1) ~ educ, design = des, family = binomial)
## F = 10.18089 on 4 and 19075 df: p= 3.1273e-08
Now, let’s see if, by controlling for other two socio-demographic variables, race and ethnicity and employment status. The fancy word for when an effect is reduced is “attenuated”. We will also do a test to see if the model with the race and ethnicity and employment status significantly improve the model fit. Traditionally, this would be done using a likelihood ratio test, but in survey models, that’s not kosher
#controlling for race/ethnicity and employment status
summary(fit.logit2)
##
## Call:
## svyglm(formula = I(deprx == 1) ~ educ + race_eth + empstat, design = des,
## family = binomial)
##
## Survey design:
## svydesign(ids = ~1, strata = ~strata, weights = ~sampweight,
## data = sub)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.54184 0.05926 -26.019 < 2e-16 ***
## educHS Diploma/GED 0.02550 0.06854 0.372 0.710
## educLess than HS 0.01715 0.09412 0.182 0.855
## educSome college 0.10796 0.06713 1.608 0.108
## educUndergraduate Degree -0.07811 0.07158 -1.091 0.275
## race_ethHispanic -0.46628 0.10645 -4.380 1.19e-05 ***
## race_ethNH_Black -0.45330 0.08075 -5.614 2.01e-08 ***
## race_ethNH_Other -1.11355 0.14608 -7.623 2.60e-14 ***
## empstatUnemployed 0.86237 0.04441 19.417 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 0.9961602)
##
## Number of Fisher Scoring iterations: 4
regTermTest(fit.logit2, test.terms = ~race_eth, method="Wald", df = NULL)
## Wald test for race_eth
## in svyglm(formula = I(deprx == 1) ~ educ + race_eth + empstat, design = des,
## family = binomial)
## F = 33.57233 on 3 and 19071 df: p= < 2.22e-16
After controlling for race/ethnicity and employment status, we see the educational attainment in almost all groups attenuate (reduce in size) somewhat. Hence, the differences in prenatal depression are smaller once controlled for race/ethnicity and employment status. Furthermore, the F test (33.57) suggests that the second model fits the data better than the first one. It is another of these omnibus tests that asks whether there is any variation in our outcome by race and ethnicity and employment status in the second model.
Next we consider the third model, which contains employment and marital status of women:
#controlling for race/ethnicity+employment status+ marital status
summary(fit.logit3)
##
## Call:
## svyglm(formula = I(deprx == 1) ~ educ + race_eth + +empstat +
## mars, design = des, family = binomial)
##
## Survey design:
## svydesign(ids = ~1, strata = ~strata, weights = ~sampweight,
## data = sub)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.22252 0.07092 -17.237 < 2e-16 ***
## educHS Diploma/GED 0.05230 0.06889 0.759 0.44776
## educLess than HS 0.02342 0.09534 0.246 0.80595
## educSome college 0.13679 0.06733 2.031 0.04222 *
## educUndergraduate Degree -0.05155 0.07188 -0.717 0.47329
## race_ethHispanic -0.44134 0.10704 -4.123 3.75e-05 ***
## race_ethNH_Black -0.42271 0.08159 -5.181 2.23e-07 ***
## race_ethNH_Other -1.04345 0.14642 -7.127 1.07e-12 ***
## empstatUnemployed 0.80749 0.04605 17.534 < 2e-16 ***
## marsMarried -0.31549 0.05222 -6.042 1.55e-09 ***
## marsNever Married -0.64373 0.07065 -9.112 < 2e-16 ***
## marsWidowed -0.20725 0.07079 -2.928 0.00342 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 0.9959921)
##
## Number of Fisher Scoring iterations: 4
regTermTest(fit.logit3, test.terms = ~empstat, method="Wald", df = NULL)
## Wald test for empstat
## in svyglm(formula = I(deprx == 1) ~ educ + race_eth + +empstat +
## mars, design = des, family = binomial)
## F = 307.4585 on 1 and 19068 df: p= < 2.22e-16
In this model, the effects of employment and marital status of women for educational attainment go back up. This is something confusing. Unemployed women are more likely to take depression medication.
f1 <- fit.logit1 %>%
tbl_regression(exponentiate = T)
f2 <- fit.logit2 %>%
tbl_regression(exponentiate = T)
f3 <- fit.logit3 %>%
tbl_regression(exponentiate = T)
f_all <- tbl_merge( tbls= list(f1, f2, f3),
tab_spanner = c("**Model 1**", "**Model 2**", "**Model 3**"))
f_all
| Characteristic | Model 1 | Model 2 | Model 3 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| OR1 | 95% CI1 | p-value | OR1 | 95% CI1 | p-value | OR1 | 95% CI1 | p-value | |
| Education Level | |||||||||
| Graduate Degree | — | — | — | — | — | — | |||
| HS Diploma/GED | 1.21 | 1.06, 1.38 | 0.004 | 1.03 | 0.90, 1.17 | 0.7 | 1.05 | 0.92, 1.21 | 0.4 |
| Less than HS | 1.25 | 1.05, 1.49 | 0.014 | 1.02 | 0.85, 1.22 | 0.9 | 1.02 | 0.85, 1.23 | 0.8 |
| Some college | 1.25 | 1.10, 1.42 | <0.001 | 1.11 | 0.98, 1.27 | 0.11 | 1.15 | 1.00, 1.31 | 0.042 |
| Undergraduate Degree | 0.91 | 0.79, 1.04 | 0.2 | 0.92 | 0.80, 1.06 | 0.3 | 0.95 | 0.82, 1.09 | 0.5 |
| Race/Ethnicity | |||||||||
| NH_White | — | — | — | — | |||||
| Hispanic | 0.63 | 0.51, 0.77 | <0.001 | 0.64 | 0.52, 0.79 | <0.001 | |||
| NH_Black | 0.64 | 0.54, 0.74 | <0.001 | 0.66 | 0.56, 0.77 | <0.001 | |||
| NH_Other | 0.33 | 0.25, 0.44 | <0.001 | 0.35 | 0.26, 0.47 | <0.001 | |||
| Employment Status | |||||||||
| Employed | — | — | — | — | |||||
| Unemployed | 2.37 | 2.17, 2.58 | <0.001 | 2.24 | 2.05, 2.45 | <0.001 | |||
| Marital Status | |||||||||
| Divorced/Separated | — | — | |||||||
| Married | 0.73 | 0.66, 0.81 | <0.001 | ||||||
| Never Married | 0.53 | 0.46, 0.60 | <0.001 | ||||||
| Widowed | 0.81 | 0.71, 0.93 | 0.003 | ||||||
|
1
OR = Odds Ratio, CI = Confidence Interval
|
|||||||||
Model 1 (deprx+educ): Compared to women with graduate level, women with HS diploma/GED (OR =1.21), less than HS (OR = 1.25), and some college degree (OR = 1.25) are statistically more likely to take depression medication. Taking of depression medication among pregnant women with undergraduate degree was not statistically significant (p = 0.2) compared to women with graduate degree, even though results showed that women with undergraduate degree are less likely to take depression medicine.
Model 2: (#educational attainment only +race/ethnicity+employment status): When race/ethnicity and employment is included in the model, along with educational attainment, it was observed that employment status affected likelihood of taking depression medication. Unemployed women are 137% more likely (OR = 2.37) to take depression medication. Furthermore, women from all other racial and ethnic group, NH_Black (0.64), NH_Other(0.33), Hispanic (0.63), are less likely to take depression medication compared to NH_White pregnant women. Interestingly, when race/ethnicity and employment status was included in the model, the impact of educational attainment on taking depression medication was not statistically significant.
Model 3:(educational attainment only +race/ethnicity+employment status+ marital status): Finally, when marital status, race/ethnicity, employment status and educational attainment were included to the model, it was found that compared to divorced women, women who were married (OR = 0.73), never married (OR = 0.53), or widowed (OR = 0.81) all were less likely to take depression medicine. Furthermore, unemployed women (OR = 2.24) were still more likely to use depression medicine and NH_White women were also more likely to take medication for depression compared to women of other race/ethnicity. Interestingly, using this model it was found that statistically, there is 15 % more likelihood of women with some college degree (OR = 1.15) taking the depression medication compared to women with graduate degree.
The Akaike Information Criteria (AIC) test for the models which measures overall model deviance, or residual variance and a penalty term for the number of parameters in a model showed that model three has an the Akaike Information Criteria (AIC) of 19835.9, which is lower than the other two models, indicating model three is the better fit to the data and explains more variation in the data.
AIC(fit.logit1, fit.logit2, fit.logit3)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
## eff.p AIC deltabar
## [1,] 5.833799 20763.6 1.458450
## [2,] 12.991788 19959.0 1.623974
## [3,] 17.290147 19835.9 1.571832