# Load required libraries
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
# Load diamonds dataset
data("diamonds")

# Numeric Summary and Novel Questions
summary(diamonds)
##      carat               cut        color        clarity          depth      
##  Min.   :0.2000   Fair     : 1610   D: 6775   SI1    :13065   Min.   :43.00  
##  1st Qu.:0.4000   Good     : 4906   E: 9797   VS2    :12258   1st Qu.:61.00  
##  Median :0.7000   Very Good:12082   F: 9542   SI2    : 9194   Median :61.80  
##  Mean   :0.7979   Premium  :13791   G:11292   VS1    : 8171   Mean   :61.75  
##  3rd Qu.:1.0400   Ideal    :21551   H: 8304   VVS2   : 5066   3rd Qu.:62.50  
##  Max.   :5.0100                     I: 5422   VVS1   : 3655   Max.   :79.00  
##                                     J: 2808   (Other): 2531                  
##      table           price             x                y         
##  Min.   :43.00   Min.   :  326   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.:56.00   1st Qu.:  950   1st Qu.: 4.710   1st Qu.: 4.720  
##  Median :57.00   Median : 2401   Median : 5.700   Median : 5.710  
##  Mean   :57.46   Mean   : 3933   Mean   : 5.731   Mean   : 5.735  
##  3rd Qu.:59.00   3rd Qu.: 5324   3rd Qu.: 6.540   3rd Qu.: 6.540  
##  Max.   :95.00   Max.   :18823   Max.   :10.740   Max.   :58.900  
##                                                                   
##        z         
##  Min.   : 0.000  
##  1st Qu.: 2.910  
##  Median : 3.530  
##  Mean   : 3.539  
##  3rd Qu.: 4.040  
##  Max.   :31.800  
## 
# Exploring novel questions
cut_price_summary <- diamonds %>%
  group_by(cut) %>%
  summarize(avg_price = mean(price))

color_carat_relationship <- diamonds %>%
  group_by(color) %>%
  summarise(mean_carat = mean(carat))

# Aggregation Functions and Visual Summary
color_clarity_price <- diamonds %>%
  group_by(color, clarity) %>%
  summarise(avg_price = mean(price))
## `summarise()` has grouped output by 'color'. You can override using the
## `.groups` argument.
# Visualizations
ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point() +
  ggtitle("Scatterplot of Carat vs Price")

ggplot(diamonds, aes(x = cut, y = price)) +
  geom_boxplot() +
  ggtitle("Boxplot of Cut vs Price")

# Week 3 Statistical Analyses
cut_price_summary <- diamonds %>%
  group_by(cut) %>%
  summarise(avg_price = mean(price))

color_carat_analysis <- diamonds %>%
  group_by(color) %>%
  summarise(mean_carat = mean(carat))

# Week 6 and Week 7 Hypothesis Testing
cut_price_test <- lm(price ~ cut, data = diamonds)
# Perform hypothesis testing on cut_price_test

carat_cut_test <- lm(price ~ carat * cut, data = diamonds)
# Perform hypothesis testing on carat_cut_test

# Week 8 ANOVA and Regression Models
anova_model <- aov(price ~ cut, data = diamonds)
# Perform ANOVA on anova_model

regression_model <- lm(price ~ carat, data = diamonds)
# Perform regression analysis on regression_model

# Week 10 Logistic Regression and Binary Variable
diamonds$log_cut <- ifelse(diamonds$cut == "Ideal", 1, 0)
logistic_model <- glm(log_cut ~ carat + color, data = diamonds, family = "binomial")
# Perform logistic regression analysis on logistic_model

# Week 11 Time Series Analysis
time_series_data <- diamonds %>%
  group_by(date = as.Date(sample(seq(as.Date('2020-01-01'), as.Date('2023-01-01'), by="day"), nrow(diamonds), replace=TRUE))) %>%
  summarise(diamond_count = n())

# Perform time series analysis on time_series_data

# Week 12 Linear Model and Diagnostic Checks
linear_model <- lm(price ~ carat, data = diamonds)

Subject: Key Insights and Recommendations from Diamonds Dataset Analysis

I am pleased to present the key insights and recommendations derived from my comprehensive exploration of the diamonds dataset. This journey has encompassed various statistical analyses, visualizations, and hypothesis testing, offering valuable insights into the intricate facets of the diamond industry.

Numeric Summary and Novel Questions: The initial numeric summary illuminated the central tendencies, dispersion, and distributions of essential attributes, laying the groundwork for subsequent analyses. Exploring novel questions revealed the substantial impact of cut quality on diamond prices and the intriguing relationship between color grades and carat sizes.

Aggregation Functions and Visual Summary: Utilizing aggregation functions, I unveiled patterns in average prices based on color and clarity combinations, providing a higher-level perspective. Visual summaries, including scatterplots, boxplots, and histograms, offered intuitive insights into attribute relationships.

Week 3 Statistical Analyses: Grouping by cut and summarizing prices exposed the significant influence of cut quality on diamond prices. Analyzing carat by color grades highlighted an interesting correlation between lower color grades and larger average carat sizes.

Week 6 and Week 7 Hypothesis Testing: Hypothesis testing on carat weight and price by cut quality underscored the need for practical significance assessment. Aggregating and testing average prices between different cut qualities provided actionable insights for pricing strategies and market dynamics.

Week 8 ANOVA and Regression Models: ANOVA tests indicated that cut quality significantly affects diamond prices, offering valuable information for stakeholders. Linear regression models emphasized the strong positive relationship between carat weight and prices, leading to actionable pricing strategies.

Week 10 Logistic Regression and Binary Variable: Logistic regression models and binary cut variables provided simplified insights into factors influencing cut quality. Recommendations included exploring consumer preferences and continuous improvement of models.

Week 11 Time Series Analysis: Time series analysis revealed a positive trend in diamond counts over time, suggesting potential growth or increased interest. Recommendations encompassed exploring seasonality, forecasting, and understanding external factors driving the observed trend.

Week 12 Linear Model and Diagnostic Checks: Building a linear model for diamond prices based on carat weight emphasized its significance for pricing strategies. Diagnostic checks were recommended to ensure the model’s reliability, addressing issues related to outliers and non-normality.

Summary and Recommendations:

Pricing Strategies: Recognize the significance of cut quality and carat weight in influencing diamond prices. Tailor pricing strategies based on these insights. Customer Preferences: Understand and align with consumer preferences, considering factors such as cut quality and carat weight. Continuous Improvement: Continuously refine models, explore additional variables, and stay informed about market trends for more accurate predictions. Strategic Planning: Leverage time series analysis for strategic planning, considering potential seasonality and forecasting future trends. In conclusion, my analyses have uncovered valuable insights that can guide strategic decision-making in the dynamic diamond industry. I encourage ongoing exploration and continuous improvement to ensure my models remain robust and aligned with the ever-evolving dynamics of the market.