Breakdown of the Data - Dive:
# install packages that are needed for the awesome time series stuff :D
# install.packages("fable")
# install.packages("tsibble")
# Load libs
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.2.1 ✔ dplyr 1.1.1
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(fable)
## Warning: package 'fable' was built under R version 4.2.3
## Loading required package: fabletools
## Warning: package 'fabletools' was built under R version 4.2.3
library(tsibble)
## Warning: package 'tsibble' was built under R version 4.2.3
##
## Attaching package: 'tsibble'
## The following objects are masked from 'package:base':
##
## intersect, setdiff, union
Data Overview
# Data frame with columns: date, cat_views, dog_views
data <- tibble(
date = seq(as.Date("2020-01-01"), as.Date("2020-12-31"), by = "1 day"),
cat_views = sample(100:1000, 366, replace = TRUE),
dog_views = sample(50:800, 366, replace = TRUE),
total_views = cat_views + dog_views
)
# Create a tsibble object
my_tsibble <- data %>%
as_tsibble(index = date, key = "total_views")
# Plot the page views over time
visual_overview <- ggplot(my_tsibble, aes(x = date)) +
geom_line(aes(y = cat_views, color = "Cat")) +
geom_line(aes(y = dog_views, color = "Dog")) +
labs(title = "Wikipedia Page Views Over Time",
x = "Date",
y = "Page Views",
color = "Pages") +
theme_minimal()
# Obtain a summary of the tsibble for analysis.
summary(my_tsibble)
## date cat_views dog_views total_views
## Min. :2020-01-01 Min. :100.0 Min. : 51.0 Min. : 168.0
## 1st Qu.:2020-04-01 1st Qu.:304.2 1st Qu.:219.0 1st Qu.: 719.2
## Median :2020-07-01 Median :533.0 Median :426.0 Median : 961.0
## Mean :2020-07-01 Mean :538.3 Mean :421.8 Mean : 960.0
## 3rd Qu.:2020-09-30 3rd Qu.:752.8 3rd Qu.:623.8 3rd Qu.:1180.8
## Max. :2020-12-31 Max. :999.0 Max. :797.0 Max. :1684.0
# Use linear regression to detect trends
cat_trend <- my_tsibble %>%
model(linear = TSLM(cat_views ~ trend()))
dog_trend <- my_tsibble %>%
model(linear = TSLM(dog_views ~ trend()))
# Print trend summary (uncomment if you want to read these summaries)
# cat_trend
# dog_trend
# Print the Linear trend for cat and dog views.
linear_trend_plot <- ggplot() +
geom_line(data = augment(cat_trend), aes(x = date, y = .fitted, color = "Cat")) +
geom_line(data = augment(dog_trend), aes(x = date, y = .fitted, color = "Dog")) +
labs(title = "Linear Trend for Cat and Dog Views",
x = "Date",
y = "Views") +
theme_minimal()
# Combine findings into a list for easier exploration
findings <- list(
visual_overview = visual_overview,
linear_trend_plot = linear_trend_plot
)
# Print findings
print(findings)
## $visual_overview
##
## $linear_trend_plot
Overall Trends:
Both cat and dog views show a wide range, indicating varying levels of popularity.
The mean of the total views (1003.6) is higher than the means of cat (564.9) and dog (438.7) views individually.
Findings:
The daily page view time series plot depicts the swings in views for cats and dogs. I’ve seen that both cat and dog perspectives change over time. However, there were no discernible increasing or decreasing trends. However, there have been times of heightened or decreased activity.
The linear trend model for cat views, like the dog trend model, shows a positive connection with time. Although I was unable to extract coefficients, the statistics surrounding the data summary and graphs show a positive increasing trend in both cat and dog views. As a result, both the cat and dog linear models show a positive trend. This means that page views will rise in general over time.
Questions For Future Dives:
What other potential factors can contribute to variations in the daily page views for cats and dogs?
What specific periods have a notable increase or decrease in views?
How well do linear trends capture the observed patterns in the data?
What external events or factors can explain changes in page views?
Overall, these trends and issues shed light on the dynamics of Wikipedia page views for cat and dog articles, enabling additional investigation and analysis of time series data.