library("tidyverse")
red_wine <- read_delim("https://mailuc-my.sharepoint.com/:x:/g/personal/brancaey_mail_uc_edu/IQBKSlUQ9WdUQZHv4AHIBIXSAc6vGQExmH61pfwWOuLki7I?e=LWB97W&download=1")BANA 7051 The Study of Wine Quality Part A
Load the data
What is the sample size?
The sample size of the data set is 1599 observations with 12 features.
nrow(red_wine)[1] 1599
Are there any outliers? Do you have concerns about data quality?’
Boxplots were used to explore outliers in the data. Examining the box plots shows that every variable has outliers. When looking at the boxplots, the three most concerning variables are Chlorides, Residual Sugar, and Sulphates, but I am also concerned about Total Sulfur Dioxide and Free Sulfur Dioxide.
par(mfrow = c(2, 3))
boxplot(red_wine$chlorides,
main = "Chlorides")
boxplot(red_wine$`residual sugar`,
main = "Residual Sugar")
boxplot(red_wine$sulphates,
main = "Sulphates")
boxplot(red_wine$`total sulfur dioxide`,
main = "Total Sulfur Dioxide")
boxplot(red_wine$`free sulfur dioxide`,
main = "Free Sulfur Dioxide")
par(mfrow = c(1, 1)) I do have some concerns due to the significant amount of outliers. There is also likely a significant data skew in many of these variables based on the plots.
How can you concisely summarize each variable? What statistics will you report?
To describe the variables, I would look at summary statistics such as the mean, median, standard deviation, min, and max. These could also help us flag outliers. You could also explore the quartiles to better understand the data.
summary_table <- data.frame(
Mean = sapply(red_wine, mean),
Median = sapply(red_wine, median),
SD = sapply(red_wine, sd),
Min = sapply(red_wine, min),
Max = sapply(red_wine, max)
)
summary_table Mean Median SD Min Max
fixed acidity 8.31963727 7.90000 1.741096318 4.60000 15.90000
volatile acidity 0.52782051 0.52000 0.179059704 0.12000 1.58000
citric acid 0.27097561 0.26000 0.194801137 0.00000 1.00000
residual sugar 2.53880550 2.20000 1.409928060 0.90000 15.50000
chlorides 0.08746654 0.07900 0.047065302 0.01200 0.61100
free sulfur dioxide 15.87492183 14.00000 10.460156970 1.00000 72.00000
total sulfur dioxide 46.46779237 38.00000 32.895324478 6.00000 289.00000
density 0.99674668 0.99675 0.001887334 0.99007 1.00369
pH 3.31111320 3.31000 0.154386465 2.74000 4.01000
sulphates 0.65814884 0.62000 0.169506980 0.33000 2.00000
alcohol 10.42298311 10.20000 1.065667582 8.40000 14.90000
quality 5.63602251 6.00000 0.807569440 3.00000 8.00000
Total sulfur dioxide shows large variability at the upper range of values. Comparing the mean at 46.47 and median at 38 shows larger differences than seen with other variables in the data set. The max also appears to be an outlier at 289, while the mean is only 46.47. A trimmed mean could be beneficial to report for data like this due to the outliers. Lastly, we see that the standard deviation is large when compared to the mean or median at 32.89.
On the other hand, for density, there is a much smalled spread in the data with the mean and median very close to eachother and a standard deviation of 0.002.
How can you visualize each variable’s distribution?
To visualize the distribution I would create histograms. See histograms below for all the variables.
par(mfrow = c(3, 4)) # set grid
for (i in 1:ncol(red_wine)) {
hist(red_wine[[i]],
main = names(red_wine)[i],
xlab = "",
col = "red",
border = "black",
breaks = 30)
}Do any variables appear skewed?
All the variables had a right skew except for density, pH, and quality based on the histograms. The 5 variables I flagged previously have the strongest skews; chlories, sulphates, residual sugar, free sulfur dioxide, and total sulfur dioxide.