Iowa_Data

Iowa Data - Exanples

library(readr)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
Iowa_Pop <- read.csv("~/Desktop/Iowa_prison_pop.csv")
Iowa_Admin <- read.csv("~/Desktop/Iowa_prison_admin.csv")
Iowa_Release <- read.csv("~/Desktop/Offender_released.csv")
Iowa_Parole <- read.csv("~/Desktop/Iowa_Parole.csv")
Iowa_Population <- inner_join(Iowa_Admin, Iowa_Pop, by = "Offender.Number")

LOS breakdown by age at admission for people currently over the age of 55 years old.

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ 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
library(lubridate)
library(dplyr)
library(DT)
library(ggplot2)
Iowa_Pop.Geriatric <- Iowa_Pop %>%
  filter(Age >=55)
Iowa_Pop.Geriatric <- Iowa_Pop.Geriatric %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date))
current_year <- as.numeric(format(Sys.Date(), "%Y"))
Iowa_Pop.Geriatric <- Iowa_Pop.Geriatric %>%
  mutate(Birth.Year = current_year - Age)
Iowa_Pop.Geriatric <- Iowa_Pop.Geriatric %>%
  mutate(Age.At.Admission = Admission.Year - Birth.Year)
Iowa_Age_Count <- Iowa_Pop.Geriatric %>%
  group_by(Age.At.Admission, Months.Served, Age) %>%
  summarize(total_count = n(), .groups = "drop")
ggplot(Iowa_Age_Count, aes(x = Age.At.Admission, y = Months.Served, color = Age)) +
  geom_point()

Iowa_Age_Count <- Iowa_Pop.Geriatric %>%
  group_by(Age.At.Admission, Months.Served, Age) %>%
  summarize(total_count = n(), .groups = "drop")
datatable(Iowa_Age_Count)

The number of individuals who entered as emerging adults and have been incarcerated for at least 20 years (broken down by ‘years served’ cohorts)

library(dplyr)
library(tidyverse)
Iowa_Pop$Years.Served <- Iowa_Pop$Months.Served / 12
LPT <- Iowa_Pop %>%
  filter(Years.Served >= 20)
LPT <- LPT %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date))
current_year <- as.numeric(format(Sys.Date(), "%Y"))
LPT <- LPT %>%
  mutate(Birth.Year = current_year - Age)
LPT <- LPT %>%
  mutate(Age.At.Admission = Admission.Year - Birth.Year)
LPT<- LPT %>%
  mutate(Age.Group = ifelse(Age >= 55, "55 and older", "55 and Young"),
         Race.Category = ifelse(Race...Ethnicity %in% c("Black", "Hispanic", "American Indian or Alaska Native", "Asian or Pacific Islander"), "People of Color", "White"))
under_25_at_admission <- LPT %>%
  filter(Age.At.Admission < 25)

count_under_25 <- under_25_at_admission %>%
  summarise(Total.Count = n())

under_25_at_admission <- under_25_at_admission %>%
  mutate(Years.Served.Group = cut(Years.Served, breaks = seq(20, max(Years.Served, na.rm = TRUE) + 5, by = 5), 
                                  right = FALSE, include.lowest = TRUE))

years_served_breakdown <- under_25_at_admission %>%
  group_by(Years.Served.Group) %>%
  summarise(Total.Count = n())

datatable(years_served_breakdown,
          caption = "The number of individuals who entered as emerging adults and have been incarcerated for at least 20 years (broken down by years served cohorts")

Average Time served by offense, age-group, and race category

library(dplyr)
library(ggplot2)
Offense_LOS <- LPT %>%
  group_by(Age.Group, Race.Category, Offense.Description, Offense.Type) %>%
  summarise(Average.Years.Served = mean(Years.Served, na.rm = TRUE),
            Count = n()) %>%
  ungroup()
`summarise()` has grouped output by 'Age.Group', 'Race.Category',
'Offense.Description'. You can override using the `.groups` argument.
print(Offense_LOS)
# A tibble: 75 × 6
   Age.Group Race.Category Offense.Description Offense.Type Average.Years.Served
   <chr>     <chr>         <chr>               <chr>                       <dbl>
 1 55 and Y… People of Co… BURGLARY 1ST DEGREE Violent                      21.1
 2 55 and Y… People of Co… KIDNAPPING - 2ND D… Violent                      24.8
 3 55 and Y… People of Co… KIDNAPPING 1ST DEG… Violent                      24.1
 4 55 and Y… People of Co… MURDER 1ST DEGREE   Violent                      26.0
 5 55 and Y… People of Co… MURDER 2ND - 85%    Violent                      21.3
 6 55 and Y… People of Co… ROBBERY 1ST DEGREE  Violent                      28.8
 7 55 and Y… People of Co… ROBBERY 2ND DEGREE… Violent                      21.5
 8 55 and Y… People of Co… SEXUAL ABUSE - 2ND… Violent                      23.1
 9 55 and Y… White         ATTEMPT TO COMMIT … Violent                      30.9
