Introduction

This report presents a comprehensive statistical analysis of diamonds dataset from the ggplot2 package. The aim is to uncover insights that can be applied in practical settings, specifically within the diamond industry.

Dataset Overview

The dataset includes the following variables:

data("diamonds")
head(diamonds)
## # A tibble: 6 × 10
##   carat cut       color clarity depth table price     x     y     z
##   <dbl> <ord>     <ord> <ord>   <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1  0.23 Ideal     E     SI2      61.5    55   326  3.95  3.98  2.43
## 2  0.21 Premium   E     SI1      59.8    61   326  3.89  3.84  2.31
## 3  0.23 Good      E     VS1      56.9    65   327  4.05  4.07  2.31
## 4  0.29 Premium   I     VS2      62.4    58   334  4.2   4.23  2.63
## 5  0.31 Good      J     SI2      63.3    58   335  4.34  4.35  2.75
## 6  0.24 Very Good J     VVS2     62.8    57   336  3.94  3.96  2.48

For a comprehensive analysis, we can explore:

Descriptive Statistics

We begin by examining the basic statistical measures for each numerical column in the dataset.

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  
## 

The descriptive statistics for the diamond dataset provide the following insights:

  1. Carat: Ranges from 0.2 to 5.01 with an average of about 0.8 carats.
  2. Depth: Has a mean of 61.75% with a standard deviation of 1.43%.
  3. Table: Averages at 57.46% with a standard deviation of 2.23%.
  4. Price: The prices vary widely, ranging from $326 to $18,823, with an average price of approximately $3,933.
  5. Dimensions (x, y, z): The average dimensions of the diamonds are around 5.73 mm by 5.73 mm by 3.54 mm. There are no missing values in the dataset, which is good for analysis.

Next, let’s perform a correlation analysis to understand how different numerical variables, especially carat, depth, table, dimensions (x, y, z), relate to the diamond’s price. This will help in understanding which factors are most influential in determining the price of a diamond.

Correlation Analysis

Understanding the relationships between different numerical variables, especially in relation to the price, is crucial.

numerical_data <- diamonds %>% select_if(is.numeric)
correlation_matrix <- cor(numerical_data)
ggcorrplot(correlation_matrix, lab = TRUE)

The correlation matrix provides insights into how different variables in the diamond dataset are related to each other, particularly in relation to the price:

  1. Carat and Price: There is a strong positive correlation (0.92) between the carat of the diamond and its price. This suggests that as the carat size increases, the price of the diamond typically increases as well.
  2. Dimensions (x, y, z) and Price: These dimensions are also strongly correlated with the price (0.88, 0.86, and 0.86 respectively). This is expected as larger diamonds (indicated by larger dimensions) tend to be heavier (higher carat) and more valuable.
  3. Table and Price: The correlation is weaker (0.13) compared to other features, indicating that the table size of the diamond is not a strong predictor of its price.
  4. Depth and Price: The correlation is very low (0.01), suggesting that the depth percentage of the diamond does not significantly influence its price.

Grouped Analysis

Now, let’s analyze how categorical variables like cut, color, and clarity affect the price. For this, we will look at average prices within each category of these variables. We will also investigate the distribution of prices and carat weights, which can provide insights into the typical characteristics of diamonds in the dataset and their pricing patterns.

avg_price_by_cut <- diamonds %>% 
  group_by(cut) %>% 
  summarize(Avg_Price = mean(price))

avg_price_by_color <- diamonds %>% 
  group_by(color) %>% 
  summarize(Avg_Price = mean(price))

avg_price_by_clarity <- diamonds %>% 
  group_by(clarity) %>% 
  summarize(Avg_Price = mean(price))

# Plotting
par(mfrow = c(1, 3))
barplot(avg_price_by_cut$Avg_Price, names.arg = avg_price_by_cut$cut, 
        main = "Average Price by Cut", col = "skyblue", ylab = "Average Price ($)")
barplot(avg_price_by_color$Avg_Price, names.arg = avg_price_by_color$color, 
        main = "Average Price by Color", col = "lightgreen", ylab = "Average Price ($)")
barplot(avg_price_by_clarity$Avg_Price, names.arg = avg_price_by_clarity$clarity, 
        main = "Average Price by Clarity", col = "salmon", ylab = "Average Price ($)")

The analysis of how cut, color, and clarity affect the average price of diamonds reveals several insights:

  1. Average Price by Cut: The cut of a diamond appears to influence its average price. ‘Premium’ and ‘Ideal’ cuts tend to have higher average prices, which indicates that better-quality cuts are valued more in the market.
  2. Average Price by Color: The color of diamonds shows a trend where diamonds with colors rated closer to D (the highest quality) tend to have higher average prices. This suggests that color is an important factor in the valuation of diamonds.
  3. Average Price by Clarity: Similar to color and cut, clarity also influences the average price. Diamonds with higher clarity ratings, such as VVS1 and IF (Internally Flawless), command higher average prices. This indicates the market’s preference for clearer diamonds.
