Author: Susan Kuca Purpose: Explore maternal morbidity and mortality by state Data: Percentage of cause of maternal morbidity obtain from state health reports and complied into a spread sheet. Because each state report covers a different period of time, Percentages are used for comparison.
#loading packages
packages <- c('tidyverse','tableone','lmtest','broom','car', 'Hmisc', 'labelled', 'dplyr')
purrr::walk(packages,library,character.only=T)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Loading required package: zoo
##
##
## Attaching package: 'zoo'
##
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
##
## Loading required package: carData
##
##
## Attaching package: 'car'
##
##
## The following object is masked from 'package:dplyr':
##
## recode
##
##
## The following object is masked from 'package:purrr':
##
## some
##
##
##
## Attaching package: 'Hmisc'
##
##
## The following objects are masked from 'package:dplyr':
##
## src, summarize
##
##
## The following objects are masked from 'package:base':
##
## format.pval, units
#Loading the data
PercMort<-data.frame(read.csv(file="C:/Users/cadye/OneDrive/Desktop/R Class Folders/Final Project/HDS_Final_Project/percent cause of death.csv"))
#review the data
summary(PercMort)
## State year Number Suicide
## Length:6 Length:6 Min. : 12.0 Length:6
## Class :character Class :character 1st Qu.: 24.0 Class :character
## Mode :character Mode :character Median : 33.0 Mode :character
## Mean : 52.4
## 3rd Qu.: 80.0
## Max. :113.0
## NA's :1
## UOD_Sub OB.Comp Homicide MVA
## Length:6 Length:6 Length:6 Length:6
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Cm Cardiac Ca Met_End
## Length:6 Length:6 Length:6 Length:6
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Sep.Inf resp MH_ALL Covid.19
## Length:6 Length:6 Length:6 Length:6
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## COVID other Hemm Emboli.Thrombotic
## Length:6 Length:6 Length:6 Length:6
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## AutoImmune Injury Hema
## Length:6 Length:6 Length:6
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
PercMortCl<-PercMort %>%
mutate(Suicide = as.numeric(x=Suicide))%>%
mutate(UOD_Sub= as.numeric(x=UOD_Sub))%>%
mutate(OB.Comp= as.numeric(x= OB.Comp)) %>%
mutate(Homicide= as.numeric(x=Homicide))%>%
mutate(MVA= as.numeric(x= MVA))%>%
mutate(Cm = as.numeric(x=Cm))%>%
mutate(Cardiac= as.numeric(x= Cardiac))%>%
mutate(Ca= as.numeric(x= Ca))%>%
mutate(Met_End= as.numeric(x= Met_End)) %>%
mutate(Sep.Inf= as.numeric(x=Sep.Inf))%>%
mutate(MH_ALL= as.numeric(x= MH_ALL))%>%
mutate(resp= as.numeric(x= resp))%>%
mutate(COVID= as.numeric(x=COVID))%>%
mutate(other= as.numeric(x= other))%>%
mutate(Hemm= as.numeric(x= Hemm))%>%
mutate(Emboli.Thrombotic= as.numeric(x= Emboli.Thrombotic))%>%
mutate(AutoImmune= as.numeric(x=AutoImmune))%>%
mutate(Injury= as.numeric(x= Injury))%>%
mutate(Hema = as.numeric(x= Hema))
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Suicide = as.numeric(x = Suicide)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `UOD_Sub = as.numeric(x = UOD_Sub)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `OB.Comp = as.numeric(x = OB.Comp)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Homicide = as.numeric(x = Homicide)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `MVA = as.numeric(x = MVA)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Cm = as.numeric(x = Cm)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Cardiac = as.numeric(x = Cardiac)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Ca = as.numeric(x = Ca)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Met_End = as.numeric(x = Met_End)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Sep.Inf = as.numeric(x = Sep.Inf)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `MH_ALL = as.numeric(x = MH_ALL)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `resp = as.numeric(x = resp)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `COVID = as.numeric(x = COVID)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `other = as.numeric(x = other)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Hemm = as.numeric(x = Hemm)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Emboli.Thrombotic = as.numeric(x = Emboli.Thrombotic)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `AutoImmune = as.numeric(x = AutoImmune)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Injury = as.numeric(x = Injury)`.
## Caused by warning:
## ! NAs introduced by coercion
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Hema = as.numeric(x = Hema)`.
## Caused by warning:
## ! NAs introduced by coercion
lapply(PercMortCl, class)
## $State
## [1] "character"
##
## $year
## [1] "character"
##
## $Number
## [1] "integer"
##
## $Suicide
## [1] "numeric"
##
## $UOD_Sub
## [1] "numeric"
##
## $OB.Comp
## [1] "numeric"
##
## $Homicide
## [1] "numeric"
##
## $MVA
## [1] "numeric"
##
## $Cm
## [1] "numeric"
##
## $Cardiac
## [1] "numeric"
##
## $Ca
## [1] "numeric"
##
## $Met_End
## [1] "numeric"
##
## $Sep.Inf
## [1] "numeric"
##
## $resp
## [1] "numeric"
##
## $MH_ALL
## [1] "numeric"
##
## $Covid.19
## [1] "character"
##
## $COVID
## [1] "numeric"
##
## $other
## [1] "numeric"
##
## $Hemm
## [1] "numeric"
##
## $Emboli.Thrombotic
## [1] "numeric"
##
## $AutoImmune
## [1] "numeric"
##
## $Injury
## [1] "numeric"
##
## $Hema
## [1] "numeric"
PercMortCl1<- PercMortCl
PercMortCl1[is.na(PercMortCl1)]<-0
d[is.na(d)] <- 0
#Next the data set is reduced # States were not consistant in how they reported cause of death. For instance, once state combined overdose/ substance abuse into mental health, while another combined COVID into respiratory. For consistancy, I used the broader catergories, with the exception of OB complications, and combined the data.Cardiomyopathy was combined with Cardiac, COVID was combined with respiratory, MVA was mergedwith injury, and overdose, substance abuse and mental health were combined.
PercMortCl1$Card<- PercMortCl1$Cm + PercMortCl1$Cardiac
PercMortCl1$MH<-PercMortCl1$Suicide+PercMortCl1$UOD_Sub+PercMortCl1$MH_ALL
PercMortCl1$InjuryMVA<-PercMortCl1$MVA +PercMortCl1$Injury
PercMortCl1$RespCov<- PercMortCl1$resp+PercMortCl1$COVID
PercMortSm<-PercMortCl1%>%
select(State,Card, MH,InjuryMVA,RespCov,OB.Comp, Homicide,Ca,Sep.Inf, other,Hemm, Emboli.Thrombotic,
AutoImmune,Hema)
PercMortSm
## State Card MH InjuryMVA RespCov OB.Comp Homicide Ca Sep.Inf other Hemm
## 1 CO 0.06 0.47 0.00 0.00 0.35 0.00 0.00 0.06 0.00 0.00
## 2 TN 0.26 0.21 0.00 0.03 0.00 0.06 0.04 0.06 0.07 0.17
## 3 MS 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
## 4 AL 0.17 0.00 0.04 0.04 0.00 0.00 0.00 0.21 0.17 0.13
## 5 MN 0.16 0.00 0.08 0.08 0.00 0.00 0.00 0.17 0.08 0.08
## 6 WI 0.09 0.52 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.12
## Emboli.Thrombotic AutoImmune Hema
## 1 0.00 0.00 0.00
## 2 0.11 0.00 0.00
## 3 0.00 0.00 0.00
## 4 0.17 0.04 0.00
## 5 0.08 0.08 0.08
## 6 0.00 0.00 0.00
labelled::var_label(x= PercMortSm)<- c( "State", "Cardiac", "MentalHealthSubs", "InjuryMVA", "RespCov", "ObComplications", "Homicide", "Cancer",
"SepsisInfection", "Other", "Hemmorage",
"EmbolicThrombotic", "AutoImmune", "Hematologic")
PercMortSm1<-PercMortSm%>% mutate( across(c(Card, MH,InjuryMVA, RespCov,OB.Comp,
Homicide,Ca,Sep.Inf, other,Hemm, Emboli.Thrombotic,
AutoImmune,Hema ), function(x) x* 100))
PercMortSm1
## State Card MH InjuryMVA RespCov OB.Comp Homicide Ca Sep.Inf other Hemm
## 1 CO 6 47 0 0 35 0 0 6 0 0
## 2 TN 26 21 0 3 0 6 4 6 7 17
## 3 MS 0 0 0 0 0 0 0 0 0 0
## 4 AL 17 0 4 4 0 0 0 21 17 13
## 5 MN 16 0 8 8 0 0 0 17 8 8
## 6 WI 9 52 0 0 0 0 0 0 0 12
## Emboli.Thrombotic AutoImmune Hema
## 1 0 0 0
## 2 11 0 0
## 3 0 0 0
## 4 17 4 0
## 5 8 8 8
## 6 0 0 0
#Because the orginal data was in a wide format, it needed to be reshaped into a long format to be plotted.
# Package reshape 2 installed; commenting out beacause of knit errors
#install.packages("reshape2")
mortLong<-pivot_longer(PercMortSm1, cols="Card":"Hema", names_to= "Mortality", values_to= "Percent")
mortLong
## # A tibble: 78 × 3
## State Mortality Percent
## <chr> <chr> <dbl>
## 1 CO Card 6
## 2 CO MH 47
## 3 CO InjuryMVA 0
## 4 CO RespCov 0
## 5 CO OB.Comp 35
## 6 CO Homicide 0
## 7 CO Ca 0
## 8 CO Sep.Inf 6
## 9 CO other 0
## 10 CO Hemm 0
## # ℹ 68 more rows
mortPlot1<-mortLong%>%
ggplot(aes(x=Mortality, y= Percent, fill=State))+
geom_bar( position= "dodge", stat = "identity")+
theme_minimal()
mortPlot1
mortPlot2<-mortLong%>%
ggplot(aes(x=State, y= Percent, fill=Mortality))+
geom_bar( position= "stack", stat = "identity")+
theme_minimal()
mortPlot2
# Install export package; commenting out to allow for knitting
# install.packages("export")
library(export)
graph2ppt(mortPlot1, file= "Myplot.pptx")
## Exported graph as Myplot.pptx
graph2ppt(mortPlot2, file = "Myplot2.pptx")
## Exported graph as Myplot2.pptx