install.packages("pageviews_0.5.0.tar", repos =NULL, type ="source")
Installing package into 'C:/Users/msubstudent/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
Warning in install.packages("pageviews_0.5.0.tar", repos = NULL, type =
"source"): installation of package 'pageviews_0.5.0.tar' had non-zero exit
status
library(tidyverse)
── 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
devtools::install_github("ironholds/pageviews")
Skipping install of 'pageviews' from a github remote, the SHA1 (d32c629c) has not changed since last install.
Use `force = TRUE` to force installation
gun_control <-article_pageviews(article ="Gun control", start =as.Date("2017-1-1"), end =as.Date("2023-12-31"))glimpse(gun_control)
Las_Vegas_shooting <-article_pageviews(article ="2017 Las Vegas shooting", start =as.Date("2017-1-1"), end =as.Date("2023-12-31"))glimpse(Las_Vegas_shooting)
project language article access agent granularity date
1 wikipedia en Gun_control all-access all-agents daily 2022-05-25
2 wikipedia en Gun_control all-access all-agents daily 2018-02-16
3 wikipedia en Gun_control all-access all-agents daily 2018-02-15
4 wikipedia en Gun_control all-access all-agents daily 2022-05-26
5 wikipedia en Gun_control all-access all-agents daily 2018-02-22
6 wikipedia en Gun_control all-access all-agents daily 2017-10-03
7 wikipedia en Gun_control all-access all-agents daily 2018-02-20
8 wikipedia en Gun_control all-access all-agents daily 2018-02-19
9 wikipedia en Gun_control all-access all-agents daily 2018-02-21
10 wikipedia en Gun_control all-access all-agents daily 2018-02-18
views
1 9666
2 6549
3 6117
4 5587
5 5142
6 4342
7 4233
8 4229
9 3914
10 3760
Mass_shootings_in_the_United_States <-article_pageviews(article ="Mass shootings in the United States", start =as.Date("2017-1-1"), end =as.Date("2023-12-31"))glimpse(Mass_shootings_in_the_United_States)
Mass_shootings_in_the_United_States |>ggplot(aes(x = date, y = views)) +geom_line()
gun_control |>ggplot(aes(x = date, y = views)) +geom_line()
gun_Mass |>ggplot(aes(x = date, y = views, color = article)) +geom_line()
gun_Mass |>pivot_wider(names_from = article, values_from = views) |>ggplot(aes(x = Mass_shootings_in_the_United_States, y = Gun_control)) +# create scatterplotgeom_point() +geom_smooth(method = lm) +# create regression linelabs(x ="Views of the Wikipedia Mass shootings in the United States article", y ="Views of the Wikipedia Gun control article", title ="Relationship between Wikipedia article views")
shootings <-bind_rows(Las_Vegas_shooting, Fresno_shootings)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")
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 459. 119. 30
2 TRUE 1237. 1065. 28
The average number of views of the Wikipedia Gun Control article in the 7 days prior to the two shootings (M = 458.7, SD = 118.57) was statistically significant and different from the average number of views in the 7 days after the shooting (M = 1236.7, SD = 1065.25), t(27.6) = 3.84, p < .001.