Analysis of the Diamonds dataset
:By Sammi Oyabi
The appropriate libraries were loaded for effective analysis of the dataset and load the diamonds data set
library(doBy)
library(tidyverse)
library(ggplot2)
library(gridExtra)
library(GGally)
data(diamonds)
-Insight of the Data Structure of the dataset helps in understanding various relationships between the diamomds characteristics and its price, identifying patterns in the quality of cuts, color and the clarity of the diamond, thus exploring how they all correlate with each other. |
-The descriptive summary the descriptive summary here specifies on the variables; price, carat, width, and depth as the output will be grouped into cut and clarity.
#summary of the variable 'price'
library(doBy)
summaryBy(price ~ cut + clarity, data = diamonds, FUN = function(x) c(Min = min(x), Q1 = quantile(x, 0.25), Median = median(x), Mean = mean(x), Q3 = quantile(x, 0.75), Max = max(x)))
## # A tibble: 40 × 8
## cut clarity price.Min `price.Q1.25%` price.Median price.Mean `price.Q3.75%`
## <ord> <ord> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Fair I1 584 1387. 2397 3704. 5614.
## 2 Fair SI2 536 2763 3681 5174. 6266.
## 3 Fair SI1 496 2082. 3528. 4208. 4798
## 4 Fair VS2 337 1814 3190 4175. 5090
## 5 Fair VS1 361 1804. 2830. 4165. 5596.
## 6 Fair VVS2 369 1227 2484 3350. 4312
## 7 Fair VVS1 740 1012 2797 3871. 4194
## 8 Fair IF 1127 1208 1849 1912. 2211
## 9 Good I1 361 2090 3118. 3597. 4971
## 10 Good SI2 335 2190 3770 4580. 4805
## # ℹ 30 more rows
## # ℹ 1 more variable: price.Max <dbl>
#summary of the variable 'carat'
summaryBy(carat ~ cut + clarity, data = diamonds, FUN = function(x) c(Min = min(x), Q1 = quantile(x, 0.25), Median = median(x), Mean = mean(x), Q3 = quantile(x, 0.75), Max = max(x)))
## # A tibble: 40 × 8
## cut clarity carat.Min `carat.Q1.25%` carat.Median carat.Mean `carat.Q3.75%`
## <ord> <ord> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Fair I1 0.34 0.85 1.06 1.36 1.82
## 2 Fair SI2 0.25 0.9 1.01 1.20 1.5
## 3 Fair SI1 0.29 0.7 0.98 0.965 1.02
## 4 Fair VS2 0.22 0.64 0.9 0.885 1.01
## 5 Fair VS1 0.25 0.598 0.77 0.880 1.01
## 6 Fair VVS2 0.23 0.45 0.7 0.692 0.91
## 7 Fair VVS1 0.3 0.34 0.7 0.665 0.91
## 8 Fair IF 0.3 0.37 0.47 0.474 0.52
## 9 Good I1 0.32 0.9 1.07 1.20 1.51
## 10 Good SI2 0.3 0.71 1 1.04 1.2
## # ℹ 30 more rows
## # ℹ 1 more variable: carat.Max <dbl>
#summary of the variable 'width'
summary(width ~ cut + clarity)
## Length Class Mode
## 3 formula call
#summary of the variable 'depth'
summaryBy(price ~ cut + clarity, data = diamonds, FUN = function(x) c(Min = min(x), Q1 = quantile(x, 0.25), Median = median(x), Mean = mean(x), Q3 = quantile(x, 0.75), Max = max(x)))
## # A tibble: 40 × 8
## cut clarity price.Min `price.Q1.25%` price.Median price.Mean `price.Q3.75%`
## <ord> <ord> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Fair I1 584 1387. 2397 3704. 5614.
## 2 Fair SI2 536 2763 3681 5174. 6266.
## 3 Fair SI1 496 2082. 3528. 4208. 4798
## 4 Fair VS2 337 1814 3190 4175. 5090
## 5 Fair VS1 361 1804. 2830. 4165. 5596.
## 6 Fair VVS2 369 1227 2484 3350. 4312
## 7 Fair VVS1 740 1012 2797 3871. 4194
## 8 Fair IF 1127 1208 1849 1912. 2211
## 9 Good I1 361 2090 3118. 3597. 4971
## 10 Good SI2 335 2190 3770 4580. 4805
## # ℹ 30 more rows
## # ℹ 1 more variable: price.Max <dbl>
-The visualization, description, and findings of the data. >Here the data is going to be visualized in form of a box plot since box plot is easier to understand and translate.The price variable, cut variable and the clarity variables is used.
#price against cut
ggplot(diamonds, aes(x = cut, y = price)) +
geom_boxplot() +
xlab("Cut") +
ylab("Price") +
ggtitle("Box Plot of Price against Cut")
#price gainst clarity
ggplot(diamonds, aes(x = clarity, y = price)) +
geom_boxplot() +
xlab("clarity") +
ylab("price") +
ggtitle("Box Plot of Price against clarity")
-Interpretation: The boxes represent the interquatile range of the diamonds prices with the cut and clarity variable(the box indicate spread of prices within the cut and clarity variable). the the line across the boxes indicate the median prices with the cut and clarity variable. Medians can provide insights into the central tendency of prices for each cut and clarity.
-Difference between the cut and clarity The cut is graded as “Ideal,” “Premium,” “Very Good,” “Good,” and “Fair”, while the clarity is graded as “Internally Flawless,” “Very, Very Slightly Included” (VVS1 and VVS2), “Very Slightly Included” (VS1 and VS2), “Slightly Included” (SI1 and SI2), and “Included” (I1, I2, I3).