library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.0     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.1     ✔ tibble    3.1.8
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(ggplot2)
library(dplyr)
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.2.3
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.2.3
library(effsize)
## Warning: package 'effsize' was built under R version 4.2.3
library(pwrss)
## Warning: package 'pwrss' was built under R version 4.2.3
## 
## Attaching package: 'pwrss'
## 
## The following object is masked from 'package:stats':
## 
##     power.t.test
library(boot)
library(broom)
library(lindia)
## Warning: package 'lindia' was built under R version 4.2.3
library(vcd)
## Warning: package 'vcd' was built under R version 4.2.3
## Loading required package: grid
# time series toolkits
library(xts)
## Warning: package 'xts' was built under R version 4.2.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.2.3
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
library(tsibble)
## Warning: package 'tsibble' was built under R version 4.2.3
## 
## Attaching package: 'tsibble'
## 
## The following object is masked from 'package:zoo':
## 
##     index
## 
## The following object is masked from 'package:lubridate':
## 
##     interval
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, union
library(wikipediatrend)
## Warning: package 'wikipediatrend' was built under R version 4.2.3
## 
##   [wikipediatrend]
##     
##   Note:
##     
##     - Data before 2016-01-01 
##       * is provided by petermeissner.de and
##       * was prepared in a project commissioned by the Hertie School of Governance (Prof. Dr. Simon Munzert)
##       * and supported by the Daimler and Benz Foundation.
##     
##     - Data from 2016-01-01 onwards 
##       * is provided by the Wikipedia Foundation
##       * via its pageviews package and API.
## 

Time-based column of data

Since my dataset does not have a column that encodes time, I will extract a time series of page views of the diamond page on wikipedia.

diamond <- wpd_get_exact(page="Diamond", 
                      from="2008-01-01", 
                      to="2009-01-01", 
                      lang="en", 
                      warn=TRUE)

diamond <- select(diamond, date, views)
diamond <- as_tsibble(diamond, index = date)
diamond |>
  ggplot() +
  geom_line(mapping = aes(x = date, y = views)) +
  labs(title = '"Diamond" Page Views on Wikipedia') +
  theme_hc()

Something that stood out immediately to me are the peak of almost 12500 views somewhere in 2008 and there are time periods where there is 0 view.

diamond |>
  filter_index("2008" ~ "2009") |>
  drop_na() |>
  ggplot(mapping = aes(x = date, y = views)) +
  geom_point(size=1, shape='O') +
  geom_smooth(span=0.2, color = 'blue', se=FALSE) +
  labs(title = "Diamond") +
  theme_hc()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Here I used LOWESS to plot a weighted linear model to identify trends in the data. The views count is relatively constant from January to around mid September and experienced a steep upwards trend until around December and experienced a steep downwards trend in January 2009. The two major trends in the data are pretty strong compare to the small changes.

acf(diamond, ci = 0.95, na.action = na.exclude)