hardtoget<-haven::read_xpt("/Users/christacrumrine/Downloads/LLCP2020.XPT ")
names(hardtoget)<-tolower(gsub(pattern = "_", replacement = "",x=names(hardtoget)))
Data Preperation
#Age cut into intervals
hardtoget$age<-cut(hardtoget$ageg5yr,
breaks=c(0,24,39,59,79,99))
#Hours of time spent as provider
hardtoget$hoursofcare<-Recode(hardtoget$crgvhrs1, recodes="1=1; 2=2; 3=3; 4=4; else=NA", as.factor = T)
hardtoget$hoursofcare<-relevel(hardtoget$hoursofcare, ref = "1")
#has health coverage
hardtoget$healthinsurace_coverage<- car::Recode(hardtoget$hlthpln1,
recodes="1='no, has coverage'; 2='yes, no coverage';else=NA",
as.factor=T)
hardtoget$healthinsurace_coverage<-relevel(hardtoget$healthinsurace_coverage, ref='yes, no coverage')
#sex
hardtoget$male<-as.factor(ifelse(hardtoget$colgsex==1,
"Male",
"Female"))
#marital status
hardtoget$marst<-Recode(hardtoget$marital, recodes="1='married'; 2='divorced'; 3='widowed'; 4='separated'; 5='nm';6='cohab'; else=NA", as.factor=T)
#depression
hardtoget$depression<-Recode(hardtoget$addepev3, recodes="1=1; 2=0; else=NA")
#assist personal care
hardtoget$ADLcare<-Recode(hardtoget$crgvper1, recodes="1=1; 2=0; else=NA")
#assist home tasks
hardtoget$IADLcare<-Recode(hardtoget$crgvhou1, recodes="1=1; 2=0; else=NA")
#Poor or fair self rated health
hardtoget$badhealth<-Recode(hardtoget$genhlth,
recodes="4:5=1; 1:3=0; else=NA")
#Drink alcohol
hardtoget$drink<-Recode(hardtoget$drnkany5, recodes="1=1; 2=0; else=NA")
#length caring for someone
hardtoget$cargving<-Recode(hardtoget$crgvlng1,
recodes="1='0less30'; 2='1to6mnths'; 3='2sixmnthsto2yrs'; 4='3twofvyears'; 5='4fvyrsormore';7:9=NA",
as.factor=T)
hardtoget$cargving<-relevel(hardtoget$cargving, ref='0less30')
#have you been told you have diabetes
hardtoget$hvdiab<-Recode(hardtoget$prediab1,
recodes="1:2 ='yes'; 3 ='no'; else = NA",
as.factor=T)
#Ever had a stroke
hardtoget$stroke<-Recode(hardtoget$cvdstrk3, recodes="1=1; 2=0; else=NA")
#smoked
hardtoget$smoked<-Recode(hardtoget$smoke100, recodes="1=1; 2=0; else=NA")
#race/ethnicity
hardtoget$black<-Recode(hardtoget$imprace,
recodes="2=1; 9=NA; else=0")
hardtoget$white<-Recode(hardtoget$imprace,
recodes="1=1; 9=NA; else=0")
hardtoget$other<-Recode(hardtoget$imprace,
recodes="3:4=1; 9=NA; else=0")
hardtoget$hispanic<-Recode(hardtoget$imprace,
recodes="5=1; 9=NA; else=0")
hardtoget$race_eth<-Recode(hardtoget$imprace,
recodes="1='nhwhite'; 2='nh_black'; 3='nh_other';4='nh_multirace'; 5='hispanic'; else=NA",
as.factor = T)
#education level
hardtoget$educ<-Recode(hardtoget$educa,
recodes="1:2='0Prim'; 3='1somehs'; 4='2hsgrad'; 5='3somecol'; 6='4colgrad';9=NA",
as.factor=T)
hardtoget$educ<-relevel(hardtoget$educ, ref='2hsgrad')
#BMI, in the brfss_17a the bmi variable has 2 implied decimal places,
#so we must divide by 100 to get real bmi's
hardtoget$bmi<-hardtoget$bmi5/100
#Healthy days
hardtoget$healthdays<-Recode(hardtoget$menthlth, recodes = "88=0; 77=NA; 99=NA")
The outcome variable that I am using is healthdays which the number of days someone reports there mental health wasn’t good.
Linear Term
hardtogetb<-hardtoget%>%
select( llcpwt, ststr, healthdays, race_eth, badhealth, marst, educ, age, bmi, hoursofcare, cargving)%>%
filter(complete.cases(.))
#outcome badhealth, smooth term: age, hoursofcare and cargiving, rest are dummy variables
brfgam<-gam(badhealth ~ hoursofcare+ cargving+ marst+educ+race_eth+healthdays,
data=hardtogetb,
weights = llcpwt/mean(llcpwt, na.rm=T), #scales to mean of 1
family=binomial)
summary(brfgam)
##
## Family: binomial
## Link function: logit
##
## Formula:
## badhealth ~ hoursofcare + cargving + marst + educ + race_eth +
## healthdays
##
## Parametric coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.616525 0.253011 -10.342 < 2e-16 ***
## hoursofcare2 0.409852 0.118318 3.464 0.000532 ***
## hoursofcare3 -0.005551 0.134086 -0.041 0.966976
## hoursofcare4 0.147726 0.108222 1.365 0.172243
## cargving1to6mnths -0.021432 0.164904 -0.130 0.896591
## cargving2sixmnthsto2yrs -0.176226 0.146413 -1.204 0.228733
## cargving3twofvyears -0.161141 0.146870 -1.097 0.272565
## cargving4fvyrsormore 0.241645 0.131945 1.831 0.067040 .
## marstdivorced 0.613513 0.205788 2.981 0.002870 **
## marstmarried 0.258903 0.189743 1.364 0.172412
## marstnm -0.080519 0.200174 -0.402 0.687506
## marstseparated 0.184327 0.276256 0.667 0.504623
## marstwidowed 0.259565 0.256552 1.012 0.311659
## educ0Prim 0.577610 0.270127 2.138 0.032493 *
## educ1somehs 0.413115 0.144288 2.863 0.004195 **
## educ3somecol -0.326855 0.100002 -3.269 0.001081 **
## educ4colgrad -0.779479 0.125009 -6.235 4.51e-10 ***
## race_ethnh_black 0.687097 0.165846 4.143 3.43e-05 ***
## race_ethnh_multirace 1.346699 0.400664 3.361 0.000776 ***
## race_ethnh_other 1.126124 0.338904 3.323 0.000891 ***
## race_ethnhwhite 0.362027 0.142088 2.548 0.010837 *
## healthdays 0.066658 0.003680 18.115 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## R-sq.(adj) = 0.129 Deviance explained = 12%
## UBRE = -0.189 Scale est. = 1 n = 4807
#outcome badhealth, smooth term: healthdays, rest are dummy variables
brfgam_1<-gam(badhealth ~ hoursofcare+ cargving+ marst+educ+race_eth+ s(healthdays),
data=hardtogetb,
weights = llcpwt/mean(llcpwt, na.rm=T), #scales to mean of 1
family=binomial)
summary(brfgam_1)
##
## Family: binomial
## Link function: logit
##
## Formula:
## badhealth ~ hoursofcare + cargving + marst + educ + race_eth +
## s(healthdays)
##
## Parametric coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.24301 0.25071 -8.947 < 2e-16 ***
## hoursofcare2 0.41294 0.11839 3.488 0.000487 ***
## hoursofcare3 -0.01213 0.13427 -0.090 0.928042
## hoursofcare4 0.14861 0.10827 1.373 0.169901
## cargving1to6mnths -0.02805 0.16494 -0.170 0.864943
## cargving2sixmnthsto2yrs -0.19495 0.14653 -1.330 0.183366
## cargving3twofvyears -0.16223 0.14706 -1.103 0.269987
## cargving4fvyrsormore 0.25355 0.13212 1.919 0.054965 .
## marstdivorced 0.63319 0.20562 3.079 0.002074 **
## marstmarried 0.28894 0.18986 1.522 0.128047
## marstnm -0.07060 0.19974 -0.353 0.723758
## marstseparated 0.21325 0.27601 0.773 0.439749
## marstwidowed 0.30097 0.25719 1.170 0.241904
## educ0Prim 0.58964 0.27027 2.182 0.029130 *
## educ1somehs 0.41376 0.14428 2.868 0.004135 **
## educ3somecol -0.32918 0.10001 -3.291 0.000997 ***
## educ4colgrad -0.78252 0.12503 -6.259 3.88e-10 ***
## race_ethnh_black 0.68854 0.16625 4.142 3.45e-05 ***
## race_ethnh_multirace 1.35467 0.40273 3.364 0.000769 ***
## race_ethnh_other 1.14229 0.33994 3.360 0.000778 ***
## race_ethnhwhite 0.36164 0.14236 2.540 0.011078 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Approximate significance of smooth terms:
## edf Ref.df Chi.sq p-value
## s(healthdays) 3.102 3.761 329.4 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## R-sq.(adj) = 0.131 Deviance explained = 12.2%
## UBRE = -0.18973 Scale est. = 1 n = 4807
plot(brfgam_1)
anova( brfgam_1,
brfgam,
test="Chisq")
library(survey)
des<-svydesign(ids = ~1,
stata=~strata,
weights = ~ llcpwt,
data=hardtoget)
ex1<-svyglm(badhealth ~ cargving+ marst+educ+race_eth+healthdays,
family=gaussian,
des)
summary(ex1)
##
## Call:
## svyglm(formula = badhealth ~ cargving + marst + educ + race_eth +
## healthdays, design = des, family = gaussian)
##
## Survey design:
## svydesign(ids = ~1, stata = ~strata, weights = ~llcpwt, data = hardtoget)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.057885 0.061206 0.946 0.34432
## cargving1to6mnths 0.014521 0.032972 0.440 0.65966
## cargving2sixmnthsto2yrs -0.014285 0.028139 -0.508 0.61173
## cargving3twofvyears -0.007362 0.026817 -0.275 0.78369
## cargving4fvyrsormore 0.034694 0.027569 1.258 0.20828
## marstdivorced 0.072669 0.051088 1.422 0.15496
## marstmarried 0.023117 0.045313 0.510 0.60996
## marstnm -0.020493 0.049124 -0.417 0.67657
## marstseparated 0.019253 0.063819 0.302 0.76291
## marstwidowed 0.034512 0.051789 0.666 0.50519
## educ0Prim 0.087216 0.062248 1.401 0.16124
## educ1somehs 0.057159 0.039101 1.462 0.14385
## educ3somecol -0.032756 0.022022 -1.487 0.13697
## educ4colgrad -0.091747 0.020069 -4.571 4.95e-06 ***
## race_ethnh_black 0.075672 0.039454 1.918 0.05517 .
## race_ethnh_multirace 0.230245 0.089127 2.583 0.00981 **
## race_ethnh_other 0.127583 0.098336 1.297 0.19454
## race_ethnhwhite 0.047101 0.029981 1.571 0.11623
## healthdays 0.011044 0.001061 10.411 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 0.1800761)
##
## Number of Fisher Scoring iterations: 2