ggplot(diamonds, aes(x = price)) + 
  geom_histogram(bins = 50, fill = "purple") + 
  labs(title = "Distribution of Diamond Prices", x = "Price ($)", y = "Frequency")

ggplot(diamonds, aes(x = carat)) + 
  geom_histogram(bins = 50, fill = "orange") + 
  labs(title = "Distribution of Diamond Carat Weights", x = "Carat", y = "Frequency")

Additionally, the distribution plots for diamond prices and carat weights provide further insights:

Outliers detection

Outliers can significantly affect the results of a statistical analysis. In the context of the diamonds dataset, we can focus on detecting outliers in key variables like price, carat, and the physical dimensions (x, y, z).

# Outlier detection for 'price' and 'carat'
par(mfrow=c(1,2)) # Plotting two plots side by side
boxplot(diamonds$price, main="Price", horizontal=TRUE, col="lightblue")
boxplot(diamonds$carat, main="Carat", horizontal=TRUE, col="lightgreen")

# Outlier detection for dimensions 'x', 'y', 'z'
par(mfrow=c(1,3)) # Plotting three plots side by side
boxplot(diamonds$x, main="Length (x)", horizontal=TRUE, col="lightcoral")
boxplot(diamonds$y, main="Width (y)", horizontal=TRUE, col="lightyellow")
boxplot(diamonds$z, main="Depth (z)", horizontal=TRUE, col="lightskyblue")

This code creates boxplots for the price, carat, and dimensions (x, y, z) which can help in visually identifying outliers (points that fall outside the whiskers of the boxplot).

Visualizations

Visual representations can provide insights into the relationships and patterns within the data. Let’s create some additional visualizations:

  1. Price vs. Carat
ggplot(diamonds, aes(x = carat, y = price)) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(method = "lm", color = "red") +
  labs(title = "Price vs. Carat", x = "Carat", y = "Price ($)")
## `geom_smooth()` using formula = 'y ~ x'

This scatter plot with a regression line will show how price varies with carat weight.

  1. Price Distribution by Cut
ggplot(diamonds, aes(x = price, fill = cut)) + 
  geom_histogram(bins = 30, position = "identity", alpha = 0.6) + 
  scale_fill_brewer(palette = "Set1") +
  labs(title = "Price Distribution by Cut", x = "Price ($)", y = "Count")

This histogram provides insight into the distribution of prices across different cuts.

  1. Carat Distribution by Clarity
ggplot(diamonds, aes(x = carat, fill = clarity)) + 
  geom_histogram(bins = 30, position = "identity", alpha = 0.6) + 
  scale_fill_brewer(palette = "Pastel1") +
  labs(title = "Carat Distribution by Clarity", x = "Carat", y = "Count")

This histogram shows how carat weight is distributed across different clarity grades.

Actionable Insights

Based on this analysis, the following practical insights can be derived:

  1. For Buyers: If on a budget, consider diamonds with good cuts, but lower color and clarity grades, as these factors significantly influence price. Smaller carat diamonds offer better value for money.
  2. For Sellers/Traders: Focusing on high-quality cuts, color, and clarity can yield higher returns, as these are highly valued in the market. However, it’s important to balance this with the increased cost of such high-quality diamonds.
  3. Inventory Management for Retailers: Stock more diamonds in the lower to mid-price range and carat size, as these are more common and likely to have more frequent turnover. High-value diamonds should be stocked less due to their higher price and lower frequency of purchase.
  4. Marketing Strategies: Emphasize the quality of cut, color, and clarity in marketing campaigns, as these factors significantly affect a diamond’s appeal and value.

This analysis can help different stakeholders in the diamond industry make informed decisions based on the characteristics that most significantly impact diamond prices.

Conclusion

In conclusion, the comprehensive statistical analysis of the diamonds dataset reveals several key insights that can guide decisions for different stakeholders in the diamond industry:

  1. Carat Weight’s Strong Influence on Price: There is a strong positive correlation between the carat weight of a diamond and its price. This suggests that the size of the diamond is one of the most significant factors determining its value.
  2. Importance of Cut, Color, and Clarity: The quality of the cut, the color grade, and the clarity of diamonds significantly influence their average price. Diamonds with higher quality cuts, closer to color grade D, and with higher clarity grades command higher prices in the market.
  3. Market Trends: The majority of diamonds in the dataset fall into the lower to mid-price range and have smaller carat weights. This indicates that while high-value, large diamonds are present, they are less common.