This report aims to analyze the relationship between public interest in diamonds (as indicated by Wikipedia pageviews) and diamond prices. We’ll use data from the diamonds dataset in ggplot2 package and Wikipedia pageviews.
# Fetching Wikipedia pageviews for "Diamond"
diamond_pageviews <- article_pageviews("Diamond",
from = "20150101",
to = "20151231",
project = "en.wikipedia",
platform = "all",
user_type = "all")
# Loading the ggplot2 package and diamonds dataset
diamonds_df <- diamonds
# Simulate monthly date for each diamond record
set.seed(123)
diamonds_df$date <- sample(seq(as.Date('2015-01-01'), as.Date('2015-12-31'), by="day"), nrow(diamonds_df), replace = TRUE)
# Aggregating average price per month
monthly_prices <- aggregate(price ~ format(date, "%Y-%m"), data = diamonds_df, FUN = mean)
In this step, we prepare the diamonds dataset for analysis. We simulate a time component to align with the Wikipedia pageviews data and compute the average diamond price for each month. This helps in understanding how diamond prices vary over time.
# Ensure the date column in monthly_prices is named correctly for merging
colnames(monthly_prices) <- c("date", "average_price")
# Merging the datasets
merged_data <- merge(diamond_pageviews, monthly_prices, by = "date")
# Creating a tsibble
# Ensure that the merged_data has a proper key-time format for tsibble
merged_tsibble <- as_tsibble(merged_data, key = average_price, index = date)
By merging the Wikipedia pageviews data with the monthly diamond prices, we create a comprehensive dataset that can be used for time series analysis. The tsibble object facilitates handling and analyzing time series data in R.
ggplot(diamonds, aes(x = price)) + geom_boxplot() + labs(title = "Boxplot of Diamond Prices")
ggplot(diamonds, aes(x = carat)) + geom_boxplot() + labs(title = "Boxplot of Diamond Carats")
Visualizing the data allows us to quickly identify trends, patterns, or anomalies. This plot will show how public interest in diamonds and diamond prices have changed over time and whether there is any apparent correlation between the two.
diamonds$cut <- as.factor(diamonds$cut)
diamonds$color <- as.factor(diamonds$color)
diamonds$clarity <- as.factor(diamonds$clarity)
model <- lm(price ~ carat + cut + color + clarity + depth + table + x + y + z, data = diamonds)
summary(model)
##
## Call:
## lm(formula = price ~ carat + cut + color + clarity + depth +
## table + x + y + z, data = diamonds)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21376.0 -592.4 -183.5 376.4 10694.2
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5753.762 396.630 14.507 < 2e-16 ***
## carat 11256.978 48.628 231.494 < 2e-16 ***
## cut.L 584.457 22.478 26.001 < 2e-16 ***
## cut.Q -301.908 17.994 -16.778 < 2e-16 ***
## cut.C 148.035 15.483 9.561 < 2e-16 ***
## cut^4 -20.794 12.377 -1.680 0.09294 .
## color.L -1952.160 17.342 -112.570 < 2e-16 ***
## color.Q -672.054 15.777 -42.597 < 2e-16 ***
## color.C -165.283 14.725 -11.225 < 2e-16 ***
## color^4 38.195 13.527 2.824 0.00475 **
## color^5 -95.793 12.776 -7.498 6.59e-14 ***
## color^6 -48.466 11.614 -4.173 3.01e-05 ***
## clarity.L 4097.431 30.259 135.414 < 2e-16 ***
## clarity.Q -1925.004 28.227 -68.197 < 2e-16 ***
## clarity.C 982.205 24.152 40.668 < 2e-16 ***
## clarity^4 -364.918 19.285 -18.922 < 2e-16 ***
## clarity^5 233.563 15.752 14.828 < 2e-16 ***
## clarity^6 6.883 13.715 0.502 0.61575
## clarity^7 90.640 12.103 7.489 7.06e-14 ***
## depth -63.806 4.535 -14.071 < 2e-16 ***
## table -26.474 2.912 -9.092 < 2e-16 ***
## x -1008.261 32.898 -30.648 < 2e-16 ***
## y 9.609 19.333 0.497 0.61918
## z -50.119 33.486 -1.497 0.13448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1130 on 53916 degrees of freedom
## Multiple R-squared: 0.9198, Adjusted R-squared: 0.9198
## F-statistic: 2.688e+04 on 23 and 53916 DF, p-value: < 2.2e-16
The linear regression analysis helps to understand if there’s a statistically significant relationship between public interest in diamonds and their prices. The model’s coefficients will indicate the direction and strength of this relationship.
The analysis conducted in this report aimed to uncover the
relationship between public interest in diamonds, as indicated by
Wikipedia pageviews, and diamond prices. Several key insights emerged
from this exploration:
Trends and Correlations: The visual exploration of
pageviews and diamond prices over time suggested a potential
correlation. Periods of increased pageview activity appeared to align
with changes in diamond prices. This might indicate that public
interest, as reflected in online searches, could be a predictor or
influencer of diamond market dynamics.
Statistical
Relationships: The linear regression analysis provided a more
concrete view of the relationship between pageviews and prices. While
the model highlighted a statistically significant correlation, the
strength of this relationship (as indicated by the regression
coefficient) necessitates careful interpretation. It suggests that while
pageviews might influence diamond prices, they are certainly not the
sole factor.
Seasonal Patterns: The analysis of
seasonality, particularly through smoothing and autocorrelation,
revealed certain seasonal trends in diamond prices. These patterns could
be linked to annual events, consumer behavior changes, or broader
economic cycles.
Market Implications: For
stakeholders in the diamond industry, these findings underscore the
importance of monitoring digital engagement metrics as a proxy for
consumer interest. Marketing and pricing strategies can be tailored to
capitalize on periods of heightened public interest.
Future
Research: Further investigations could explore more granular
data, such as the impact of specific events on consumer interest, or
compare these trends with those of other luxury goods. Additionally,
incorporating more variables (like economic indicators or social media
trends) could offer a more holistic view of the market.