10 55 and Y… White         ATTEMPTED MURDER, … Violent                      23.6
# ℹ 65 more rows
# ℹ 1 more variable: Count <int>
ggplot(Offense_LOS, aes(x = Offense.Type, y = Average.Years.Served, fill = interaction(Age.Group, Race.Category) ))+
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Average Time Served by Offense Type, Age Group, and Race Category",
       x = "Offense Type",
       y = "Average Years Served") +
  theme_minimal() +
  scale_fill_manual(values = c("55 and older.People of Color" = "blue", 
                               "55 and Young.People of Color" = "lightblue", 
                               "55 and older.White" = "red", 
                               "55 and Young.White" = "pink")) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Average Years Served for People Incarcerated Before/After 25, Now Over 55’ by admission cohort

library(dplyr)
library(lubridate)
library(DT)
population_over_55 <- Iowa_Pop.Geriatric %>%
  filter(Age >= 55)
population_over_55 <- population_over_55 %>%
  mutate(Admit.Age.Group = ifelse(Age.At.Admission < 25, "Emerging Adult (Under 25)", "Over 25"))
population_over_55 <- population_over_55 %>%
  mutate(Years.Served = Months.Served / 12,
         Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date))
population_over_55 <- population_over_55 %>%
  mutate(Cohort = cut(Admission.Year, breaks = seq(1960, 2025, by = 5), include.lowest = TRUE))
average_sentence_by_group <- population_over_55 %>%
  group_by(Cohort, Admit.Age.Group) %>%
  summarise(
    Avg.Years.Served = mean(Years.Served, na.rm = TRUE),
    Count = n()
  ) %>%
  ungroup()
`summarise()` has grouped output by 'Cohort'. You can override using the
`.groups` argument.
print(average_sentence_by_group)
# A tibble: 19 × 4
   Cohort      Admit.Age.Group           Avg.Years.Served Count
   <fct>       <chr>                                <dbl> <int>
 1 [1960,1965] Emerging Adult (Under 25)            62.1      3
 2 (1965,1970] Emerging Adult (Under 25)            53.7      2
 3 (1965,1970] Over 25                              54.7      1
 4 (1970,1975] Emerging Adult (Under 25)            51.2      7
 5 (1970,1975] Over 25                              50.1      2
 6 (1975,1980] Emerging Adult (Under 25)            45.1     11
 7 (1975,1980] Over 25                              46.0     25
 8 (1980,1985] Emerging Adult (Under 25)            41.4     25
 9 (1980,1985] Over 25                              41.5     29
10 (1985,1990] Emerging Adult (Under 25)            36.2     27
11 (1985,1990] Over 25                              35.9     44
12 (1990,1995] Emerging Adult (Under 25)            32.6      6
13 (1990,1995] Over 25                              31.3     53
14 (1995,2000] Over 25                              26.1     61
15 (2000,2005] Over 25                              20.8    111
16 (2005,2010] Over 25                              16.1    163
17 (2010,2015] Over 25                              11.1    152
18 (2015,2020] Over 25                               6.14   181
19 (2020,2025] Over 25                               1.23   572
datatable(average_sentence_by_group, 
          caption = 'Average Years Served for People Incarcerated Before/After 25, Now Over 55')

Two options: What is the proportion of people serving long sentences (20 yrs or more), particularly among the aging population, and people of color

Proportion tables of those incarcerated for more than 20 years by age, race, and combined

library(dplyr)
Iowa_Pop$Years.Served <- Iowa_Pop$Months.Served / 12
LPT <- Iowa_Pop %>%
  filter(Years.Served >= 20)
LPT <- LPT %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date))
current_year <- as.numeric(format(Sys.Date(), "%Y"))
LPT <- LPT %>%
  mutate(Birth.Year = current_year - Age)
LPT <- LPT %>%
  mutate(Age.At.Admission = Admission.Year - Birth.Year)
LPT<- LPT %>%
  mutate(Age.Group = ifelse(Age >= 55, "55 and older", "55 and Young"),
         Race.Category = ifelse(Race...Ethnicity %in% c("Black", "Hispanic", "American Indian or Alaska Native", "Asian or Pacific Islander"), "People of Color", "White"))
long_term_proportions_age <- LPT %>%
  group_by(Age.Group) %>%
  summarise(Count = n()) %>%
  ungroup() %>%
  mutate(Proportion = Count / sum(Count))
long_term_proportions_race <- LPT %>%
  group_by(Race.Category) %>%
  summarise(Count = n()) %>%
  ungroup() %>%
  mutate(Proportion = Count / sum(Count))
