Shootings

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.2.3
Warning: package 'ggplot2' was built under R version 4.2.3
Warning: package 'tibble' was built under R version 4.2.3
Warning: package 'tidyr' was built under R version 4.2.3
Warning: package 'readr' was built under R version 4.2.3
Warning: package 'purrr' was built under R version 4.2.3
Warning: package 'dplyr' was built under R version 4.2.3
Warning: package 'stringr' was built under R version 4.2.3
Warning: package 'forcats' was built under R version 4.2.3
Warning: package 'lubridate' was built under R version 4.2.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.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(pageviews)        # This package gets data on Wikipedia viewing
library(DT)               # DT stands for datatable, and creates interactive tables
Warning: package 'DT' was built under R version 4.2.3
library(infer)            # for some stats like t_test
Warning: package 'infer' was built under R version 4.2.3
library(devtools)
Warning: package 'devtools' was built under R version 4.2.3
Loading required package: usethis
Warning: package 'usethis' was built under R version 4.2.3

Mass Shootings & Gun Control

Below will be a graph of the number of views on the Wikipedia article, “Mass shootings in the United States” from 2017 to 2023:

shootings <- article_pageviews(article = "Mass shootings in the United States", start = as.Date("2017-1-1"), end = as.Date("2023-12-31"))
shootings |> 
  ggplot(aes(x = date, y = views)) +
  geom_line() +
  labs(x = "Views", 
       y = "Year", 
       title = "Views of Mass Shootings in the United States article on Wikipedia")

It seems like there are a few spikes in searches, the largest one being in mid-2022. Here is a similar chart but for the Wikipedia article, “Gun control”:

control <- article_pageviews(article = "Gun control", start = as.Date("2017-1-1"), end = as.Date("2023-12-31"))
control |> 
  ggplot(aes(x = date, y = views)) +
  geom_line() +
  labs(x = "Views", 
       y = "Year", 
       title = "Views of Gun control article on Wikipedia")

The spike is similarly positioned in mid-2022. Here are the two graphs combined:

guns <- bind_rows(shootings, control) 
guns |> 
  ggplot(aes(x = date, y = views, color = article)) +
  geom_line() +
    labs(x = "Views", 
       y = "Year", 
       title = "Views of Gun Control & Mass Shootings articles on Wikipedia")

Here are the scatterplot of the views of each article:

guns |> 
  pivot_wider(names_from = article, values_from = views) |> 
  ggplot(aes(x = Mass_shootings_in_the_United_States, y = Gun_control)) +          # create scatterplot
  geom_point() +
  geom_smooth(method = lm) +                                  # create regression line
  labs(x = "Views of the Wikipedia Mass shootings in the US article", 
       y = "Views of the Wikipedia Gun control article", 
       title = "Relationship between Wikipedia article views")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 2 rows containing non-finite values (`stat_smooth()`).
Warning: Removed 2 rows containing missing values (`geom_point()`).

Shootings in Maine and California

I wanted to find out data on two shootings within the past year that had a high number of deaths, and see whether those shootings made a difference in Wikipedia views. The first shooting I chose was the Lewiston Shooting in Maine, on October 25th, 2023:

top_maine <- top_articles(start = as.Date("2023-10-26"))
top_maine |> 
  select(article, views) |>
  filter(!article == "Main_Page", !article == "Special:Search") |> 
  slice_max(views, n = 10) |> 
  datatable()
top_maine |> 
  select(article, views) |>
  filter(!article == "Main_Page", !article == "Special:Search") |> 
  top_n(10, views) |> 
  ggplot(aes(x = fct_rev(as_factor(article)), y = views)) +
  geom_col(fill = "springgreen") +
  coord_flip() +
  scale_y_continuous(labels = scales::comma) +
  labs(y = "Number of Views", x = "Article", title = "Top Wikipedia articles, Oct. 26, 2023")

The Lewiston Shooting seemed to be quite significant, as it was the top 3 most visited site on Wikipedia that day. Here is the data for another mass shooting in 2023, this time in Monterey Park, California on January 21st:

top_cali <- top_articles(start = as.Date("2023-1-22"))
top_cali |> 
  select(article, views) |>
  filter(!article == "Main_Page", !article == "Special:Search") |> 
  slice_max(views, n = 10) |> 
  datatable()
top_cali |> 
  select(article, views) |>
  filter(!article == "Main_Page", !article == "Special:Search") |> 
  top_n(10, views) |> 
  ggplot(aes(x = fct_rev(as_factor(article)), y = views)) +
  geom_col(fill = "springgreen") +
  coord_flip() +
  scale_y_continuous(labels = scales::comma) +
  labs(y = "Number of Views", x = "Article", title = "Top Wikipedia articles, Jan. 22, 2023")

It seemed like this shooting was not significant. Further digging showed that the event was only in the top 40s two days after it took place.

Views on Gun Control

Perhaps these two shootings would raise more awareness about gun control in the general public. Here is a graph of views on the Gun control Wikipedia article 7 days before and after the Lewiston shooting:

gun_maine <- article_pageviews(article = "Gun_control",
                           start = as.Date("2023-10-18"),
                           end = as.Date("2023-11-1"))

gun_maine <- gun_maine |> 
  mutate(day = -7:7) |> 
  mutate(event = "Maine")

gun_maine |> 
  ggplot(aes(x = day, y = views)) +
  geom_line()

And here is the same graph for the Monterey Park shooting:

gun_cali <- article_pageviews(article = "Gun_control",
                           start = as.Date("2023-1-14"),
                           end = as.Date("2023-1-28"))

gun_cali <- gun_cali |> 
  mutate(day = -7:7) |> 
  mutate(event = "California")

gun_cali |> 
  ggplot(aes(x = day, y = views)) +
  geom_line()

Here is a combination of both graphs:

mass_shootings <- bind_rows(gun_maine, gun_cali)

mass_shootings |> 
  ggplot(aes(x = day, y = views, color = event)) +
  geom_line() +
  theme_minimal() +
  labs(x = "Days before/after Shooting", 
       y = "Wikipedia Views", 
       color = "Event", 
       title = "Views of the Wikipedia Gun Control Article before and after Two Mass Shootings")

There seems to be a spike in views of the Gun control article the days after each shooting. To see whether this result is significant, let’s perform a t-test:

mass_shootings |> 
  mutate(after_event = (day > 0)) |> 
  t_test(views ~ after_event)
Warning: The statistic is based on a difference or ratio; by default, for
difference-based statistics, the explanatory variable is subtracted in the
order "TRUE" - "FALSE", or divided in the order "TRUE" / "FALSE" for
ratio-based statistics. To specify this order yourself, supply `order =
c("TRUE", "FALSE")`.
# A tibble: 1 × 7
  statistic  t_df  p_value alternative estimate lower_ci upper_ci
      <dbl> <dbl>    <dbl> <chr>          <dbl>    <dbl>    <dbl>
1      3.75  27.8 0.000836 two.sided       155.     70.1     239.
mass_shootings |> 
  mutate(after_event = (day > 0)) |> 
  group_by(after_event) |> 
  summarize(Mean = mean(views),
            StdDev = sd(views),
            N = n())
# A tibble: 2 × 4
  after_event  Mean StdDev     N
  <lgl>       <dbl>  <dbl> <int>
1 FALSE        466.   116.    16
2 TRUE         621.   110.    14

The average number of views on the Gun control Wikipedia article 7 days after both shootings (M = 621.07, SD = 110.46) is significantly higher than the 7 days before the shootings (M = 466.31 , SD = 115.63), t(27.8) = 3.75, p < .001.