Importing Libraries

library(readr)
library(dplyr)
library(RColorBrewer)
library(ggplot2)
library(texreg)

Importing & Fixing Data

guns <- read_csv("/Users/rachel_ramphal/Documents/Data Sets/guns.csv") %>%
    select(year, intent, police, sex, age, race, education) %>%

    mutate(intent = ifelse(intent == "Suicide", 0,
                    ifelse(intent == "Homicide", 1, 2)))

Descriptive Analysis

graph1 <- guns %>%
  group_by(race, intent) %>%
   summarize(n=n()) %>%
    mutate(percent=n/sum(n)) %>%
  
  ggplot() + 
  geom_col(aes(y = percent, x = race, fill = intent)) +
  scale_fill_gradient(low = "purple2", high = "darkturquoise") +
  labs(title = "Type of Gun Related Death by Race", x = "Race", y = "Percent") +
  theme(plot.title = element_text(face = "bold", hjust = 0.5, color = "slateblue3")) 

Regression Analysis

Models for Suicide
suicide <- guns %>%
  filter(intent == 0)
model4 <- glm(intent ~ sex, family = "binomial", data = suicide)

model5 <- glm(intent ~ sex + race, family = "binomial", data = suicide)

model6 <- glm(intent ~ sex + race + age, family = "binomial", data = suicide)
#AIC vs BIC
htmlreg(list(model4, model5, model6), doctype = FALSE)
#Selecting best model 
htmlreg(list(model6), doctype = FALSE)