library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(survey)
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
##
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
##
## dotchart
library(questionr)
library(haven)
load("~/Documents/1A_DEM Doctorate/DEM 7283/brfss16.Rdata")
#names(brfss16)
#recode the number of hours of sleep to binary
brfss16$shortsleep<-Recode(brfss16$SLEPTIM1, recodes ="0:6=1; 7:24=0; else=NA", as.factor=T)
#recode general health. Good and excelent are good, all else less good
#brfss16$genpoor<-Recode(brfss16$GENHLTH, recodes ="4:5='fair poor'; 1:3='good'; else=NA")
#recode sex variable to male or female
brfss16$male<-Recode(brfss16$SEX, recodes="1='male'; 2='0female'; else=NA")
#recode 5 level race/ethnicity to individual variables
brfss16$black<-Recode(brfss16$`_RACEGR3`, recodes="2='nh black'; 9=NA; else='non black'")
brfss16$white<-Recode(brfss16$`_RACEGR3`, recodes="1='nh white'; 9=NA; else='non white'")
brfss16$other<-Recode(brfss16$`_RACEGR3`, recodes="3:4='other'; 9=NA; else='non other'")
brfss16$hispanic<-Recode(brfss16$`_RACEGR3`, recodes="5='hispanic'; 1:4='0non hispanic'; else=NA")
##Education
#recode college education
brfss16$college<-Recode(brfss16$`_EDUCAG`, recodes="3:4='college'; 1:2='0no college'; else=NA")
#income
#recode poverty
brfss16$poverty<-Recode(brfss16$INCOME2, recodes="1:4='poverty'; 5:8='0no poverty'; else=NA")
#recode employment
brfss16$employyes<-Recode(brfss16$EMPLOY1, recodes="1:2='employed'; 3:4='0not employed'; else=NA")
#recode laborforce etc
brfss16$laborforce<-Recode(brfss16$EMPLOY1, recodes="1:4='in lab force'; 5:8='not in lab force'; else=NA")
#recode marital status
brfss16$married<-Recode(brfss16$MARITAL, recodes="1='married'; 2:6='0not married'; else=NA")
##Chronic diseases
#recode diabetes ever
brfss16$dm<-Recode(brfss16$DIABETE3, recodes="1='diabetes'; 2='0no dm'; else=NA")
#recode obese ever
brfss16$obese<-Recode(brfss16$`_BMI5CAT`, recodes="4='obese'; 1:3='not obese'; else=NA")
#recode depression ever
#brfss16$depression<-Recode(brfss16$ADDEPEV2, recodes="1='depression'; 2='0no depression'; else=NA")
##Behaviors
#recode exercise recently
brfss16$exercise<-Recode(brfss16$EXERANY2, recodes="1='exercise'; 2='0no exercise'; else=NA")
##Insurance
#recode private insurace
#brfss16$privateins<-Recode(brfss16$HLTHCVR1, recodes="1:2='2private ins'; 3:7='1cvg'; 8='0none'; else=NA")
Using a subset of the dataset comprised of respondents in the labor force, we evaluated demographic variables (ie sex, hispanic ethnicity, marital status, education, poverty), activities (ie employment, exercise), or obesity to determine if any of the selected factors were associated with short sleep duration (ie less than 7 hours of sleep at night).
Data was weighted by person weight variable ’_LLCPWT’.
library(questionr)
labforcesub <-subset(brfss16, select=c ("shortsleep", "male", "hispanic", "married", "college", "poverty", "employyes", "obese", "dm", "exercise", "laborforce", "_LLCPWT")) %>%
filter(laborforce=="in lab force")
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$male, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0female male
## 0 0.6443741 0.6329230
## 1 0.3556259 0.3670770
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$hispanic, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0non hispanic hispanic
## 0 0.6348031 0.6593302
## 1 0.3651969 0.3406698
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$married, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0not married married
## 0 0.6097108 0.6644043
## 1 0.3902892 0.3355957
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$college, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0no college college
## 0 0.6230878 0.6470361
## 1 0.3769122 0.3529639
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$poverty, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0no poverty poverty
## 0 0.6435643 0.6076766
## 1 0.3564357 0.3923234
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$employyes, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0not employed employed
## 0 0.6116144 0.6405531
## 1 0.3883856 0.3594469
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$exercise, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0no exercise exercise
## 0 0.5913341 0.6500375
## 1 0.4086659 0.3499625
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$obese, weights=labforcesub$`_LLCPWT`), margin = 2)
## not obese obese
## 0 0.6526995 0.5937598
## 1 0.3473005 0.4062402
prop.table(wtd.table(labforcesub$shortsleep, labforcesub$dm, weights=labforcesub$`_LLCPWT`), margin = 2)
## 0no dm diabetes
## 0 0.6300624 0.5920181
## 1 0.3699376 0.4079819
labforcesub2<-labforcesub%>%
filter(is.na(`_LLCPWT`)==F)
options(survey.lonely.psu = "adjust")
design<-svydesign(ids=~1, weights=~`_LLCPWT`, data=labforcesub2)
Chi-squared analyses were performed with weighted, survey design object data ###chi-square with survey design
svy<- svyby(formula = ~shortsleep, by = ~male+hispanic+married+college+employyes+poverty+exercise+obese+dm, FUN = svymean, na.rm=T, design = design)
svychisq(~shortsleep + male, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + male, design = design)
## F = 9.123, ndf = 1, ddf = 257000, p-value = 0.002524
svychisq(~shortsleep + hispanic, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + hispanic, design = design)
## F = 17.155, ndf = 1, ddf = 257000, p-value = 3.447e-05
svychisq(~shortsleep + married, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + married, design = design)
## F = 206.07, ndf = 1, ddf = 257000, p-value < 2.2e-16
svychisq(~shortsleep + college, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + college, design = design)
## F = 35.118, ndf = 1, ddf = 257000, p-value = 3.107e-09
svychisq(~shortsleep + employyes, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + employyes, design = design)
## F = 16.989, ndf = 1, ddf = 257000, p-value = 3.761e-05
svychisq(~shortsleep + poverty, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + poverty, design = design)
## F = 49.122, ndf = 1, ddf = 257000, p-value = 2.411e-12
svychisq(~shortsleep + exercise, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + exercise, design = design)
## F = 147.32, ndf = 1, ddf = 257000, p-value < 2.2e-16
svychisq(~shortsleep + obese, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + obese, design = design)
## F = 186.05, ndf = 1, ddf = 257000, p-value < 2.2e-16
svychisq(~shortsleep + dm, design=design)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~shortsleep + dm, design = design)
## F = 2.9942, ndf = 1, ddf = 257000, p-value = 0.08356
Out of the variables evaluated, sex, hispanic ethnicity, marriage, college, employment, poverty, exercise, and obesity are not independent of short sleep duration. In this analysis, diabetes is independent and not associated with sleep duration.
logitmd1<- svyglm(shortsleep~male+hispanic+married+college+employyes+poverty+exercise+obese+dm, design=design,family=binomial)
## Warning in eval(family$initialize): non-integer #successes in a binomial
## glm!
stargazer(logitmd1, style="demography", type="html", title="Associations with Short Sleep Duration Using BRFSS 2016", covariate.labels = c("Male","Hispanic", "Married", "College Grad", "Employed", "Poverty", "Exercise", "Obese", "Diabetic", ci=T))
| shortsleep | |
| Male | -0.014 |
| (0.070) | |
| Hispanic | -0.260* |
| (0.102) | |
| Married | -0.260*** |
| (0.068) | |
| College Grad | 0.141* |
| (0.070) | |
| Employed | -0.300** |
| (0.105) | |
| Poverty | 0.083 |
| (0.087) | |
| Exercise | -0.241*** |
| (0.072) | |
| Obese | 0.171** |
| (0.065) | |
| Diabetic | 0.056 |
| (0.112) | |
| TRUE | 0.014 |
| (0.171) | |
| N | 18,192 |
| Log Likelihood | -9,203.634 |
| AIC | 18,427.270 |
| p < .05; p < .01; p < .001 | |
Employment had the highest magnitude parameter estimate that was associated with a decrease likelihood of short sleep duration. Hispanic ethnicity and exercise also had negative associations with short sleep duration. Obesity followed by college education had the highest positive association with short sleep duration.
oddsratio <- exp(cbind("Odds ratio" = coef(logitmd1), confint.default(logitmd1, level = 0.95)))
oddsratio
## Odds ratio 2.5 % 97.5 %
## (Intercept) 1.0140178 0.7253739 1.4175203
## malemale 0.9860223 0.8601012 1.1303786
## hispanichispanic 0.7712986 0.6310214 0.9427597
## marriedmarried 0.7707222 0.6740968 0.8811980
## collegecollege 1.1509110 1.0042039 1.3190511
## employyesemployed 0.7406208 0.6026715 0.9101461
## povertypoverty 1.0867449 0.9171714 1.2876704
## exerciseexercise 0.7854698 0.6815912 0.9051802
## obeseobese 1.1860184 1.0438754 1.3475170
## dmdiabetes 1.0574648 0.8487792 1.3174592
Having a college education (15%) and being obese (19%) had an increase in the odds of short sleep duration. Poverty and diabetes trended to have increased odds, but this was not statistically significant (Odds ratio 1.09, 0.92-1.29, Odds ratio 1.06, 0.85-1.32; respectively).
In contrast, there was a protective association with being hispanic (23%), married (23%), employed (16%), and exercise (21%) had a decreased in the odds of having short sleep duration. While males trended to have decreased odds, this was not statistically significant (Odds ratio 0.99, 0.86-1.13).