# these are the commands I need to load to concatenate my datasets, clean them, and make them ready to use

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
library(janitor)
## 
## Attaching package: 'janitor'
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
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.
k12 <- k12 %>%
  mutate(School_Type_Group = "K-12")

higher_ed <- higher_ed %>%
  mutate(School_Type_Group = "Higher Ed")

all_shootings <- bind_rows(k12, higher_ed)

all_shootings <- all_shootings %>%
  clean_names()

View(all_shootings)
table(all_shootings$school_type_group)
## 
## Higher Ed      K-12 
##       280       398
table(all_shootings$armed_person_on_scene)
## 
## No evidence of            Yes 
##            628             50
table(all_shootings$accessibility_to_public)
## 
##                     Publicly Accessible Restricted Space and Didn't Have Access 
##                                     489                                      28 
##         Restricted Space but Had Access                                 Unknown 
##                                     157                                       4
# 2) Select the dependent variable you are interested in, along with independent variables which you believe are causing the dependent variable. 

# I want to look at these: school_type_group, armed_person_on_scene, accessibility_to_public    

# here I try to find the average of each 

aggregate(number_of_victims_killed ~ school_type_group,
          data = all_shootings, FUN = mean)
##   school_type_group number_of_victims_killed
## 1         Higher Ed                 1.321429
## 2              K-12                 1.329146
# 3) create a linear model using the "lm()" command, save it to some object

model1 <- lm(number_of_victims_killed ~ school_type_group, data=all_shootings)

# 4) call a "summary()" on your new model
summary(model1)
## 
## Call:
## lm(formula = number_of_victims_killed ~ school_type_group, data = all_shootings)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.3291 -0.3291 -0.3291 -0.3214 30.6786 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           1.321429   0.117133   11.28   <2e-16 ***
## school_type_groupK-12 0.007717   0.152881    0.05     0.96    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.96 on 676 degrees of freedom
## Multiple R-squared:  3.769e-06,  Adjusted R-squared:  -0.001476 
## F-statistic: 0.002548 on 1 and 676 DF,  p-value: 0.9598
# Below 0.05: Statistically significant relationship.
# Above 0.05: Not statistically significant.

The P-value is 0.96 which means it is not statistically significant. School type is not associated with number of fatalities.

My R-squared is essentially zero which means school type explains almost none of the variation in fatalities.

# Now I will examine if accessibility to te public has an impact on our dependent variable, fatalities. 

model2 <- lm(number_of_victims_killed ~ accessibility_to_public, data=all_shootings)
summary(model2)
## 
## Call:
## lm(formula = number_of_victims_killed ~ accessibility_to_public, 
##     data = all_shootings)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.3571 -0.1677 -0.1677 -0.1677 30.5350 
## 
## Coefficients:
##                                                                Estimate
## (Intercept)                                                     1.16769
## accessibility_to_publicRestricted Space and Didn't Have Access  2.18945
## accessibility_to_publicRestricted Space but Had Access          0.29728
## accessibility_to_publicUnknown                                 -0.16769
##                                                                Std. Error
## (Intercept)                                                       0.08649
## accessibility_to_publicRestricted Space and Didn't Have Access    0.37167
## accessibility_to_publicRestricted Space but Had Access            0.17545
## accessibility_to_publicUnknown                                    0.96025
##                                                                t value Pr(>|t|)
## (Intercept)                                                     13.500  < 2e-16
## accessibility_to_publicRestricted Space and Didn't Have Access   5.891 6.06e-09
## accessibility_to_publicRestricted Space but Had Access           1.694   0.0907
## accessibility_to_publicUnknown                                  -0.175   0.8614
##                                                                   
## (Intercept)                                                    ***
## accessibility_to_publicRestricted Space and Didn't Have Access ***
## accessibility_to_publicRestricted Space but Had Access         .  
## accessibility_to_publicUnknown                                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.913 on 674 degrees of freedom
## Multiple R-squared:  0.05053,    Adjusted R-squared:  0.04631 
## F-statistic: 11.96 on 3 and 674 DF,  p-value: 1.233e-07

My p-value is 1.23e-07 which is really .00000012 which means there IS a statistically significant relationship. I’m pretty confused so I looked this up, and it says R squared tells us “How much does school accessibility help us understand why some shootings have more fatalities than others?” My r-squared value is 0.05 which is 5% which means school accessibility explains about 5% of the differences in fatalities across events. In conclusion, our P-value tells us that school accessibility is related to fatalities, but our R-squared value tells us school accessibility alone doesn’t really predict or explain how deadly a shooting will be. When I think about it, there are other factors that may be playing a role like the type of weapon used, whether there was an armed person on campus, and more.

Question 6: 6) Choose some significant independent variables. Interpret its Estimates (or Beta Coefficients). How do the independent variables individually affect the dependent variable?

My results show that school accessibility has a significant relationship with the number of fatalities in a very surprising way. Shootings that occurred in restricted spaces where the shooter did not have authorized access averaged 2.19 more deaths than shootings in publicly accessible locations! This suggests that shootings in certain restricted spaces tend to have more fatalities.

# 7) Does the model you create meet or violate the assumption of linearity? Show your work with "plot(x,which=1)

plot(model2, which=1)

The red line on my graph is flat because I am comparing catagories of schools- closed, accessible, restricted areas. So, the linearity assumption does not apply in the usual way.

I’m pretty confused, and wondering if this dataset is even good for this class because so many of my instances are just one. But it was almost impossible to find data for this class. I hope this is good enough.