library(ggplot2)
library(dplyr)

# Prettier graphs
theme_set(theme_bw())

Question 1

This question is Question 4.2 from the textbook and has been reproduced here along with R code to create the table. Use R and the appropriate functions from the table lab for your answers.

Nine-hundred and ten (910) randomly sampled registered voters from Tampa, FL were asked if they thought workers who have illegally entered the US should be (i) allowed to keep their jobs and apply for US citizenship, (ii) allowed to keep their jobs as temporary guest workers but not allowed to apply for US citizenship, or (iii) lose their jobs and have to leave the country. The results of the survey by political ideology are shown below.

## Copy and run this code to create table
tab <- structure(c(57L, 121L, 179L, 15L, 101L, 28L, 45L, 1L, 120L, 113L, 
126L, 4L), dim = 4:3, dimnames = list(response = c("Apply for citizenship", 
"Guest worker", "Leave the country", "Not sure"), political = c("conservative", 
"liberal", "moderate")), class = "table")

tab
##                        political
## response                conservative liberal moderate
##   Apply for citizenship           57     101      120
##   Guest worker                   121      28      113
##   Leave the country              179      45      126
##   Not sure                        15       1        4
  1. What percent of these Tampa, FL voters identify themselves as conservatives?

  2. What percent of these Tampa, FL voters are in favor of the citizenship option?

  3. What percent of these Tampa, FL voters identify themselves as conservatives and are in favor of the citizenship option?

  4. What percent of these Tampa, FL voters who identify themselves as conservatives are also in favor of the citizenship option? What percent of moderates share this view? What percent of liberals share this view?

  5. Do political ideology and views on immigration appear to be associated? Explain your reasoning.

Question 2

This question uses police shooting data aggregated by the Washington Post documenting all fatal shootings by a police officer between 2015-2022.

A dictionary of terms used can be found here

# Copy and paste these lines to load data
police <- read.csv("https://remiller1450.github.io/data/Police.csv")

# Clean data for problem by selecting relevant 
# columns and removing missing values
police <- police[, c(3,4,5,6,9,10,11,12,13,17)]

police <- police[complete.cases(police) & 
                   police$flee != "" &
                   police$gender != "", ]
  1. Which five states had the greatest number of shootings between 2015-2022?

  2. Below is a plot demonstrating the relationship between whether or not a body camera was being used during the shooting and whether the assailant was either shot or both shot and tasered. Create the table associated with this plot, find the odds of being shot vs shot and tasered and determine from the ratio of these odds whether or not the two variables appear to be associated.

  1. Next, we present a table showing the threat level of the assailant (“attack” is considered the highest level of threat, followed by “other” and then “undetermined”). What variable is being conditioned on, and what conclusions could we draw from this table? Create the plot associated with this table
shot shot and Tasered
attack 0.65366 0.49191
other 0.32165 0.49515
undetermined 0.02469 0.01294
  1. For this final part, we are interested in asking the question of whether or not the total number of shootings that include body cameras has increased or decreased throughout the years. First create a bar chart showing the number of fatal shootings that occurred each year and then create a second plot which includes the variable for body camera. What do we see in the first plot, and how does this relate to what we see in the second plot?