Encounter data includes U.S. Border Patrol (USBP) Title 8 Apprehensions, Office of Field Operations (OFO) Title 8 Inadmissibles, and Title 42 Expulsions* for fiscal year (FY) 2024.
Demographics for USBP and OFO include:
#install.packages(“tidyverse”) #library(tidyverse)
Reading Data into R - Comma-Separated Values (CSV) data file from a text file
data <- read.csv('finalproject.csv' , header = TRUE , sep=',')
data$Fiscal.Year <- as.factor(data$Fiscal.Year)
data$Month.Grouping <- as.factor(data$Month.Grouping)
data$Month..abbv. <- as.factor(data$Month..abbv.)
data$Component <- as.factor(data$Component)
data$Land.Border.Region <- as.factor(data$Land.Border.Region)
data$Area.of.Responsibility <- as.factor(data$Area.of.Responsibility)
data$AOR..Abbv. <- as.factor(data$AOR..Abbv.)
data$Demographic <- as.factor(data$Demographic)
data$Citizenship <- as.factor(data$Citizenship)
data$Title.of.Authority <- as.factor(data$Title.of.Authority)
data$Encounter.Type <- as.factor(data$Encounter.Type)
summary(data$Encounter.Count)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.0 3.0 13.0 238.8 96.0 25457.0
hist(data$Encounter.Count, main = "Distribution of Encounter Counts", xlab = "Encounter Count")
# Calculate IQR for Encounter.Count
Q1 <- quantile(data$Encounter.Count, 0.25)
Q3 <- quantile(data$Encounter.Count, 0.75)
IQR <- Q3 - Q1
# Define lower and upper bounds for outliers
lower_bound <- Q1 - 1.5 * IQR
upper_bound <- Q3 + 1.5 * IQR
# Identify outliers
outliers <- subset(data$Encounter.Count, data$Encounter.Count < lower_bound | data$Encounter.Count > upper_bound)
# Count outliers
n_outliers <- length(outliers)
n_outliers
## [1] 974
The distribution of encounters exhibits a large number of outliers when detected using the IQR rule, which also confirms the right-skewed nature of the data. A log transformation is used to address the presence of outliers and to achieve normality.
data$Log_Encounter_Count <- log(data$Encounter.Count + 1)
hist(data$Log_Encounter_Count, main = "Histogram of Log-Transformed Encounter Counts", xlab = "Log(Encounter Count + 1)")
Boxplot for the log-transformed Encounter Count to visualize outliers
boxplot(data$Log_Encounter_Count, main = "Boxplot for Log-Transformed Encounter Counts")
Some factors were omitted due to the one-level rule, preventing the regression model from running.
options(width=120)
data$Log_Encounter_Count <- log(data$Encounter.Count + 1)
my.model <- lm(Log_Encounter_Count ~ Month..abbv. + Component +
Land.Border.Region + Area.of.Responsibility + Demographic +
Citizenship + Encounter.Type, data = data)
# Output the summary of the model:
summary(my.model)
##
## Call:
## lm(formula = Log_Encounter_Count ~ Month..abbv. + Component +
## Land.Border.Region + Area.of.Responsibility + Demographic +
## Citizenship + Encounter.Type, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.3910 -1.0367 -0.0847 1.0420 4.7252
##
## Coefficients: (2 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.12801 0.21718 0.589 0.555611
## Month..abbv.FEB -0.12174 0.06277 -1.940 0.052483 .
## Month..abbv.JAN -0.18721 0.06309 -2.967 0.003015 **
## Month..abbv.NOV -0.09181 0.06282 -1.462 0.143927
## Month..abbv.OCT -0.09192 0.06216 -1.479 0.139236
## ComponentU.S. Border Patrol -1.77068 0.23972 -7.386 1.71e-13 ***
## Land.Border.RegionOther -0.72400 0.11201 -6.464 1.10e-10 ***
## Land.Border.RegionSouthwest Land Border 2.52425 0.20758 12.160 < 2e-16 ***
## Area.of.ResponsibilityBaltimore Field Office 0.12562 0.17828 0.705 0.481066
## Area.of.ResponsibilityBig Bend Sector -2.12269 0.19811 -10.715 < 2e-16 ***
## Area.of.ResponsibilityBlaine Sector 0.26022 0.28171 0.924 0.355680
## Area.of.ResponsibilityBoston Field Office -0.40837 0.17068 -2.393 0.016755 *
## Area.of.ResponsibilityBuffalo Field Office -0.09382 0.19347 -0.485 0.627749
## Area.of.ResponsibilityBuffalo Sector -0.50853 0.33821 -1.504 0.132736
## Area.of.ResponsibilityChicago Field Office -0.38583 0.18011 -2.142 0.032220 *
## Area.of.ResponsibilityDel Rio Sector 1.50391 0.15399 9.766 < 2e-16 ***
## Area.of.ResponsibilityDetroit Field Office -0.99766 0.18250 -5.467 4.76e-08 ***
## Area.of.ResponsibilityDetroit Sector -0.42447 0.33632 -1.262 0.206971
## Area.of.ResponsibilityEl Centro Sector -0.86098 0.16099 -5.348 9.21e-08 ***
## Area.of.ResponsibilityEl Paso Field Office -1.90908 0.24097 -7.923 2.74e-15 ***
## Area.of.ResponsibilityEl Paso Sector 1.18960 0.15327 7.761 9.77e-15 ***
## Area.of.ResponsibilityGrand Forks Sector -0.45696 0.38630 -1.183 0.236891
## Area.of.ResponsibilityHavre Sector -0.81408 0.40808 -1.995 0.046096 *
## Area.of.ResponsibilityHoulton Sector -0.36470 0.33188 -1.099 0.271864
## Area.of.ResponsibilityHouston Field Office 1.12905 0.16562 6.817 1.02e-11 ***
## Area.of.ResponsibilityLaredo Field Office -1.31272 0.22776 -5.764 8.63e-09 ***
## Area.of.ResponsibilityLaredo Sector -0.89455 0.17499 -5.112 3.28e-07 ***
## Area.of.ResponsibilityLos Angeles Field Office 0.44006 0.17441 2.523 0.011658 *
## Area.of.ResponsibilityMiami Field Office 1.51429 0.16338 9.268 < 2e-16 ***
## Area.of.ResponsibilityMiami Sector 0.62783 0.28484 2.204 0.027549 *
## Area.of.ResponsibilityNew Orleans Field Office 0.23016 0.21988 1.047 0.295251
## Area.of.ResponsibilityNew Orleans Sector 0.65059 0.38197 1.703 0.088573 .
## Area.of.ResponsibilityNew York Field Office 0.46700 0.17093 2.732 0.006309 **
## Area.of.ResponsibilityPortland Field Office -1.01633 0.19886 -5.111 3.30e-07 ***
## Area.of.ResponsibilityPreclearance Field Office -0.01257 0.19367 -0.065 0.948236
## Area.of.ResponsibilityRamey Sector 1.15253 0.35298 3.265 0.001100 **
## Area.of.ResponsibilityRio Grande Valley Sector 0.77258 0.15126 5.108 3.36e-07 ***
## Area.of.ResponsibilitySan Diego Field Office -1.65980 0.21546 -7.704 1.53e-14 ***
## Area.of.ResponsibilitySan Diego Sector 1.08276 0.14277 7.584 3.85e-14 ***
## Area.of.ResponsibilitySan Francisco Field Office 0.33507 0.17966 1.865 0.062222 .
## Area.of.ResponsibilitySan Juan Field Office 0.13823 0.18278 0.756 0.449544
## Area.of.ResponsibilitySeattle Field Office -0.15478 0.17711 -0.874 0.382209
## Area.of.ResponsibilitySpokane Sector -0.60830 0.45674 -1.332 0.182966
## Area.of.ResponsibilitySwanton Sector 0.77510 0.26786 2.894 0.003821 **
## Area.of.ResponsibilityTampa Field Office 0.37429 0.17653 2.120 0.034028 *
## Area.of.ResponsibilityTucson Field Office -2.29010 0.22146 -10.341 < 2e-16 ***
## Area.of.ResponsibilityTucson Sector 1.16905 0.15119 7.732 1.22e-14 ***
## Area.of.ResponsibilityYuma Sector NA NA NA NA
## DemographicFMUA 2.07021 0.10289 20.120 < 2e-16 ***
## DemographicSingle Adults 2.23622 0.10063 22.222 < 2e-16 ***
## DemographicUC / Single Minors 0.31833 0.11416 2.788 0.005312 **
## CitizenshipCANADA 0.68623 0.15141 4.532 5.95e-06 ***
## CitizenshipCHINA, PEOPLES REPUBLIC OF 1.12118 0.14106 7.948 2.23e-15 ***
## CitizenshipCOLOMBIA 1.06842 0.12949 8.251 < 2e-16 ***
## CitizenshipCUBA 1.27409 0.13085 9.737 < 2e-16 ***
## CitizenshipECUADOR 0.80832 0.13608 5.940 3.00e-09 ***
## CitizenshipEL SALVADOR 0.78113 0.13478 5.796 7.15e-09 ***
## CitizenshipGUATEMALA 1.60398 0.13212 12.141 < 2e-16 ***
## CitizenshipHAITI 1.27504 0.13220 9.645 < 2e-16 ***
## CitizenshipHONDURAS 1.24432 0.13218 9.414 < 2e-16 ***
## CitizenshipINDIA 1.55321 0.13788 11.265 < 2e-16 ***
## CitizenshipMEXICO 2.46750 0.12412 19.881 < 2e-16 ***
## CitizenshipMYANMAR (BURMA) 0.59412 0.20485 2.900 0.003742 **
## CitizenshipNICARAGUA 1.04018 0.13105 7.938 2.43e-15 ***
## CitizenshipOTHER 1.85697 0.12166 15.263 < 2e-16 ***
## CitizenshipPERU 0.33990 0.13979 2.431 0.015068 *
## CitizenshipPHILIPPINES 1.88847 0.16323 11.569 < 2e-16 ***
## CitizenshipROMANIA -0.14221 0.15731 -0.904 0.366018
## CitizenshipRUSSIA 0.57377 0.14965 3.834 0.000127 ***
## CitizenshipTURKEY -0.36249 0.16367 -2.215 0.026815 *
## CitizenshipUKRAINE 1.88355 0.14165 13.297 < 2e-16 ***
## CitizenshipVENEZUELA 1.47151 0.12710 11.578 < 2e-16 ***
## Encounter.TypeInadmissibles NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.57 on 6157 degrees of freedom
## Multiple R-squared: 0.4158, Adjusted R-squared: 0.4091
## F-statistic: 62.6 on 70 and 6157 DF, p-value: < 2.2e-16
There are two coefficients not defined due to singularities: Area.of.ResponsibilityYuma Sector and Encounter.TypeInadmissibles. This suggests the presence of perfect multicollinearity, which occurs when one variable can be exactly predicted from others.
Upon inspection of the data, it was found that Encounter Type occurs only within a specific Area of Responsibility, and it does not add explanatory power beyond what is already captured by Area of Responsibility.
Consequently, Encounter Type has been dropped from Model 2. Similarly, Area of Responsibility has also been dropped from Model 2.
options(width=120)
data$Log_Encounter_Count <- log(data$Encounter.Count + 1)
my.model2 <- lm(Log_Encounter_Count ~ Month..abbv. + Component +
Land.Border.Region + Demographic +
Citizenship , data = data)
# To output the summary of the model:
summary(my.model2)
##
## Call:
## lm(formula = Log_Encounter_Count ~ Month..abbv. + Component +
## Land.Border.Region + Demographic + Citizenship, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.6461 -1.2442 -0.1849 1.1529 6.1798
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.23316 0.16476 -1.415 0.157069
## Month..abbv.FEB -0.12379 0.07008 -1.766 0.077394 .
## Month..abbv.JAN -0.14204 0.07045 -2.016 0.043811 *
## Month..abbv.NOV -0.05120 0.07016 -0.730 0.465556
## Month..abbv.OCT -0.09920 0.06942 -1.429 0.153068
## ComponentU.S. Border Patrol -0.19491 0.05785 -3.369 0.000759 ***
## Land.Border.RegionOther 0.22262 0.06506 3.421 0.000627 ***
## Land.Border.RegionSouthwest Land Border 1.92346 0.06692 28.744 < 2e-16 ***
## DemographicFMUA 1.93025 0.11418 16.905 < 2e-16 ***
## DemographicSingle Adults 1.89206 0.11112 17.027 < 2e-16 ***
## DemographicUC / Single Minors 0.26586 0.12675 2.098 0.035986 *
## CitizenshipCANADA 0.49518 0.16847 2.939 0.003302 **
## CitizenshipCHINA, PEOPLES REPUBLIC OF 1.01575 0.15699 6.470 1.05e-10 ***
## CitizenshipCOLOMBIA 0.89413 0.14439 6.192 6.30e-10 ***
## CitizenshipCUBA 1.10547 0.14570 7.587 3.75e-14 ***
## CitizenshipECUADOR 0.68012 0.15176 4.482 7.54e-06 ***
## CitizenshipEL SALVADOR 0.60567 0.15006 4.036 5.50e-05 ***
## CitizenshipGUATEMALA 1.29078 0.14688 8.788 < 2e-16 ***
## CitizenshipHAITI 1.09328 0.14728 7.423 1.30e-13 ***
## CitizenshipHONDURAS 0.98832 0.14697 6.725 1.92e-11 ***
## CitizenshipINDIA 1.42560 0.15340 9.293 < 2e-16 ***
## CitizenshipMEXICO 2.00370 0.13753 14.569 < 2e-16 ***
## CitizenshipMYANMAR (BURMA) 0.60561 0.22806 2.655 0.007941 **
## CitizenshipNICARAGUA 0.88367 0.14590 6.057 1.47e-09 ***
## CitizenshipOTHER 1.56601 0.13543 11.563 < 2e-16 ***
## CitizenshipPERU 0.34875 0.15596 2.236 0.025376 *
## CitizenshipPHILIPPINES 1.75690 0.18144 9.683 < 2e-16 ***
## CitizenshipROMANIA -0.25277 0.17492 -1.445 0.148489
## CitizenshipRUSSIA 0.43054 0.16680 2.581 0.009870 **
## CitizenshipTURKEY -0.21076 0.18242 -1.155 0.247990
## CitizenshipUKRAINE 1.61644 0.15731 10.275 < 2e-16 ***
## CitizenshipVENEZUELA 1.28007 0.14168 9.035 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.754 on 6196 degrees of freedom
## Multiple R-squared: 0.2655, Adjusted R-squared: 0.2618
## F-statistic: 72.25 on 31 and 6196 DF, p-value: < 2.2e-16
Reading Data into R - Comma-Separated Values (CSV) data file from a text file
data3 <- read.csv('finalproject_model3.csv' ,
header = TRUE ,
sep=',')
data3$Log_Encounter_Count3 <- log(data3$Encounter.Count + 1)
hist(data$Log_Encounter_Count, main = "Histogram of Log-Transformed Encounter Counts", xlab = "Log(Encounter Count + 1)")
data3$Log_Encounter_Count3 <- log(data3$Encounter.Count + 1)
my.model3 <- lm(Log_Encounter_Count3 ~ +
Land.Border.Region + Demographic +
Citizenship , data = data3)
##One level factor : Component : U.S Patrol
# To output the summary of the model:
summary(my.model3)
##
## Call:
## lm(formula = Log_Encounter_Count3 ~ +Land.Border.Region + Demographic +
## Citizenship, data = data3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.6450 -1.1731 -0.0189 1.2557 5.3887
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.38993 0.30005 1.300 0.193997
## Land.Border.RegionSouthwest Land Border 2.87514 0.19810 14.514 < 2e-16 ***
## DemographicSingle Adults 0.02574 0.10980 0.234 0.814699
## CitizenshipCANADA -1.63929 1.11571 -1.469 0.142005
## CitizenshipCHINA, PEOPLES REPUBLIC OF -0.01347 0.35558 -0.038 0.969788
## CitizenshipCOLOMBIA 1.93754 0.29698 6.524 9.87e-11 ***
## CitizenshipCUBA 0.88091 0.29994 2.937 0.003374 **
## CitizenshipECUADOR 2.02482 0.29537 6.855 1.11e-11 ***
## CitizenshipEL SALVADOR 0.97433 0.29263 3.330 0.000895 ***
## CitizenshipGUATEMALA 2.47856 0.29013 8.543 < 2e-16 ***
## CitizenshipHAITI -0.69886 0.34099 -2.050 0.040617 *
## CitizenshipHONDURAS 1.66092 0.29134 5.701 1.48e-08 ***
## CitizenshipINDIA 0.66427 0.35323 1.881 0.060263 .
## CitizenshipMEXICO 3.24392 0.29009 11.182 < 2e-16 ***
## CitizenshipMYANMAR (BURMA) -2.57193 1.90528 -1.350 0.177292
## CitizenshipNICARAGUA 0.66977 0.29766 2.250 0.024615 *
## CitizenshipOTHER 1.79584 0.29358 6.117 1.27e-09 ***
## CitizenshipPERU 1.34507 0.30341 4.433 1.01e-05 ***
## CitizenshipPHILIPPINES -2.08301 0.70477 -2.956 0.003178 **
## CitizenshipRUSSIA -0.45928 0.43138 -1.065 0.287220
## CitizenshipUKRAINE -2.28104 0.55186 -4.133 3.81e-05 ***
## CitizenshipVENEZUELA 1.07825 0.29917 3.604 0.000325 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.892 on 1265 degrees of freedom
## Multiple R-squared: 0.3356, Adjusted R-squared: 0.3245
## F-statistic: 30.42 on 21 and 1265 DF, p-value: < 2.2e-16
plot(residuals(my.model3) ~ fitted(my.model3))
abline(h = 0, col = "red")
title("Residuals vs Fitted")
shapiro.test(residuals(my.model3))
##
## Shapiro-Wilk normality test
##
## data: residuals(my.model3)
## W = 0.9965, p-value = 0.005283
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
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
test <- read_csv("finalProject.csv")
## Rows: 6228 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): Fiscal Year, Month Grouping, Month (abbv), Component, Land Border Region, Area of Responsibility, AOR (Abb...
## dbl (1): Encounter Count
##
## ℹ 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.
test$`Fiscal Year` <- as.factor(test$`Fiscal Year`)
test$`Month Grouping` <- as.factor(test$`Month Grouping`)
test$`Month (abbv)` <- as.factor(test$`Month (abbv)`)
test$Component <- as.factor(test$Component)
test$`Land Border Region` <- as.factor(test$`Land Border Region`)
test$`Area of Responsibility` <- as.factor(test$`Area of Responsibility`)
test$`AOR (Abbv)` <- as.factor(test$`AOR (Abbv)`)
test$Demographic <- as.factor(test$Demographic)
test$Citizenship <- as.factor(test$Citizenship)
test$`Title of Authority` <- as.factor(test$`Title of Authority`)
test$`Encounter Count` <- as.numeric(as.character(test$`Encounter Count`))
##Clustering by region countries
test$Region <- factor(test$Citizenship)
levels(test$Region) <- c(levels(test$Region), "South America")
test$Region[test$Citizenship %in% c("BRAZIL", "COLOMBIA", "ECUADOR", "PERU", "VENEZUELA")] <- "South America"
levels(test$Region) <- c(levels(test$Region), "North America")
test$Region[test$Citizenship %in% c("CANADA")] <- "North America"
levels(test$Region) <- c(levels(test$Region), "Asia")
test$Region[test$Citizenship %in% c("CHINA, PEOPLES REPUBLIC OF", "INDIA", "PHILIPPINES", "MYANMAR (BURMA)")] <- "Asia"
levels(test$Region) <- c(levels(test$Region), "Central America & Caribbean")
test$Region[test$Citizenship %in% c("CUBA", "EL SALVADOR", "GUATEMALA", "HAITI", "HONDURAS", "NICARAGUA", "MEXICO")] <- "Central America & Caribbean"
levels(test$Region) <- c(levels(test$Region), "Europe & Central Asia")
test$Region[test$Citizenship %in% c("ROMANIA", "RUSSIA", "TURKEY", "UKRAINE")] <- "Europe & Central Asia"
levels(test$Region) <- c(levels(test$Region), "Other")
test$Region[test$Citizenship %in% c("OTHER")] <- "Other"
##check assumptions
summary(test$`Encounter Count`)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.0 3.0 13.0 238.8 96.0 25457.0
hist(test$`Encounter Count`, main = "Distribution of Encounter Counts", xlab = "Encounter Count")
boxplot(test$`Encounter Count`, main = "Boxplot for Encounter Counts", ylim = c(0, 300))
##Log transformation
test$Log_Encounter_Count <- log(test$`Encounter Count` + 1)
hist(test$Log_Encounter_Count, main = "Histogram of Log-Transformed Encounter Counts", xlab = "Log(Encounter Count + 1)")
boxplot(test$Log_Encounter_Count, main = "Boxplot for Log-Transformed Encounter Counts")
my.model2 <- lm(log(`Encounter Count` + 1) ~ test$Region + `Land Border Region` + Demographic + `Month (abbv)` + Component, data = test)
summary(my.model2)
##
## Call:
## lm(formula = log(`Encounter Count` + 1) ~ test$Region + `Land Border Region` +
## Demographic + `Month (abbv)` + Component, data = test)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.2173 -1.3455 -0.2612 1.2312 6.0783
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.58579 0.13376 4.380 1.21e-05 ***
## test$RegionNorth America -0.24994 0.13974 -1.789 0.07372 .
## test$RegionAsia 0.54247 0.08230 6.592 4.71e-11 ***
## test$RegionCentral America & Caribbean 0.47190 0.05906 7.990 1.60e-15 ***
## test$RegionEurope & Central Asia -0.18040 0.08141 -2.216 0.02673 *
## test$RegionOther 0.82897 0.09297 8.916 < 2e-16 ***
## `Land Border Region`Other 0.20631 0.06669 3.094 0.00199 **
## `Land Border Region`Southwest Land Border 1.85393 0.06851 27.061 < 2e-16 ***
## DemographicFMUA 1.90611 0.11738 16.239 < 2e-16 ***
## DemographicSingle Adults 1.80408 0.11389 15.840 < 2e-16 ***
## DemographicUC / Single Minors 0.25920 0.13022 1.990 0.04659 *
## `Month (abbv)`FEB -0.12004 0.07238 -1.658 0.09729 .
## `Month (abbv)`JAN -0.13468 0.07275 -1.851 0.06418 .
## `Month (abbv)`NOV -0.03374 0.07243 -0.466 0.64140
## `Month (abbv)`OCT -0.09097 0.07169 -1.269 0.20448
## ComponentU.S. Border Patrol -0.23064 0.05925 -3.893 0.00010 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.812 on 6212 degrees of freedom
## Multiple R-squared: 0.2142, Adjusted R-squared: 0.2123
## F-statistic: 112.9 on 15 and 6212 DF, p-value: < 2.2e-16
plot(residuals(my.model2) ~ fitted(my.model2))
abline(h = 0, col = "red")
title("Residuals vs Fitted")
qqnorm(residuals(my.model2))
qqline(residuals(my.model2), col = "red")
title("Q-Q Plot")
# Cook's distance plot
plot(cooks.distance(my.model2), type = "h", main = "Cook's Distance", ylab = "Cook's Distance")
plot(hatvalues(my.model2), main = "Leverage Plot", xlab = "Observation", ylab = "Leverage")
abline(h = 2 * mean(hatvalues(my.model2)), col = "red")
### GLM
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
my.model.glm <- glm.nb(`Encounter Count` ~ test$Region + `Land Border Region` + Demographic + `Month (abbv)` + Component, data = test)
summary(my.model.glm)
##
## Call:
## glm.nb(formula = `Encounter Count` ~ test$Region + `Land Border Region` +
## Demographic + `Month (abbv)` + Component, data = test, init.theta = 0.3477901492,
## link = log)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.55338 0.12774 4.332 1.48e-05 ***
## test$RegionNorth America 1.01327 0.13131 7.717 1.20e-14 ***
## test$RegionAsia 0.68106 0.07732 8.808 < 2e-16 ***
## test$RegionCentral America & Caribbean 0.89308 0.05545 16.107 < 2e-16 ***
## test$RegionEurope & Central Asia -0.30461 0.07653 -3.980 6.89e-05 ***
## test$RegionOther 1.19198 0.08730 13.653 < 2e-16 ***
## `Land Border Region`Other 0.88105 0.06279 14.032 < 2e-16 ***
## `Land Border Region`Southwest Land Border 2.52209 0.06445 39.129 < 2e-16 ***
## DemographicFMUA 2.84629 0.11229 25.347 < 2e-16 ***
## DemographicSingle Adults 2.98201 0.10913 27.326 < 2e-16 ***
## DemographicUC / Single Minors 0.60464 0.12421 4.868 1.13e-06 ***
## `Month (abbv)`FEB -0.22242 0.06794 -3.274 0.001062 **
## `Month (abbv)`JAN -0.24913 0.06830 -3.648 0.000265 ***
## `Month (abbv)`NOV -0.07942 0.06798 -1.168 0.242716
## `Month (abbv)`OCT -0.10387 0.06728 -1.544 0.122659
## ComponentU.S. Border Patrol -0.03094 0.05558 -0.557 0.577739
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(0.3478) family taken to be 1)
##
## Null deviance: 10826 on 6227 degrees of freedom
## Residual deviance: 8067 on 6212 degrees of freedom
## AIC: 65844
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 0.34779
## Std. Err.: 0.00507
##
## 2 x log-likelihood: -65809.85100