This segment deals with the basic logistic regression using a single categorical predictor. We use the babiesdata. This is summarised first-MinuteFifth-minute below:
Characteristic
N = 8,2581
Fifth minute APGAR Category
Low
345 (4.18%)
Medium
1,972 (23.9%)
High
5,941 (71.9%)
Mortality
1,358 (16.4%)
1 n (%)
29.1 Research question
What is the association between death and the fifth-minute APGAR Score categories?
What are the predicted probabilities of death for the various fifth minute APGAR score categories?
Do these probabilities differ significantly from each other?
29.2 Graphing variables
Code
babies %>%group_by(apgar5cat, died) %>%summarize(count =n(), .groups ="drop") %>%group_by(apgar5cat) %>%mutate(perc = count/sum(count)) %>%ggplot(aes(x = apgar5cat, y = count, fill = died, label =paste0(count, "\n (", scales::percent(perc), ")"))) +geom_bar(stat ="identity", position =position_dodge())+labs(x ="Five minute APGAR", y ="Frequency", fill ="Mortality")+geom_text(vjust =-.25, color="black", size =3, fontface="italic", position =position_dodge(width =1))+ylim(c(0, 6000)) +scale_fill_manual(values =c("#70161E","#A4B6AC"))+theme_bw()
Figure 29.1: Barplot of Five minute APGAR categories and Mortality