F-31 Data

Author

Jacob Souch

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.3.0      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(usmap)

#Residential mobility 
maternalmortality2018 <- read_csv("C:/Users/jacob/Downloads/maternalmortality2018.csv", 
    skip = 2)
Rows: 52 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Location, Maternal Mortality Rate per 100,000 live Births
dbl (1): Number of Deaths

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
maternalmortality2018$NAME <- maternalmortality2018$Location

maternalmortality2018$`Maternal Mortality Rate per 100,000 live Births` <- as.numeric(maternalmortality2018$`Maternal Mortality Rate per 100,000 live Births`)
Warning: NAs introduced by coercion
x <- tidycensus::load_variables("acs5", year = 2018)

y <- tidycensus::get_acs(variables = c(DiffCoSameState = "B07403_010"   ,
WithinCoF = "B07403_009", DiffStateF = "B07403_015", TotFemale = "B07403_001", DiffCoSameStateF ="B07403_012", SameHouseFemale = "B07403_006"), geography = "state",output = "wide", year= 2018 )
Getting data from the 2014-2018 5-year ACS
y$WithinCoPctFemale <- y$WithinCoFE/y$TotFemaleE*100
y$DiffStatePctFemale <- y$DiffStateFE/y$TotFemaleE*100
y$DiffCoSameStatePctFemale <- y$DiffCoSameStateFE/y$TotFemaleE*100
y$SameHouseFemalePct <- y$SameHouseFemaleE/y$TotFemaleE*100



joined <- left_join(y, maternalmortality2018, by = "NAME")



cor.test(joined$`Maternal Mortality Rate per 100,000 live Births`, joined$DiffCoSameStatePctFemale, method = "spearman")
Warning in cor.test.default(joined$`Maternal Mortality Rate per 100,000 live
Births`, : Cannot compute exact p-value with ties

    Spearman's rank correlation rho

data:  joined$`Maternal Mortality Rate per 100,000 live Births` and joined$DiffCoSameStatePctFemale
S = 3214.7, p-value = 0.1271
alternative hypothesis: true rho is not equal to 0
sample estimates:
      rho 
0.2848242 
plot(joined$SameHouseFemalePct, joined$`Maternal Mortality Rate per 100,000 live Births`)

text(joined$NAME)
Warning in xy.coords(x, y, recycle = TRUE, setLab = FALSE): NAs introduced by
coercion

joined$state <- joined$NAME

vars <- c("SameHouseFemalePct", "DiffCoSameStatePctFemale", "DiffStatePctFemale")

#Mobility Measures 

lapply(vars, function(x)
  {
plot_usmap(regions = "states", values = x, data = joined)+
  scale_fill_continuous(
    low = "white", high = "steel blue", name = x, label = scales::comma
  )+
    ggtitle(x)+
  theme(legend.position = "right")
}
)
[[1]]


[[2]]


[[3]]

#Maternal Mortality

plot_usmap(regions = "states", values = "Maternal Mortality Rate per 100,000 live Births", data = joined)+
  scale_fill_continuous(
    low = "white", high = "red", label = scales::comma)+
    ggtitle("")+
  theme(legend.position = "right")

NVSS

#read.table("C:/Users/jacob/University of Texas at San Antonio/TEAM - Cossman Crew - General/F-31/Inputs/Nat2021us")

ACS/IPUMS

#if (!require("ipumsr")) stop("Reading IPUMS data into R requires the ipumsr package. It can be installed using the following command: install.packages('ipumsr')")

#ddi <- read_ipums_ddi("usa_00008.xml")
#data <- read_ipums_micro(ddi)