## [1] 1599 13
## [1] "X" "fixed.acidity" "volatile.acidity"
## [4] "citric.acid" "residual.sugar" "chlorides"
## [7] "free.sulfur.dioxide" "total.sulfur.dioxide" "density"
## [10] "pH" "sulphates" "alcohol"
## [13] "quality"
## 'data.frame': 1599 obs. of 13 variables:
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ fixed.acidity : num 7.4 7.8 7.8 11.2 7.4 7.4 7.9 7.3 7.8 7.5 ...
## $ volatile.acidity : num 0.7 0.88 0.76 0.28 0.7 0.66 0.6 0.65 0.58 0.5 ...
## $ citric.acid : num 0 0 0.04 0.56 0 0 0.06 0 0.02 0.36 ...
## $ residual.sugar : num 1.9 2.6 2.3 1.9 1.9 1.8 1.6 1.2 2 6.1 ...
## $ chlorides : num 0.076 0.098 0.092 0.075 0.076 0.075 0.069 0.065 0.073 0.071 ...
## $ free.sulfur.dioxide : num 11 25 15 17 11 13 15 15 9 17 ...
## $ total.sulfur.dioxide: num 34 67 54 60 34 40 59 21 18 102 ...
## $ density : num 0.998 0.997 0.997 0.998 0.998 ...
## $ pH : num 3.51 3.2 3.26 3.16 3.51 3.51 3.3 3.39 3.36 3.35 ...
## $ sulphates : num 0.56 0.68 0.65 0.58 0.56 0.56 0.46 0.47 0.57 0.8 ...
## $ alcohol : num 9.4 9.8 9.8 9.8 9.4 9.4 9.4 10 9.5 10.5 ...
## $ quality : int 5 5 5 6 5 5 5 7 7 5 ...
Quality is measured from 1 to 10. The following demonstrates the counts per grading. There have not been any 1, 2, 9 or 10 ratings.
##
## 3 4 5 6 7 8
## 10 53 681 638 199 18
## X fixed.acidity volatile.acidity citric.acid
## Min. : 1.0 Min. : 4.60 Min. :0.1200 Min. :0.000
## 1st Qu.: 400.5 1st Qu.: 7.10 1st Qu.:0.3900 1st Qu.:0.090
## Median : 800.0 Median : 7.90 Median :0.5200 Median :0.260
## Mean : 800.0 Mean : 8.32 Mean :0.5278 Mean :0.271
## 3rd Qu.:1199.5 3rd Qu.: 9.20 3rd Qu.:0.6400 3rd Qu.:0.420
## Max. :1599.0 Max. :15.90 Max. :1.5800 Max. :1.000
## residual.sugar chlorides free.sulfur.dioxide
## Min. : 0.900 Min. :0.01200 Min. : 1.00
## 1st Qu.: 1.900 1st Qu.:0.07000 1st Qu.: 7.00
## Median : 2.200 Median :0.07900 Median :14.00
## Mean : 2.539 Mean :0.08747 Mean :15.87
## 3rd Qu.: 2.600 3rd Qu.:0.09000 3rd Qu.:21.00
## Max. :15.500 Max. :0.61100 Max. :72.00
## total.sulfur.dioxide density pH sulphates
## Min. : 6.00 Min. :0.9901 Min. :2.740 Min. :0.3300
## 1st Qu.: 22.00 1st Qu.:0.9956 1st Qu.:3.210 1st Qu.:0.5500
## Median : 38.00 Median :0.9968 Median :3.310 Median :0.6200
## Mean : 46.47 Mean :0.9967 Mean :3.311 Mean :0.6581
## 3rd Qu.: 62.00 3rd Qu.:0.9978 3rd Qu.:3.400 3rd Qu.:0.7300
## Max. :289.00 Max. :1.0037 Max. :4.010 Max. :2.0000
## alcohol quality
## Min. : 8.40 Min. :3.000
## 1st Qu.: 9.50 1st Qu.:5.000
## Median :10.20 Median :6.000
## Mean :10.42 Mean :5.636
## 3rd Qu.:11.10 3rd Qu.:6.000
## Max. :14.90 Max. :8.000
Fixed acidity refers to the tartaric acid concentration. Tartaric Acid plays a critical role in the taste, feel and color of a wine. But even more important, it lowers the pH enough to kill undesirable bacteria, acting as a preservative. Winemakers adjust acidity by adding tartaric acid to the wine. In our case it varies between 4.6 and 15.9 g/L with a median of 7.9 g/L.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.60 7.10 7.90 8.32 9.20 15.90
Volatile acidity refers to the concentration of acetic acid. The normal level of acetic acid in wine is around 0.3 g/L. Around this level, acetic acid is very desirable, contributing to the wine’s smell and taste. A high concentration of acetic acid in wine is a strong indication that the grapes have been contaminated. In our case, red wines tend to show a higher concentration of acetic acid which is normal but in the case of the maximum 1.58 g/L we can assume that any number above the 3rd quarile could indicate a contaminated wine.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.1200 0.3900 0.5200 0.5278 0.6400 1.5800
Citric acid is only present in small amounts in grapes, unless added and is often added to wines to increase acidity, complement a specific flavor or prevent ferric hazes. That’s why it shows a big amount of 0 citric acid observation in the below plot.
Residual sugar levels are normal to high. Dry wines shouldn’t exceed 2g/L, nevertheless our median is 2.2 which is close to 2 and we can consider it a normal level.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.900 1.900 2.200 2.539 2.600 15.500
Chloride level shows the amount of salt in the wine. Calcium Chloride can be used in order to lower mash pH. 1 gram per gallon will add 72ppm calcium and 127 ppm chloride. In our case the chloride levels are really low as shown at the plot.
The free form of SO2 exists in equilibrium between molecular SO2 (as a dissolved gas) and bisulfite ion. It prevents microbial growth and the oxidation of wine. Normal levels vary from 1 to 60mg/L. The 75% of our sample do not exceed 21 mg/L so we consider as outliers those higher than 60.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.00 7.00 14.00 15.87 21.00 72.00
Total sulfur dioxide is the amount of free and bound forms of S02. In low concentrations, SO2 is mostly undetectable in wine, but at free SO2 concentrations over 50 ppm, SO2 becomes evident in the nose and taste of wine. In our case the 50% of our sample varies between 22.0 and 62.0 ppm which is normal.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.00 22.00 38.00 46.47 62.00 289.00
The density of wine is close to that of water, dry wine is less, sweet wine is higher. Water has a density of 1.000 Kg/L.
Ethanol has a density of 0.789 Kg/L.
Sugar has a density of 1.587 Kg/L.
So from the below summary one can observe that our sample has a low density of sugar and alcohol. Later we can compare the wines with high residual sugars and low alcohol in order to see the corralation with density.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.9901 0.9956 0.9968 0.9967 0.9978 1.0040
PH is a measure of the acidity of wine. All wines ideally have a pH level between 2.9 and 4.2. Most red wines are between 3.3 and 3.5 pH. The lower the pH, the more acidic the wine is, the higher the pH, the less acidic the wine. Each point of the pH scale is a factor of 10. This means a wine with a pH of 3 is 10 times more acidic than a wine with a pH of 4. In our sample the pH varies between the common red-wine-levels which is 3.210 - 3.400.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.740 3.210 3.310 3.311 3.400 4.010
Depending on the production method, style and the color of the wine, sulfites in wine range from no-added sulphur (10-40 ppm) to about 350 ppm. Wines with lower acidity need more sulfur than higher acidity wines. At pH 3.6 and above, the sulphates needed is much higher because it?s an exponential ratio. Wines with higher sugar content tend to need more sulfur to prevent secondary fermentation of the remaining sugar. We can check the correlation between sugar and sulphates at the multivariate analysis later.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.3300 0.5500 0.6200 0.6581 0.7300 2.0000
Alcohol levels are typically restricted for Vinho Verde wines to no more than 11.5%. Vinho Verde Alvarinho is an exception to this rule as the intention is to recognise this special grape and to allow a richer wine to be produced to bring out the full character of the grape. Later we can assume that those wines with concentration of alcohol greater than the 3rd quartile (11.1%) could be considered as Alvarinho and be segmented differently.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 8.40 9.50 10.20 10.42 11.10 14.90
As mentioned earlier there have not been any 1, 2, 9 or 10 ratings.
There are 1,599 wine observations (specifically Portuguese red vinho verde wines) in the dataset with 13 features (x, fixed.acidity, volatile.acidity, citric.acid, residual.sugar, chlorides, free.sulfur.dioxide, total.sulfur.dioxide, density, pH, sulphates, alcohol, and quality).
x: 1599 entries (S/N)
fixed.acidity: 4.6 - 15.9 (tartaric acid - g / dm^3)
volatile.acidity: 0.12 - 1.58 (acetic acid - g / dm^3)
citric.acid: 0 - 1 (g / dm^3)
residual.sugar: 0.9 - 15.5 (g / dm^3)
chlorides: 0.012 - 0.611 (sodium chloride - g / dm^3)
free.sulfur.dioxide: 1 - 72 (mg / dm^3)
total.sulfur.dioxide: 6 - 289 (mg / dm^3)
density: 0.99007 - 1.00369 (g / cm^3)
pH: 2.74 - 4.01
sulphates: 0.33 - 2.00 (potassium sulphate - g / dm3)
alcohol: 8.4 - 14.9 (% by volume)
quality: 1 - 10 (score between 0 and 10)
fixed acidity - pH, Volatile acidity - pH, residual sugar - density - alcohol, alcohol - quality, chloride - quality, sulphates - sugar, free - total
I did not create any new variable as there was no need to do so.
No there was no need to tidy the data as there is no missing value or unstractured data.
In this section I will check all possible combinations between two variables and see whether there is a significant pearson R or not. Starting with a wide image of where corelation is stronger and later each combination seperately.
Deap red and green blocks are the ones I will put the most effort because they indicate the highest pearson R levels.
The red line in each diagram adds a smooth mean line on the plot.
##
## Pearson's product-moment correlation
##
## data: wines$fixed.acidity and wines$pH
## t = -37.366, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.7082857 -0.6559174
## sample estimates:
## cor
## -0.6829782
In the above plot we can see a significant R (close to -0.7). This means that while fixed acidity increases, the pH increases adequately.
##
## Pearson's product-moment correlation
##
## data: wines$residual.sugar and wines$density
## t = 15.189, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3116908 0.3973835
## sample estimates:
## cor
## 0.3552834
On the above plot, if I had more observations and a bigger dataset, it would show a higher pearson R, because destiy depends on sugars and alcohol.
##
## Pearson's product-moment correlation
##
## data: wines$alcohol and wines$density
## t = -22.838, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.5322547 -0.4583061
## sample estimates:
## cor
## -0.4961798
Same goes with the above plot. Density depends of sugars and alcohol.
##
## Pearson's product-moment correlation
##
## data: wines$alcohol and wines$residual.sugar
## t = 1.6829, df = 1597, p-value = 0.09258
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.006960058 0.090909069
## sample estimates:
## cor
## 0.04207544
There is almost no correlation between alcohol and residual sugar because in fermentation, sugar becomes alcohol but the residual sugar doesn’t have anything to do with the percentage of alcohol in the wine.
##
## Pearson's product-moment correlation
##
## data: wines$quality and wines$alcohol
## t = 21.639, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.4373540 0.5132081
## sample estimates:
## cor
## 0.4761663
On the above plot, I tried to observe if alcohol influence quality. Although it shows a high pearson R (close to 0.5) it doesn’t mean that it is true. I elaborate further later on.
##
## Pearson's product-moment correlation
##
## data: wines$free.sulfur.dioxide and wines$total.sulfur.dioxide
## t = 35.84, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6395786 0.6939740
## sample estimates:
## cor
## 0.6676665
The above observation is obvious. Nevertheless I was expecting a higher pearson R score. I observe it further later on.
##
## Pearson's product-moment correlation
##
## data: wines$sulphates and wines$quality
## t = 10.38, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2049011 0.2967610
## sample estimates:
## cor
## 0.2513971
The above looks weird. It suppose to have a negative correlation. Maybe it is because I do not have enough data. Sulphates make a wine smell ugly, thus quality should decrease instead of increase.
##
## Pearson's product-moment correlation
##
## data: wines$pH and wines$citric.acid
## t = -25.767, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.5756337 -0.5063336
## sample estimates:
## cor
## -0.5419041
There seems to be a valuable negative corelation on the above plot. And that because acidity is higher in low pH levels.
##
## Pearson's product-moment correlation
##
## data: wines$fixed.acidity and wines$density
## t = 35.877, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6399847 0.6943302
## sample estimates:
## cor
## 0.6680473
As mentioned before, fixed acidity is the concentation of tartaric acid which acts as perservative in wine. On the plot one can see that it not only affects the pH but the density as well as it shows a significant corelation.
##
## Pearson's product-moment correlation
##
## data: wines$fixed.acidity and wines$citric.acid
## t = 36.234, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6438839 0.6977493
## sample estimates:
## cor
## 0.6717034
As mentioned before citric acid is only present in small amounts in grapes, unless added and is often added to wines to increase acidity. The above plot proves the norm.
After having tested all of the possible relationships between the variables, as seen from the pearson correlation coefficient, the most significant relationships could be that of free.sulfur.dioxide with total.sulfur.dioxide which is something normal, that of fixed.acidity with pH which are negative correlated meaning that as far as the amount of tartaric acid increases the pH decreases, that of alcohol with density which is negative correlated and is true based on the assumptions, that of quality with alcohol which shows that the percentage of alcohol could benefit the rating of judges, that of chlorides and density which are positive correlated, and that of sulphates and quality which are positive correlated and really weird because sulphates represent bad smell on wine.
I have observed any possible correlation between two variables and there in nothing more special than the features I mentioned before.
The strongest relationship, meaning that the pearson’s r is closer to 1 or -1, was that of that of free.sulfur.dioxide with total.sulfur.dioxide.
Trying to find some relation on the data I found out that it would be simpler if I changed the type of quality variable into factor. From the plot below one can see that there is no particular relation between quuality and the correlated pH and fixed.acidity.
Then I tryied to see any correlation between alcohol, residual.sugar and density as these variables are highly depened from each other. The outcome is the following.
##
## Pearson's product-moment correlation
##
## data: wines$alcohol/wines$residual.sugar and wines$alcohol
## t = 10.454, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2066314 0.2984078
## sample estimates:
## cor
## 0.2530889
On the way to get deeper in data, I suspected something really weird. As shown on the plot below the wines with low density, and high alcohol levels have higher pH levels as the bubbles grow bigger and stabilize in a high but not top quality. It was a trigger to create a model from this inspetion.
##
## Calls:
## m1: lm(formula = I(alcohol) ~ I(log(density)), data = wines)
## m2: lm(formula = I(alcohol) ~ I(log(density)) + density, data = wines)
## m3: lm(formula = I(alcohol) ~ I(log(density)) + density + pH, data = wines)
##
## =============================================================
## m1 m2 m3
## -------------------------------------------------------------
## (Intercept) 9.511*** -119715.455*** -120007.717***
## (0.046) (6965.198) (6957.679)
## I(log(density)) -279.582*** -119622.613*** -119903.757***
## (12.224) (6942.987) (6935.408)
## density 119725.363*** 120016.571***
## (6965.221) (6957.693)
## pH 0.328*
## (0.146)
## -------------------------------------------------------------
## R-squared 0.247 0.364 0.366
## adj. R-squared 0.246 0.364 0.365
## sigma 0.925 0.850 0.849
## F 523.135 457.528 307.457
## p 0.000 0.000 0.000
## Log-likelihood -2143.541 -2007.746 -2005.236
## Deviance 1366.979 1153.445 1149.830
## AIC 4293.081 4023.491 4020.472
## BIC 4309.213 4045.000 4047.358
## N 1599 1599 1599
## =============================================================
## fit lwr upr
## 1 12.71032 11.0242 14.39645
Same goes with free.sulfur.dioxide and total.sulfur.dioxide. Both showed high correlation thus I added quality as an extra variable to see if appears any pattern in data and there it is. One can observe from the plot that blue dots are in lower level and light green in upper.
##
## Calls:
## m11: lm(formula = I(log(total.sulfur.dioxide)) ~ I(free.sulfur.dioxide^(1/3)),
## data = wines)
## m22: lm(formula = I(log(total.sulfur.dioxide)) ~ I(free.sulfur.dioxide^(1/3)) +
## free.sulfur.dioxide, data = wines)
## m33: lm(formula = I(log(total.sulfur.dioxide)) ~ I(free.sulfur.dioxide^(1/3)) +
## free.sulfur.dioxide + quality, data = wines)
##
## ===========================================================
## m11 m22 m33
## -----------------------------------------------------------
## (Intercept) 1.154*** -0.014 -0.178
## (0.051) (0.132) (0.179)
## I(free.sulfur.dioxide^(1/3)) 1.021*** 1.771*** 1.738***
## (0.021) (0.081) (0.078)
## free.sulfur.dioxide -0.040*** -0.039***
## (0.004) (0.004)
## quality: 2/1 0.170
## (0.144)
## quality: 3/1 0.373**
## (0.133)
## quality: 4/1 0.160
## (0.133)
## quality: 5/1 0.051
## (0.135)
## quality: 6/1 0.120
## (0.164)
## -----------------------------------------------------------
## R-squared 0.601 0.622 0.653
## adj. R-squared 0.601 0.622 0.651
## sigma 0.446 0.434 0.417
## F 2403.014 1315.623 426.984
## p 0.000 0.000 0.000
## Log-likelihood -976.254 -931.578 -865.011
## Deviance 317.455 300.203 276.220
## AIC 1958.507 1871.157 1748.021
## BIC 1974.639 1892.665 1796.415
## N 1599 1599 1599
## ===========================================================
## fit lwr upr
## 1 63.94576 31.18716 114.0876
The below plot shows that higher concentration of residual sugar are observed mainly in medium quality wines as a higher volume of big bubbles are concentrated in quality 5 and 6.
At the below plot one can see the big chloride bubbles away from the rest at really high sulphate levels.
I observed all of the investigations that showed a statistically significant correlation between them. By some modifications in the coding, we saw that we can trust some patterns concerning the outcome of the comparisons.
There quite interesting interactions between the features. Some of them are described below: At the quality-alcohol plot, one can see that as far as the alcohol rises, the quality is getting better. The weird observation here concerns the residual sugars which show high levels in small alcohol levels for medium quality wines which is not something commonly heared in the wine market. Another observation that made me curious to elaborate a bit more is the density-alcohol plot. Here, one can see that the quality and the pH levels get bigger as far as the alcohol rises and the density is in low levels. I have never observed anything like this before as pH and quality are negatively correlated in common. Thats why I created a model for this plot and for the one with the biggest and clearest correlation, after transforming the axis to fit a linear model
From the above boxplots, one can obsrve that increasing the alcohol on wine, you can foul the opinion of judges as the quality grows bigger in high alcohol wines. On the other side bad aromas of high concentration of free sulfur dioxide doesn’t affect the judges at all as shown from the stability on the plot. This happens because maybe we don’t have the appropriate amount of data to draw accurate results.
Density is affected by two factors in wine world; alcohol and residual sugars. The alcohol lowers density and sugars augment it. On the other hand, low pH levels make better wines with a result of higher quality. On this plot I tried to combine all four to see if any pattern comes out. And there it is! This plot triggered the linear model construction and it shows an example which makes a lot of sense. I input a 0.992 density with 2.75 pH to the model and it gives back the alcohol level(fit, lower 0.5%, upper 0.5%).
The most common knowledge of every wine maker is that free sulfur dioxide affects total sulfur dioxide and vice versa. I tried to add quality on the plot and it showed a pattern that higher quality wines have less total sulfur dioxide. So I created a model that takes as input free sulfur dioxide and quality values and exports total sulfur dioxide level(fit, lower 0.5%, upper 0.5%).
This was a good attempt to further understand what is really happening in real data intsead of making obsrvasions based on theory. I expected different results is some cases such as the correlation between free sulfur dioxide and quality. Free sulfur dioxide in particular is the worst nightmare of every winemaker because it has direct affect on wine’s ‘nose’. I expected to observe low levels in high quality and high levels in low quality which did not happen. I observed higher levels in medium quality which could be because I did’t have the volume of data to cover low and high quality segments equally. In general the outcomes were accurate. As mentioned previously if having a bigger population and some more factorial variables, we could observe some better outcomes. If we combined red with white wines of the last 5 years for example we could see some really interesting changes through time and spieces.