library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.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
k12 <- read_csv("Violence Project - K-12 SCHOOLS DATABASE 2026 - Event.csv")
## Rows: 398 Columns: 58
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (46): Full Date, Day of Week, Time of Day, During Class?, School Name, ...
## dbl  (10): ID #, Month, Day, Year, Latitude, Longitude, Number of
## Victims Ki...
## num   (1): Enrollment
## time  (1): Time Homicide
## Occurred
## 
## ℹ 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.
higher_ed <- read_csv("Violence Project - HIGHER ED DATABASE 2026 - Event.csv")
## Rows: 280 Columns: 60
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (48): Full Date, Day of Week, Time of Day, During Class?, School Name, ...
## dbl  (10): ID #, Month, Day, Year, Latitude, Longitude, Number of
## Victims Ki...
## num   (1): Enrollment
## time  (1): Time Homicide
## Occurred
## 
## ℹ 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.
View(k12)
View(higher_ed)
k12 <- k12 %>%
  mutate(School_Type_Group = "K-12")

higher_ed <- higher_ed %>%
  mutate(School_Type_Group = "Higher Ed")
View(k12)
View(higher_ed)
# Columns found only in K-12
setdiff(names(k12), names(higher_ed))
## [1] "School Level"
# Columns found only in higher education
setdiff(names(higher_ed), names(k12))
## [1] "School Type"             "Endowment (in millions)"
## [3] "HBCU"
all_shootings <- bind_rows(k12, higher_ed)
library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
all_shootings <- all_shootings %>%
  clean_names()
names(all_shootings)
##  [1] "id_number"                                        
##  [2] "full_date"                                        
##  [3] "month"                                            
##  [4] "day"                                              
##  [5] "year"                                             
##  [6] "day_of_week"                                      
##  [7] "time_of_day"                                      
##  [8] "time_homicide_occurred"                           
##  [9] "during_class"                                     
## [10] "school_name"                                      
## [11] "address"                                          
## [12] "city"                                             
## [13] "state"                                            
## [14] "zip_code"                                         
## [15] "density"                                          
## [16] "latitude"                                         
## [17] "longitude"                                        
## [18] "industry_type_of_business"                        
## [19] "school_level"                                     
## [20] "number_of_employees_at_site"                      
## [21] "enrollment"                                       
## [22] "accessibility_to_public"                          
## [23] "gun_free_zone"                                    
## [24] "security_systems"                                 
## [25] "lockdown"                                         
## [26] "how_perpetrator_accessed"                         
## [27] "armed_person_on_scene"                            
## [28] "location_of_homicide"                             
## [29] "location_of_homicide_specify"                     
## [30] "number_of_victims_killed"                         
## [31] "number_of_victims_injured"                        
## [32] "number_of_shooting_injuries"                      
## [33] "number_of_other_injuries"                         
## [34] "students_killed"                                  
## [35] "staff_killed"                                     
## [36] "students_injured"                                 
## [37] "staff_injured"                                    
## [38] "hostages"                                         
## [39] "weapon_used"                                      
## [40] "how_was_weapon_obtained"                          
## [41] "when_was_weapon_obtained"                         
## [42] "other_weapons"                                    
## [43] "preplanned"                                       
## [44] "degree_of_planning"                               
## [45] "inspired_by_or_studied_other_perpetrators"        
## [46] "inspired_by_or_studied_other_perpetrators_specify"
## [47] "connected_to_another_homicide"                    
## [48] "connected_to_another_homicide_specify"            
## [49] "active_shooter"                                   
## [50] "gang_group_related"                               
## [51] "drive_by"                                         
## [52] "domestic"                                         
## [53] "situation"                                        
## [54] "on_scene_outcome"                                 
## [55] "conviction_outcome"                               
## [56] "short_summary"                                    
## [57] "full_description"                                 
## [58] "articles"                                         
## [59] "school_type_group"                                
## [60] "school_type"                                      
## [61] "endowment_in_millions"                            
## [62] "hbcu"
table(all_shootings$school_type_group)
## 
## Higher Ed      K-12 
##       280       398
glimpse(all_shootings)
## Rows: 678
## Columns: 62
## $ id_number                                         <dbl> 1, 2, 3, 4, 5, 6, 7,…
## $ full_date                                         <chr> "01/19/2000", "02/29…
## $ month                                             <dbl> 1, 2, 3, 5, 5, 5, 7,…
## $ day                                               <dbl> 19, 29, 10, 5, 10, 2…
## $ year                                              <dbl> 2000, 2000, 2000, 20…
## $ day_of_week                                       <chr> "Wednesday", "Tuesda…
## $ time_of_day                                       <chr> "Afternoon", "Mornin…
## $ time_homicide_occurred                            <time> 14:13:00, 10:00:00,…
## $ during_class                                      <chr> "No evidence of", "Y…
## $ school_name                                       <chr> "Ridgewood High Scho…
## $ address                                           <chr> "7650 Orchid Lake Rd…
## $ city                                              <chr> "New Port Richey", "…
## $ state                                             <chr> "FL", "MI", "GA", "C…
## $ zip_code                                          <chr> "34653", "48505", "3…
## $ density                                           <chr> "Suburban", "Urban",…
## $ latitude                                          <dbl> 28.27111, 43.00643, …
## $ longitude                                         <dbl> -82.68698, -83.66535…
## $ industry_type_of_business                         <chr> "Educational Institu…
## $ school_level                                      <chr> "High", "Elementary"…
## $ number_of_employees_at_site                       <chr> "51-150", "Unknown",…
## $ enrollment                                        <dbl> 1604, NA, 904, 1412,…
## $ accessibility_to_public                           <chr> "Publicly Accessible…
## $ gun_free_zone                                     <chr> "Yes", "Yes", "Yes",…
## $ security_systems                                  <chr> "School deputy on si…
## $ lockdown                                          <chr> "No evidence of", "N…
## $ how_perpetrator_accessed                          <chr> "No Access Restricti…
## $ armed_person_on_scene                             <chr> "Yes", "No evidence …
## $ location_of_homicide                              <chr> "Outside", "Inside",…
## $ location_of_homicide_specify                      <chr> "Parking Lot", "Comm…
## $ number_of_victims_killed                          <dbl> 1, 1, 2, 1, 1, 1, 2,…
## $ number_of_victims_injured                         <dbl> 0, 0, 1, 1, 0, 0, 0,…
## $ number_of_shooting_injuries                       <dbl> 0, 0, 1, 0, 0, 0, 0,…
## $ number_of_other_injuries                          <dbl> 0, 0, 0, 1, 0, 0, 0,…
## $ students_killed                                   <chr> "Yes", "Yes", "Yes",…
## $ staff_killed                                      <chr> "No evidence of", "N…
## $ students_injured                                  <chr> "No evidence of", "N…
## $ staff_injured                                     <chr> "No evidence of", "N…
## $ hostages                                          <chr> "No evidence of", "N…
## $ weapon_used                                       <chr> "Handgun", "Handgun"…
## $ how_was_weapon_obtained                           <chr> "Stolen", "Stolen", …
## $ when_was_weapon_obtained                          <chr> "0 - 6 months prior"…
## $ other_weapons                                     <chr> NA, "Knife", NA, NA,…
## $ preplanned                                        <chr> "No evidence of", "N…
## $ degree_of_planning                                <chr> NA, NA, NA, NA, NA, …
## $ inspired_by_or_studied_other_perpetrators         <chr> "No evidence of", "N…
## $ inspired_by_or_studied_other_perpetrators_specify <chr> NA, NA, NA, NA, NA, …
## $ connected_to_another_homicide                     <chr> "No evidence of", "N…
## $ connected_to_another_homicide_specify             <chr> NA, NA, NA, NA, NA, …
## $ active_shooter                                    <chr> "No evidence of", "N…
## $ gang_group_related                                <chr> "No evidence of", "N…
## $ drive_by                                          <chr> "No evidence of", "N…
## $ domestic                                          <chr> "No evidence of", "N…
## $ situation                                         <chr> "Accident/Negligence…
## $ on_scene_outcome                                  <chr> "Arrested on Scene",…
## $ conviction_outcome                                <chr> "Manslaughter by Cul…
## $ short_summary                                     <chr> "Student shot throug…
## $ full_description                                  <chr> "On Wednesday, Janua…
## $ articles                                          <chr> "https://www.tampaba…
## $ school_type_group                                 <chr> "K-12", "K-12", "K-1…
## $ school_type                                       <chr> NA, NA, NA, NA, NA, …
## $ endowment_in_millions                             <chr> NA, NA, NA, NA, NA, …
## $ hbcu                                              <chr> NA, NA, NA, NA, NA, …
class(all_shootings$number_of_victims_killed)
## [1] "numeric"
summary(all_shootings$number_of_victims_killed)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   1.000   1.000   1.326   1.000  32.000
table(all_shootings$number_of_victims_killed)
## 
##   1   2   3   4   5   6   9  10  17  21  26  32 
## 604  44  14   5   3   1   2   1   1   1   1   1
 # Select some variables of interest and see if there is any obvious correlations using the COR command
