── 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.0
✔ 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 viewinglibrary(DT) # DT stands for datatable, and creates interactive tableslibrary(infer) # for some stats like t_testlibrary(devtools)
Loading required package: usethis
mass_shootings <-article_pageviews(article ="Mass shootings in the United States", start =as.Date("2017-01-01"), end =as.Date("2023-12-31"))glimpse(mass_shootings)
gun_control |>ggplot(aes(x = date, y = views)) +geom_line()
mass <-bind_rows(gun_control, mass_shootings)
1.
mass |>ggplot(aes(x = date, y = views, color = article)) +geom_line()
Here you can see that the mass shootings article received a lot more views than the gun control article but that the views on each seem to increase at the same time.
mass |>pivot_wider(names_from = article, values_from = views)
# A tibble: 2,556 × 8
project language access agent granularity date Gun_control
<chr> <chr> <chr> <chr> <chr> <dttm> <dbl>
1 wikipedia en all-acc… all-… daily 2017-01-01 00:00:00 285
2 wikipedia en all-acc… all-… daily 2017-01-02 00:00:00 393
3 wikipedia en all-acc… all-… daily 2017-01-03 00:00:00 434
4 wikipedia en all-acc… all-… daily 2017-01-04 00:00:00 544
5 wikipedia en all-acc… all-… daily 2017-01-05 00:00:00 635
6 wikipedia en all-acc… all-… daily 2017-01-06 00:00:00 620
7 wikipedia en all-acc… all-… daily 2017-01-07 00:00:00 431
8 wikipedia en all-acc… all-… daily 2017-01-08 00:00:00 464
9 wikipedia en all-acc… all-… daily 2017-01-09 00:00:00 610
10 wikipedia en all-acc… all-… daily 2017-01-10 00:00:00 595
# ℹ 2,546 more rows
# ℹ 1 more variable: Mass_shootings_in_the_United_States <dbl>
2.
mass |>pivot_wider(names_from = article, values_from = views)|>ggplot(aes(x = Mass_shootings_in_the_United_States, y = Gun_control))+geom_point()+geom_smooth(method = lm) +# create regression linelabs(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")
shootings <-bind_rows(lasvegas, Lewistown)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")
You can see here the Las Vegas shooting received a lot more views than the other shooting.
shootings |>mutate(after_event = (day >0))
project language article access agent granularity date
1 wikipedia en Gun_control all-access all-agents daily 2017-09-26
2 wikipedia en Gun_control all-access all-agents daily 2017-09-27
3 wikipedia en Gun_control all-access all-agents daily 2017-09-28
4 wikipedia en Gun_control all-access all-agents daily 2017-09-29
5 wikipedia en Gun_control all-access all-agents daily 2017-09-30
6 wikipedia en Gun_control all-access all-agents daily 2017-10-01
7 wikipedia en Gun_control all-access all-agents daily 2017-10-02
8 wikipedia en Gun_control all-access all-agents daily 2017-10-03
9 wikipedia en Gun_control all-access all-agents daily 2017-10-04
10 wikipedia en Gun_control all-access all-agents daily 2017-10-05
11 wikipedia en Gun_control all-access all-agents daily 2017-10-06
12 wikipedia en Gun_control all-access all-agents daily 2017-10-07
13 wikipedia en Gun_control all-access all-agents daily 2017-10-08
14 wikipedia en Gun_control all-access all-agents daily 2017-10-09
15 wikipedia en Gun_control all-access all-agents daily 2017-10-10
16 wikipedia en Gun_control all-access all-agents daily 2023-10-18
17 wikipedia en Gun_control all-access all-agents daily 2023-10-19
18 wikipedia en Gun_control all-access all-agents daily 2023-10-20
19 wikipedia en Gun_control all-access all-agents daily 2023-10-21
20 wikipedia en Gun_control all-access all-agents daily 2023-10-22
21 wikipedia en Gun_control all-access all-agents daily 2023-10-23
22 wikipedia en Gun_control all-access all-agents daily 2023-10-24
23 wikipedia en Gun_control all-access all-agents daily 2023-10-25
24 wikipedia en Gun_control all-access all-agents daily 2023-10-26
25 wikipedia en Gun_control all-access all-agents daily 2023-10-27
26 wikipedia en Gun_control all-access all-agents daily 2023-10-28
27 wikipedia en Gun_control all-access all-agents daily 2023-10-29
28 wikipedia en Gun_control all-access all-agents daily 2023-10-30
29 wikipedia en Gun_control all-access all-agents daily 2023-10-31
30 wikipedia en Gun_control all-access all-agents daily 2023-11-01
views day event after_event
1 486 -7 Las vegas FALSE
2 450 -6 Las vegas FALSE
3 423 -5 Las vegas FALSE
4 399 -4 Las vegas FALSE
5 284 -3 Las vegas FALSE
6 317 -2 Las vegas FALSE
7 3554 -1 Las vegas FALSE
8 4342 0 Las vegas FALSE
9 3469 1 Las vegas TRUE
10 2838 2 Las vegas TRUE
11 1966 3 Las vegas TRUE
12 1189 4 Las vegas TRUE
13 1221 5 Las vegas TRUE
14 1713 6 Las vegas TRUE
15 1476 7 Las vegas TRUE
16 350 -7 Lewistown FALSE
17 357 -6 Lewistown FALSE
18 358 -5 Lewistown FALSE
19 333 -4 Lewistown FALSE
20 351 -3 Lewistown FALSE
21 417 -2 Lewistown FALSE
22 492 -1 Lewistown FALSE
23 548 0 Lewistown FALSE
24 778 1 Lewistown TRUE
25 651 2 Lewistown TRUE
26 484 3 Lewistown TRUE
27 553 4 Lewistown TRUE
28 620 5 Lewistown TRUE
29 524 6 Lewistown TRUE
30 559 7 Lewistown TRUE
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: 2 × 4
after_event Mean StdDev N
<lgl> <dbl> <dbl> <int>
1 FALSE 841. 1223. 16
2 TRUE 1289. 931. 14
The average number of views of the Wikipedia Gun Control article in the 7 days prior to the two shootings (M = 841.3, SD = 1223.3) was not statistically significantly different from the average number of views in the 7 days after the shooting (M = 1288.6, SD = 930.8), t(27.5) = 1.13, p = .266.