# Load required libraries
library(tsibble)
##
## Attaching package: 'tsibble'
## The following objects are masked from 'package:base':
##
## intersect, setdiff, union
library(ggplot2)
library(fable)
## Loading required package: fabletools
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
# Read data from CSV file
your_data <- read.csv("wikipedia_pageviews.csv")
# Convert Date column to Date type
your_data$Date <- as.Date(your_data$Date)
# Convert Date column to Date type
your_data$Date <- as.Date(your_data$Date)
# Create a tsibble object
your_tsibble <- tsibble::tsibble(
Date = your_data$Date,
Diamond = your_data$Diamond
)
## Using `Date` as index variable.
# Plot your data over time
autoplot(your_tsibble, series = "Diamond") +
labs(title = "Diamonds over Time",
y = "Diamond Count")
## Plot variable not specified, automatically selected `.vars = Diamond`
## Warning in geom_line(...): Ignoring unknown parameters: `series`
# Linear regression
lm_result <- lm(Diamond ~ Date, data = your_data)
# Print summary
summary(lm_result)
##
## Call:
## lm(formula = Diamond ~ Date, data = your_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1098.1 -267.3 -21.0 219.1 5666.8
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.760e+04 5.951e+03 -4.638 5.10e-06 ***
## Date 1.572e+00 3.048e-01 5.158 4.32e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 527.5 on 328 degrees of freedom
## Multiple R-squared: 0.07503, Adjusted R-squared: 0.07221
## F-statistic: 26.61 on 1 and 328 DF, p-value: 4.325e-07
# Check for trends
ggplot(your_data, aes(x = Date, y = Diamond)) +
geom_line() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
labs(title = "Linear Regression Trend",
y = "Diamonds Count",
x = "Date")
## `geom_smooth()` using formula = 'y ~ x'
# ACF and PACF plots
Acf(your_tsibble$Diamond, main = "ACF of Diamonds Time Series")
Pacf(your_tsibble$Diamond, main = "PACF of Diamonds Time Series")
Insight: These plots show the autocorrelation and partial
autocorrelation functions of the Diamonds time series.
Significance: Autocorrelation helps identify patterns or cycles in the data. Peaks in ACF and PACF plots indicate potential seasonality.
Further Questions: Are there significant lags in the autocorrelation and partial autocorrelation plots? What is the lag at which autocorrelation becomes negligible? Does this suggest seasonality in the data?