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
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.1 ✔ readr 2.2.0
## ✔ ggplot2 4.0.3 ✔ stringr 1.6.0
## ✔ lubridate 1.9.5 ✔ tibble 3.3.1
## ✔ purrr 1.2.2 ✔ tidyr 1.3.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(dplyr)
ice_arrests_results<-readRDS("cleaned_ice_dataset.Rdata")
ice_arrests_results4capstone <- ice_arrests_results|> select(apprehension_aor, apprehension_date, apprehension_state_original, apprehension_city_original, citizenship_country, gender, age_at_apprehension_approximate, case_threat_level2)
summary(ice_arrests_results4capstone)
## apprehension_aor apprehension_date apprehension_state_original
## Length :142906 Min. :2025-01-20 00:00:00 Length :142906
## N.unique : 5 1st Qu.:2025-08-11 00:00:00 N.unique : 1
## N.blank : 0 Median :2025-12-08 00:00:00 N.blank : 0
## Min.nchar: 29 Mean :2025-12-04 22:04:22 Min.nchar: 5
## Max.nchar: 34 3rd Qu.:2026-04-17 00:00:00 Max.nchar: 5
## Max. :2026-08-05 00:00:00 NAs : 4376
## apprehension_city_original citizenship_country gender
## Length :142906 Length :142906 Length :142906
## N.unique : 2444 N.unique : 165 N.unique : 3
## N.blank : 0 N.blank : 0 N.blank : 0
## Min.nchar: 1 Min.nchar: 4 Min.nchar: 4
## Max.nchar: 23 Max.nchar: 31 Max.nchar: 7
## NAs : 4425
## age_at_apprehension_approximate case_threat_level2
## Min. : 1.00 Min. :0.0000
## 1st Qu.: 27.00 1st Qu.:0.0000
## Median : 34.00 Median :0.0000
## Mean : 35.57 Mean :0.7033
## 3rd Qu.: 43.00 3rd Qu.:1.0000
## Max. :126.00 Max. :3.0000
summary(ice_arrests_results4capstone$case_threat_level2)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.7033 1.0000 3.0000
head(ice_arrests_results4capstone)
## # A tibble: 6 × 8
## apprehension_aor apprehension_date apprehension_state_or…¹
## <chr> <dttm> <chr>
## 1 San Antonio Area of Responsibility 2026-03-11 00:00:00 TEXAS
## 2 San Antonio Area of Responsibility 2026-08-01 00:00:00 TEXAS
## 3 Dallas Area of Responsibility 2025-03-26 00:00:00 <NA>
## 4 Harlingen Area of Responsibility 2025-08-13 00:00:00 TEXAS
## 5 Harlingen Area of Responsibility 2025-12-30 00:00:00 TEXAS
## 6 Harlingen Area of Responsibility 2026-07-24 00:00:00 TEXAS
## # ℹ abbreviated name: ¹​apprehension_state_original
## # ℹ 5 more variables: apprehension_city_original <chr>,
## # citizenship_country <chr>, gender <chr>,
## # age_at_apprehension_approximate <dbl>, case_threat_level2 <dbl>
library(pastecs)
##
## Attaching package: 'pastecs'
## The following object is masked from 'package:tidyr':
##
## extract
## The following objects are masked from 'package:dplyr':
##
## first, last
library(readxl)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
stat.desc(ice_arrests_results4capstone$case_threat_level2)
## nbr.val nbr.null nbr.na min max range
## 1.429060e+05 9.557800e+04 0.000000e+00 0.000000e+00 3.000000e+00 3.000000e+00
## sum median mean SE.mean CI.mean.0.95 var
## 1.005080e+05 0.000000e+00 7.033155e-01 2.939548e-03 5.761457e-03 1.234843e+00
## std.dev coef.var
## 1.111235e+00 1.579995e+00
table(ice_arrests_results4capstone$case_threat_level2)
##
## 0 1 2 3
## 95578 14291 12894 20143
14291+12894+20143
## [1] 47328
hist(ice_arrests_results4capstone$case_threat_level2,
main = "ICE Arrests by Level of Prior Criminal Conviction, Jan 2025-Aug 2026",
xlab = "Level",
ylab = "# of Arrests",
ylim = c(0,95000),
col = "lightblue",
border = "white",
breaks = 4)
table(ice_arrests_results4capstone$apprehension_aor)
##
## Dallas Area of Responsibility El Paso Area of Responsibility
## 31153 9608
## Harlingen Area of Responsibility Houston Area of Responsibility
## 30809 37942
## San Antonio Area of Responsibility
## 33394
table(ice_arrests_results4capstone$citizenship_country)
##
## AFGHANISTAN ALBANIA
## 97 14
## ALGERIA ANDORRA
## 10 1
## ANGOLA ANTIGUA-BARBUDA
## 40 1
## ARGENTINA ARMENIA
## 51 7
## AUSTRALIA AZERBAIJAN
## 6 14
## BAHAMAS BANGLADESH
## 12 23
## BARBADOS BELARUS
## 3 9
## BELGIUM BELIZE
## 4 68
## BENIN BHUTAN
## 9 5
## BOLIVIA BOSNIA-HERZEGOVINA
## 59 3
## BRAZIL BULGARIA
## 159 2
## BURKINA FASO BURMA
## 13 35
## BURUNDI CAMBODIA
## 7 23
## CAMEROON CANADA
## 118 50
## CAPE VERDE CHAD
## 1 2
## CHILE CHINA, PEOPLES REPUBLIC OF
## 78 628
## COLOMBIA CONGO
## 2639 17
## COSTA RICA CROATIA
## 60 1
## CUBA DEM REP OF THE CONGO
## 4683 35
## DJIBOUTI DOMINICA
## 1 3
## DOMINICAN REPUBLIC ECUADOR
## 129 1112
## EGYPT EL SALVADOR
## 84 6504
## EQUATORIAL GUINEA ERITREA
## 43 38
## ETHIOPIA FINLAND
## 16 3
## FRANCE GABON
## 12 8
## GAMBIA GEORGIA
## 1 20
## GERMANY GHANA
## 10 41
## GREECE GRENADA
## 2 3
## GUATEMALA GUINEA
## 11792 23
## GUINEA-BISSAU GUYANA
## 4 5
## HAITI HONDURAS
## 93 18780
## HONG KONG HUNGARY
## 2 13
## INDIA INDONESIA
## 667 39
## IRAN IRAQ
## 123 29
## IRELAND ISRAEL
## 4 23
## ITALY IVORY COAST
## 17 13
## JAMAICA JAPAN
## 50 3
## JORDAN KAZAKHSTAN
## 120 13
## KENYA KOREA
## 61 5
## KOSOVO KUWAIT
## 6 2
## KYRGYZSTAN LAOS
## 12 53
## LATVIA LEBANON
## 6 11
## LIBERIA LIBYA
## 11 5
## MACAU MALAWI
## 1 2
## MALAYSIA MALI
## 6 10
## MARSHALL ISLANDS MAURITANIA
## 1 23
## MEXICO MICRONESIA, FEDERATED STATES OF
## 76816 6
## MOLDOVA MONGOLIA
## 6 3
## MONTENEGRO MOROCCO
## 3 22
## MOZAMBIQUE NAMIBIA
## 2 2
## NEPAL NETHERLANDS
## 232 6
## NEW ZEALAND NICARAGUA
## 2 3320
## NIGER NIGERIA
## 13 289
## NORTH MACEDONIA PAKISTAN
## 3 149
## PALAU PALESTINE BORN BEFORE 1948
## 5 1
## PANAMA PAPUA NEW GUINEA
## 37 1
## PARAGUAY PERU
## 4 509
## PHILIPPINES POLAND
## 29 13
## PORTUGAL ROMANIA
## 12 183
## RUSSIA RWANDA
## 85 9
## SAMOA SAO TOME AND PRINCIPE
## 1 1
## SAUDI ARABIA SENEGAL
## 6 31
## SERBIA SIERRA LEONE
## 4 9
## SINGAPORE SLOVAKIA
## 1 2
## SLOVENIA SOMALIA
## 3 7
## SOUTH AFRICA SOUTH KOREA
## 17 20
## SOUTH SUDAN SPAIN
## 1 65
## SRI LANKA ST. KITTS-NEVIS
## 82 2
## ST. LUCIA ST. VINCENT-GRENADINES
## 3 2
## STATELESS SUDAN
## 14 24
## SWEDEN SYRIA
## 2 18
## TAIWAN TAJIKISTAN
## 27 7
## TANZANIA THAILAND
## 15 13
## TOGO TONGA
## 8 2
## TRINIDAD AND TOBAGO TUNISIA
## 8 7
## TURKIYE TURKMENISTAN
## 129 5
## UGANDA UKRAINE
## 7 31
## UNITED ARAB EMIRATES UNITED KINGDOM
## 1 38
## UNKNOWN URUGUAY
## 35 13
## UZBEKISTAN VENEZUELA
## 67 10873
## VIETNAM YEMEN
## 430 8
## YUGOSLAVIA ZAMBIA
## 1 8
## ZIMBABWE
## 51
table(ice_arrests_results4capstone$gender)
##
## Female Male Unknown
## 16774 126092 40
table(ice_arrests_results4capstone$age_at_apprehension_approximate)
##
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## 9 21 41 63 85 81 86 79 83 95 76 76 84 119 101 138
## 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
## 265 1098 2042 2585 3333 3676 3974 4250 4767 4876 4945 4972 5027 4953 5134 5098
## 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
## 5179 4805 4769 4600 4531 4395 4229 3928 3929 3740 3404 3336 3188 2881 2686 2460
## 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
## 2311 2052 1947 1660 1482 1349 1189 991 843 781 668 607 485 414 360 324
## 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
## 208 202 172 122 99 67 58 64 33 31 16 31 10 9 7 6
## 81 82 83 84 85 87 107 126
## 2 5 2 2 1 2 1 1
arrest_table <- table(ice_arrests_results4capstone$apprehension_aor, ice_arrests_results4capstone$case_threat_level2)
chisq.test(arrest_table)
##
## Pearson's Chi-squared test
##
## data: arrest_table
## X-squared = 4270.8, df = 12, p-value < 2.2e-16
ice_arrests_results4capstone %>% count(case_threat_level2)
## # A tibble: 4 × 2
## case_threat_level2 n
## <dbl> <int>
## 1 0 95578
## 2 1 14291
## 3 2 12894
## 4 3 20143
proportions(table(ice_arrests_results4capstone$case_threat_level2))
##
## 0 1 2 3
## 0.66881726 0.10000280 0.09022714 0.14095279
move decimal 2 spaces
ggplot creates graphs using raw data
ggplot(ice_arrests_results4capstone,aes(x=case_threat_level2)) + geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
ggplot(ice_arrests_results4capstone,aes(case_threat_level2)) + geom_bar()
ggplot(ice_arrests_results4capstone,aes(x=case_threat_level2,y=age_at_apprehension_approximate)) + geom_point()
cor(ice_arrests_results4capstone$case_threat_level2,ice_arrests_results4capstone$age_at_apprehension_approximate)
## [1] 0.09244681
ggplot(ice_arrests_results4capstone,aes(apprehension_aor)) + geom_bar()
shapiro-wilke test: low p value = deviations from normality = non
normality going on / not due to chance
geom_point - continuous numerical variables, ideal for understanding correlations or distributions between 2 - 5 variables (at most)
geom_line - good for time series or any kind of sequental data. Trends over time.
geom_bar - counts categorical variables or frequency counts
geom_histogram - similar to geom_bar, but only has one variable and is used to show distributions
geom_boxplot - comparing means across groups, continuous data only
The pearson correlation?? As number of arrests go up (or # of people without histories), those arrests w/ criminal histories go down
arrest_levels<-ice_arrests_results4capstone %>% select(case_threat_level2)
Descr. statistics table
box plot - proportion
ice_arrests_resultsfinal <- ice_arrests_results4capstone %>%
mutate(time_period = cut(as.Date(apprehension_date), breaks = "month"),
has_history = ifelse(case_threat_level2>0, "History", "No History"))
tbl <- table(ice_arrests_resultsfinal$time_period, ice_arrests_resultsfinal$has_history)
trend_table <- table(ice_arrests_resultsfinal$time_period, ice_arrests_resultsfinal$has_history)
round(prop.table(trend_table, margin =1),3)
##
## History No History
## 2025-01-01 0.519 0.481
## 2025-02-01 0.506 0.494
## 2025-03-01 0.500 0.500
## 2025-04-01 0.511 0.489
## 2025-05-01 0.493 0.507
## 2025-06-01 0.373 0.627
## 2025-07-01 0.370 0.630
## 2025-08-01 0.346 0.654
## 2025-09-01 0.317 0.683
## 2025-10-01 0.287 0.713
## 2025-11-01 0.269 0.731
## 2025-12-01 0.257 0.743
## 2026-01-01 0.292 0.708
## 2026-02-01 0.317 0.683
## 2026-03-01 0.317 0.683
## 2026-04-01 0.331 0.669
## 2026-05-01 0.325 0.675
## 2026-06-01 0.277 0.723
## 2026-07-01 0.281 0.719
## 2026-08-01 0.232 0.768
res <- chisq.test(trend_table)
res
##
## Pearson's Chi-squared test
##
## data: trend_table
## X-squared = 3617, df = 19, p-value < 2.2e-16
prop.trend.test(x = trend_table[,"History"], n=rowSums(trend_table))
##
## Chi-squared Test for Trend in Proportions
##
## data: trend_table[, "History"] out of rowSums(trend_table) ,
## using scores: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
## X-squared = 2033.5, df = 1, p-value < 2.2e-16
library(ggplot2)
ice_arrests_resultsfinal %>%
ggplot(aes(x=time_period, fill=has_history)) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent_format()) +
labs(
title = "Proportion of Individuals with Prior Convictions Over Time",
x = "Time Period",
y = "Percentage of Individuals",
fill = "Criminal History"
) +
theme_minimal() +
theme(axis.text=element_text(angle = 45, hjust = 1))
ice_arrests_resultsfinal %>%
ggplot(aes(x=time_period, fill=has_history)) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent_format()) +
labs(
title = "Proportion of Individuals with Prior Convictions Over Time",
x = "Time Period",
y = "Percentage of Individuals",
fill = "Criminal Conviction History"
) +
theme_minimal() +
theme(axis.text=element_text(angle = 45, hjust = 1))
ice_arrests_resultsfinal %>%
filter(!is.na(time_period), !is.na(has_history)) %>%
group_by(time_period) %>%
summarize(
pct_history = mean(has_history == "History"),
.groups = "drop"
) %>%
ggplot(aes(x = as.Date(time_period), y = pct_history)) +
geom_line(color = "#2c7bb6", linewidth = 1) +
geom_point(color = "#2c7bb6", size = 2.5) +
scale_y_continuous(labels = scales::percent_format(), limits = c(0, 1)) +
labs(
title = "Percentage with Criminal Conviction History Over Time",
x = "Time Period",
y = "Proportion with History"
) +
theme_minimal()