In the given data set, all rows represent diamonds with 3 columns namely carat, clarity and price
We have more than 50000 transaction recorded in the given file. high clarity Diamond is priced high. Does the relationship between price and clarity always hold true ?
Let us investigate
step 1: load the data
mydata <- read.csv(file.choose())
View(mydata)
str(mydata)
## 'data.frame': 53940 obs. of 3 variables:
## $ carat : num 0.23 0.21 0.23 0.29 0.31 0.24 0.24 0.26 0.22 0.23 ...
## $ clarity: chr "SI2" "SI1" "VS1" "VS2" ...
## $ price : int 326 326 327 334 335 336 336 337 337 338 ...
Step 2: Ensure you have right package for the project analysis - ggplot2
library(ggplot2)
Step 3: scatter plot
ggplot(data=mydata, aes(x=carat, y=price)) + geom_point()
step 4: Now, we can add clarity variable
ggplot(data=mydata, aes(x=carat, y=price, colour=clarity)) + geom_point()
Step 5: the scatter points got many clumsy points and not so clear. let us make it more clear
ggplot(data=mydata, aes(x=carat, y=price, colour=clarity)) + geom_point(alpha=0.1)
step 6: Its seem to be clear but scatter plot is all the records irrespective of significant and not significant.Therefore let us filter out the data now with the condition on clarity
ggplot(data=mydata[mydata$carat < 2.5,],aes(x=carat, y=price, colour=clarity)) + geom_point(alpha=0.1)
It is filtering out the data and showing data from 0 to 2.5 carat only
Step 7:To see the average for variable ‘carat’ run the following line
ggplot(data=mydata[mydata$carat < 2.5,],aes(x=carat, y=price, colour=clarity)) + geom_point(alpha=0.1) + geom_smooth()
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
1.From this plot we can observe that in the carat(1.0:1.5)we can see there is not much of the clash or intersection between all kind of clarity here. 2.From the plot we can observe that in the carat range(1.5:2.0) we can see that many clashes between different kind of clarity are the in which VVS2 is intersecting VVS1 and also IF price range. S12 3.From the scatter plot we can observe that carat range(2.0:2.5) we can see that the clarity wise pricing is not done because VS2 is intersecting many other clarity range such as SI1, SI2, VVS1 and there is down trend ahead, IF is also intersected by I1.
From the above statements we can see that our assumption as price is determined by the clarity of the diamonds but here we can see that various interception between different clarity range proves that the prices have be altered or influence, which defies our assumption of price is based on clarity.