long_term_proportions_age_race <- LPT %>%
  group_by(Race.Category, Age.Group) %>%
  summarise(Count = n()) %>%
  ungroup()  %>%
  mutate(Proportion = Count / sum(Count))
`summarise()` has grouped output by 'Race.Category'. You can override using the
`.groups` argument.
datatable(long_term_proportions_race)
datatable(long_term_proportions_age)
datatable(long_term_proportions_age_race)

Second: Create 5 year cohorts of admission year

library(dplyr)
library(lubridate)

Iowa_Pop$Years.Served <- Iowa_Pop$Months.Served / 12

LPT <- Iowa_Pop %>%
  filter(Years.Served >= 20)

LPT <- LPT %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date),
         Birth.Year = current_year - Age,
         Age.At.Admission = Admission.Year - Birth.Year)

current_year <- as.numeric(format(Sys.Date(), "%Y"))

LPT <- LPT %>%
  mutate(Age.Group = ifelse(Age.At.Admission >= 55, "55 and older", "Under 55"),
         Race.Category = ifelse(Race...Ethnicity %in% c("Black", "Hispanic", 
                            "American Indian or Alaska Native", "Asian or Pacific Islander"), 
                            "People of Color", "White"))

LPT <- LPT %>%
  mutate(Cohort = cut(Admission.Year, breaks = seq(1960, current_year, by = 5), include.lowest = TRUE))

long_term_proportions_age_race <- LPT %>%
  group_by(Cohort, Age.Group, Race.Category) %>%
  summarise(Count = n()) %>%
  ungroup() %>%
  group_by(Cohort) %>%
  mutate(Proportion = Count / sum(Count))
`summarise()` has grouped output by 'Cohort', 'Age.Group'. You can override
using the `.groups` argument.
datatable(long_term_proportions_age_race)

Age Distribution of Individuals Serving Long Prison Terms for Violent Offenses by Race/Ethnicity

library(tidyverse)
library(lubridate)
library(dplyr)
library(DT)

LPT.age.offense <- LPT %>%
  filter(Offense.Type == "Violent")
LPT.age.offense <- LPT.age.offense %>%
  mutate(Age.Cohort = case_when(
    Age.At.Admission < 25 ~ "Emerging Adult (Under 25)",
    Age.At.Admission >= 25 & Age.At.Admission < 35 ~ "25-34 years",
    Age.At.Admission >= 35 & Age.At.Admission < 45 ~ "35-44 years",
    Age.At.Admission >= 45 & Age.At.Admission < 55 ~ "45-54 years",
    Age.At.Admission >= 55  ~ "55 + years",
  ))

age_race_distribution <- LPT.age.offense %>%
  group_by(Age.Cohort, Race.Category) %>%
  summarise(Count = n()) %>%
  group_by(Race.Category) %>%
  mutate(Proportion = Count / sum(Count))
`summarise()` has grouped output by 'Age.Cohort'. You can override using the
`.groups` argument.
datatable(age_race_distribution, 
          caption = 'Age Distribution of Individuals Serving Long Prison Terms for Violent Offenses by Race/Ethnicity')

Proportion of Individuals Serving Long Prison Terms for Violent Offenses by Age Cohort’)

library(tidyverse)
library(lubridate)
library(dplyr)
library(DT)

Iowa_Pop$Years.Served <- Iowa_Pop$Months.Served / 12

LPT_all <- Iowa_Pop %>%
  filter(Years.Served >= 20)

LPT_violent <- LPT_all %>%
  filter(Offense.Type == "Violent")

LPT_all <- LPT_all %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date),
         current_year = as.numeric(format(Sys.Date(), "%Y")),
         Birth.Year = current_year - Age,  # Calculate birth year
         Age.At.Admission = Admission.Year - Birth.Year)  # Age at admission

LPT_violent <- LPT_violent %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date),
         current_year = as.numeric(format(Sys.Date(), "%Y")),
         Birth.Year = current_year - Age,  # Calculate birth year
         Age.At.Admission = Admission.Year - Birth.Year)  # Age at admission

LPT_all <- LPT_all %>%
  mutate(Age.Cohort = case_when(
    Age.At.Admission < 25 ~ "Emerging Adult (Under 25)",
    Age.At.Admission >= 25 & Age.At.Admission < 35 ~ "25-34 years",
    Age.At.Admission >= 35 & Age.At.Admission < 45 ~ "35-44 years",
    Age.At.Admission >= 45 & Age.At.Admission < 55 ~ "45-54 years",
    Age.At.Admission >= 55 & Age.At.Admission < 65 ~ "55-64 years",
    Age.At.Admission >= 65 ~ "65+ years"
  ))

