#load data
source = "https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv"
data = read.delim(source, sep=';')
colnames(data)
##  [1] "fixed.acidity"        "volatile.acidity"     "citric.acid"         
##  [4] "residual.sugar"       "chlorides"            "free.sulfur.dioxide" 
##  [7] "total.sulfur.dioxide" "density"              "pH"                  
## [10] "sulphates"            "alcohol"              "quality"
#Get independent variables
sugar_mean = mean(data$residual.sugar)
sulfate_mean = mean(data$sulphates)

data$High_Sugar = data$residual.sugar > sugar_mean
data$High_Sulfates = data$sulphates > sulfate_mean
#Create linear regression
linear_model =lm(quality ~ pH  + High_Sulfates + High_Sugar, data=data)
res = resid(linear_model)

par(mfrow=c(2,2))
plot(linear_model)

summary(linear_model)
## 
## Call:
## lm(formula = quality ~ pH + High_Sulfates + High_Sugar, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.9716 -0.4278  0.0074  0.5814  2.5909 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        5.86101    0.41714  14.050   <2e-16 ***
## pH                -0.13127    0.12483  -1.052    0.293    
## High_SulfatesTRUE  0.55430    0.03912  14.169   <2e-16 ***
## High_SugarTRUE    -0.03838    0.04312  -0.890    0.374    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7605 on 1595 degrees of freedom
## Multiple R-squared:  0.1148, Adjusted R-squared:  0.1131 
## F-statistic: 68.95 on 3 and 1595 DF,  p-value: < 2.2e-16
plot(data$pH ~ data$quality, ylab="pH", xlab="quality",main="Wine Information")

Analysis: The P Value is VERY small, which implies that there IS a correlation between ph, high sugar, and high sulfates, and quality of wine. However, looking at the plot of quality and ph, there isn’t really any noticable correlation. The QQ has a somewhat normal distribution which is good, but the RVL plot shows signs of heteroskedasticity. Because quality of wine is discrete and not continious, I don’t think using a linear model was a good tool for testing correlation for this data value in this dataset.