2025-06-08

Importing Data and R set up

white_wine <- read.csv("winequality-white.csv", sep = ";", header = T)

red_wine <- read.csv("winequality-red.csv", sep = ";", header = T)

red_wine$wine_type <- "Red"

white_wine$wine_type <- "White"

combined_wine <- rbind(red_wine, white_wine)

The above code loads in two data sets that we will be exploring statistics with. The data set: “Wine Quality”, By P. Cortez, A. Cerdeira, Fernando Almeida, Telmo Matos, J. Reis. 2009 can be found on the UC Irvine Machine Learning Repository. We are also going to combine them into 1 data set, to make comparisons easier.

Data Check

## There are a total of  0  NA's in the Wine dataset
## 
## FALSE  TRUE 
##  5320  1177

There are some apparent duplicated values in our datasets and no missing values. Even though there are no unique identifiers to verify if they are true duplicates or not, we will still clean the data sets of them.

combined_wine <- unique(combined_wine)

Selecting Predictor Variables

When making a linear regression model, it helps to first graph some variables to get a “gut” feeling about whether they will be strong predictor variables.

We are going to graph 2 different predictor variables, alcohol and residual sugar, to see if they might have promise to help us build a model to predict the rating of a wine.

We want to see if alcohol has a correlation to the quality rating. So first, let’s see if the graph looks promising.

There seems to be a correlation with alcohol content and rating, hopefully a t-value will confirm this.

Next, we would like to get a visualization if there might be a correlation between residual sugar levels and the quality rating of wine. The graph isn’t promising, but let’s go ahead and see if the wine types different medians in average quality.

Code for Boxplot of Median Wine Ratings

ggplot(combined_wine, aes(x = wine_type, y = quality, fill = wine_type)) +
  geom_boxplot() +
  stat_summary(fun = mean, geom = "crossbar", width = .75, color = "black") +
  labs(title = "Quality Ratings of Red and White Wine",
       x = "Wine Type",
       y = "Quality Rating (0-10)") +
  theme_minimal()

Resulting Boxplot

Both wine types have similar median ratings, with White Wines having a slightly higher median.

Linear Regression of the Quality of Wine

We are going to attempt to fit a linear model to see if alcohol content and residual sugar are good predictors of a wines quality rating. The function lm() in R uses the formula: \[y \sim alcohol + residual.sugar\]
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.8002 0.1040 17.3058 0
alcohol 0.3698 0.0094 39.4132 0
residual.sugar 0.0186 0.0025 7.5376 0

We can see that both alcohol and residual sugar are good predictors of wine quality, regardless of wine type due to their T values.

Explanation of T Values

When examining a linear regression model, the t-value measures the strength of a predictor variable.

The formula for a t-value is: \[t = \frac{\hat{\beta} - 0}{\text{SE}(\hat{\beta})}\] The higher the t-value, the stronger the predictor variable is. Out of alcohol content and residual sugar (for both types of wine), alcohol content is the stronger predictor variable.

Citations

Cortez, P., Cerdeira, A., Almeida, F., Matos, T., & Reis, J. (2009). Wine Quality [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C56S3T.