Step 3: For each variable, generate summary statistics based on whether high or low health literacy; Start with education level as example
## Get stratified counts and percentage of each education category
demo_ed = df.demo.prep %>% group_by(educ_p) %>%
summarize(count=n(), perce = (n()/nrow(df.demo.prep))*100)
demo_edlow = filter(df.demo.prep, predictions_LP=="Low") %>% group_by(educ_p) %>%
summarize(count=n(), perce = (n()/nrow(filter(., predictions_LP=="Low")))*100)
demo_edhigh = filter(df.demo.prep, predictions_LP=="High") %>% group_by(educ_p) %>%
summarize(count=n(), perce = (n()/nrow(filter(., predictions_LP=="High")))*100)
## Assemble into readable matrix
demoEduc = matrix(c(
"No degree ", demo_ed$count[2], round(demo_ed$perce[2],1) , demo_edlow$count[2], round(demo_edlow$perce[2],1), demo_edhigh$count[2], round(demo_edhigh$perce[2],1),
"GED/high school", demo_ed$count[1], round(demo_ed$perce[1],1) , demo_edlow$count[1], round(demo_edlow$perce[1],1), demo_edhigh$count[1], round(demo_edhigh$perce[1],1),
"Some college or more", demo_ed$count[3], round(demo_ed$perce[3],1) , demo_edlow$count[3], round(demo_edlow$perce[3],1), demo_edhigh$count[3], round(demo_edhigh$perce[3],1) ),
ncol=7,byrow=TRUE)
colnames(demoEduc) = c("Levels", "Total", "Total-%", "LowHL", "LowHL-%", "HighHL", "HighHL-%")
pander(head(demoEduc))
| No degree |
402 |
9.3 |
188 |
12.1 |
214 |
7.7 |
| GED/high school |
995 |
23 |
413 |
26.5 |
582 |
21 |
| Some college or more |
2934 |
67.7 |
959 |
61.5 |
1975 |
71.3 |
Step 4: Follow same procedure as above for remaining variables
## Get stratified counts and percentage of each sex category
demo_sex = df.demo.prep %>% group_by(sex) %>%
summarize(count=n(), perce = (n()/nrow(df.demo.prep))*100)
demo_sexlow = filter(df.demo.prep, predictions_LP=="Low") %>% group_by(sex) %>%
summarize(count=n(), perce = (n()/nrow(filter(., predictions_LP=="Low")))*100)
demo_sexhigh = filter(df.demo.prep, predictions_LP=="High") %>% group_by(sex) %>%
summarize(count=n(), perce = (n()/nrow(filter(., predictions_LP=="High")))*100)
## Assemble into readable matrix
demoSex = matrix(c(
"Women", demo_sex$count[2], round(demo_sex$perce[2],1) , demo_sexlow$count[2], round(demo_sexlow$perce[2],1), demo_sexhigh$count[2], round(demo_sexhigh$perce[2],1) ),
ncol=7,byrow=TRUE)
colnames(demoSex) = c("Levels", "Total", "Total-%", "LowHL", "LowHL-%", "HighHL", "HighHL-%")
pander(demoSex)
| Women |
1930 |
44.6 |
688 |
44.1 |
1242 |
44.8 |
## Get stratified counts and percentage of each race category
demo_race = df.demo.prep %>% group_by(race) %>%
summarize(count=n(), perce = (n()/nrow(df.demo.prep))*100)
demo_racelow = filter(df.demo.prep, predictions_LP=="Low") %>% group_by(race) %>%
summarize(count=n(), perce = (n()/nrow(filter(., predictions_LP=="Low")))*100)
demo_racehigh = filter(df.demo.prep, predictions_LP=="High") %>% group_by(race) %>%
summarize(count=n(), perce = (n()/nrow(filter(., predictions_LP=="High")))*100)
## Assemble into readable matrix
demoRace = matrix(c(
"White", demo_race$count[5], round(demo_race$perce[5],1) , demo_racelow$count[5], round(demo_racelow$perce[5],1), demo_racehigh$count[5], round(demo_racehigh$perce[5],1),
"Black", demo_race$count[2], round(demo_race$perce[2],1) , demo_racelow$count[2], round(demo_racelow$perce[2],1), demo_racehigh$count[2], round(demo_racehigh$perce[2],1),
"Hispanic", demo_race$count[3], round(demo_race$perce[3],1) , demo_racelow$count[3], round(demo_racelow$perce[3],1), demo_racehigh$count[3], round(demo_racehigh$perce[3],1),
"Asian", demo_race$count[1], round(demo_race$perce[1],1) , demo_racelow$count[1], round(demo_racelow$perce[1],1), demo_racehigh$count[1], round(demo_racehigh$perce[1],1),
"Other", demo_race$count[4], round(demo_race$perce[4],1) , demo_racelow$count[4], round(demo_racelow$perce[4],1), demo_racehigh$count[4], round(demo_racehigh$perce[4],1) ),
ncol=7,byrow=TRUE)
colnames(demoRace) = c("Levels", "Total", "Total-%", "LowHL", "LowHL-%", "HighHL", "HighHL-%")
pander(demoRace)
| White |
1407 |
32.5 |
431 |
27.6 |
976 |
35.2 |
| Black |
582 |
13.4 |
237 |
15.2 |
345 |
12.5 |
| Hispanic |
572 |
13.2 |
262 |
16.8 |
310 |
11.2 |
| Asian |
1348 |
31.1 |
484 |
31 |
864 |
31.2 |
| Other |
422 |
9.7 |
146 |
9.4 |
276 |
10 |
## Get mean and SD for continuous variable of age; Assemble into readable matrix
demo_low = filter(df.demo.prep, predictions_LP=="Low")
demo_high = filter(df.demo.prep, predictions_LP=="High")
demoAge = matrix(c(
"Age", round(mean(df.demo.prep$Age),1), round(sd(df.demo.prep$Age),1), round(mean(demo_low$Age),1), round(sd(demo_low$Age),1), round(mean(demo_high$Age),1), round(sd(demo_high$Age),1) ),
ncol=7,byrow=TRUE)
colnames(demoAge) = c("Levels", "Total", "Total-%", "LowHL", "LowHL-%", "HighHL", "HighHL-%")
pander(demoAge)
| Age |
57.2 |
10 |
56.6 |
10.2 |
57.6 |
9.8 |
## Get mean and SD for interval variable of comorbidity score; Assemble into readable matrix
democoMorbid = matrix(c(
"Comorbidity Score", round(mean(df.demo.prep$CHARLSON_INDEX),1), round(sd(df.demo.prep$CHARLSON_INDEX),1), round(mean(demo_low$CHARLSON_INDEX),1), round(sd(demo_low$CHARLSON_INDEX),1), round(mean(demo_high$CHARLSON_INDEX),1), round(sd(demo_high$CHARLSON_INDEX),1) ),
ncol=7,byrow=TRUE)
colnames(democoMorbid) = c("Levels", "Total", "Total-%", "LowHL", "LowHL-%", "HighHL", "HighHL-%")
pander(democoMorbid)
| Comorbidity Score |
2.2 |
1.5 |
2.2 |
1.6 |
2.1 |
1.5 |