LPT_violent <- LPT_violent %>%
  mutate(Age.Cohort = case_when(
    Age.At.Admission < 25 ~ "Emerging Adult (Under 25)",
    Age.At.Admission >= 25 & Age.At.Admission < 35 ~ "25-34 years",
    Age.At.Admission >= 35 & Age.At.Admission < 45 ~ "35-44 years",
    Age.At.Admission >= 45 & Age.At.Admission < 55 ~ "45-54 years",
    Age.At.Admission >= 55 & Age.At.Admission < 65 ~ "55-64 years",
    Age.At.Admission >= 65 ~ "65+ years"
  ))

LPT_total_age <- LPT_all %>%
  group_by(Age.Cohort) %>%
  summarise(Total.Count = n())

LPT_violent_age <- LPT_violent %>%
  group_by(Age.Cohort) %>%
  summarise(Violent.Count = n())

LPT_age_distribution <- LPT_total_age %>%
  left_join(LPT_violent_age, by = "Age.Cohort") %>%
  mutate(Proportion.Violent = Violent.Count / Total.Count)

datatable(LPT_age_distribution, 
          caption = 'Proportion of Individuals Serving Long Prison Terms for Violent Offenses by Age Cohort')

Proportion of Individuals Serving Long Prison Terms for Violent Offenses by Age Cohort and Race/Ethnicity’)

library(tidyverse)
library(lubridate)
library(dplyr)
library(DT)

Iowa_Pop$Years.Served <- Iowa_Pop$Months.Served / 12

LPT_all <- Iowa_Pop %>%
  filter(Years.Served >= 20)

LPT_violent <- LPT_all %>%
  filter(Offense.Type == "Violent")

LPT_all <- LPT_all %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date),
         current_year = as.numeric(format(Sys.Date(), "%Y")),
         Birth.Year = current_year - Age,  # Calculate birth year
         Age.At.Admission = Admission.Year - Birth.Year,  # Age at admission
         Race.Category = ifelse(Race...Ethnicity %in% c("Black", "Hispanic", 
                                                        "American Indian or Alaska Native", 
                                                        "Asian or Pacific Islander"), 
                                "People of Color", "White"))  # Categorize race/ethnicity

LPT_violent <- LPT_violent %>%
  mutate(Admission.Date = as.Date(Prison.Start.Date, format = "%m/%d/%Y"),
         Admission.Year = year(Admission.Date),
         current_year = as.numeric(format(Sys.Date(), "%Y")),
         Birth.Year = current_year - Age,  # Calculate birth year
         Age.At.Admission = Admission.Year - Birth.Year,  # Age at admission
         Race.Category = ifelse(Race...Ethnicity %in% c("Black", "Hispanic", 
                                                        "American Indian or Alaska Native", 
                                                        "Asian or Pacific Islander"), 
                                "People of Color", "White"))  # Categorize race/ethnicity

LPT_all <- LPT_all %>%
  mutate(Age.Cohort = case_when(
    Age.At.Admission < 25 ~ "Emerging Adult (Under 25)",
    Age.At.Admission >= 25 & Age.At.Admission < 35 ~ "25-34 years",
    Age.At.Admission >= 35 & Age.At.Admission < 45 ~ "35-44 years",
    Age.At.Admission >= 45 & Age.At.Admission < 55 ~ "45-54 years",
    Age.At.Admission >= 55 & Age.At.Admission < 65 ~ "55-64 years",
    Age.At.Admission >= 65 ~ "65+ years"
  ))

LPT_violent <- LPT_violent %>%
  mutate(Age.Cohort = case_when(
    Age.At.Admission < 25 ~ "Emerging Adult (Under 25)",
    Age.At.Admission >= 25 & Age.At.Admission < 35 ~ "25-34 years",
    Age.At.Admission >= 35 & Age.At.Admission < 45 ~ "35-44 years",
    Age.At.Admission >= 45 & Age.At.Admission < 55 ~ "45-54 years",
    Age.At.Admission >= 55 & Age.At.Admission < 65 ~ "55-64 years",
    Age.At.Admission >= 65 ~ "65+ years"
  ))

LPT_total_age_race <- LPT_all %>%
  group_by(Age.Cohort, Race.Category) %>%
  summarise(Total.Count = n())
`summarise()` has grouped output by 'Age.Cohort'. You can override using the
`.groups` argument.
LPT_violent_age_race <- LPT_violent %>%
  group_by(Age.Cohort, Race.Category) %>%
  summarise(Violent.Count = n())
`summarise()` has grouped output by 'Age.Cohort'. You can override using the
`.groups` argument.
LPT_age_race_distribution <- LPT_total_age_race %>%
  left_join(LPT_violent_age_race, by = c("Age.Cohort", "Race.Category")) %>%
  mutate(Proportion.Violent = Violent.Count / Total.Count)

datatable(LPT_age_race_distribution, 
          caption = 'Proportion of Individuals Serving Long Prison Terms for Violent Offenses by Age Cohort and Race/Ethnicity')