cor(
  all_shootings$enrollment,
  all_shootings$number_of_victims_killed,
  use = "complete.obs"
)
## [1] 0.03349962
# Near 1 means a strong relationship, and near 0 means no relationship

This information shows us that there is not a strong correlation between the size of the school and the number of fatalities. Essentially, larger schools typically do not experience more fatalities than smaller schools.

table(all_shootings$day_of_week)
## 
##    Friday    Monday  Saturday    Sunday  Thursday   Tuesday Wednesday 
##       129       100        71        73       102        98       105
# one of the scholarly aricles I was reading says that shootings have gotten more deadly over time. Let's run a correlation to see if that may be true
# A positive result indicates higher fatalities per incident over time; a negative result indicates the opposite.

cor(
  all_shootings$year,
  all_shootings$number_of_victims_killed,
  use = "complete.obs"
)
## [1] -0.01116037

The negative result above shows us that the number of fatalities at each incident have decreased over time.

# Examine the same variables visually using the PAIRS command
pairs(all_shootings[, c("enrollment", "year", "number_of_victims_killed")])

# Select two variables that seem correlated (positively or negatively) and examine them using PEARSON, SPEARMAN or KENDALL (depending on which is more appropriate)

#I want to measure the relationship between the number of victims injured and the number of victims killed

names(all_shootings)[grepl("injur", names(all_shootings))]
## [1] "number_of_victims_injured"   "number_of_shooting_injuries"
## [3] "number_of_other_injuries"    "students_injured"           
## [5] "staff_injured"
# first, we have to check and see if these values are considered numbers/numeric so we can compare them

class(all_shootings$number_of_victims_injured)
## [1] "numeric"
cor.test(all_shootings$number_of_victims_injured, all_shootings$number_of_victims_killed, method = "spearman", exact = FALSE)
## 
##  Spearman's rank correlation rho
## 
## data:  all_shootings$number_of_victims_injured and all_shootings$number_of_victims_killed
## S = 34663260, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.3326825

Spearman’s correlation is 0.33 which shows us that school homicide incidents involving more injuries tend to also involve more fatalities.

I used Spearman’s correlation because my data is very heavily skewed since most events only had one death and a few involved significantly more fatalities. The results show a small positive correlation (ρ = 0.333, p < .001) which communicates to me that incidents with more injuries tended to have more fatalities.