Section 8.6 Understanding Correlation
Before we get to a linear regression, it is best to first understand how (if at all) our variables are correlated with each other. For a review on correlation, go back to SectionΒ 7.1 of the textbook.
We are first trying to figure out what variables, if any, should be included in our linear regression model, and this is exactly where correlation comes into play.
cor.test(pizza_sales$volume,pizza_sales$price)
Pearson's product-moment correlation
data: pizza_sales$volume and pizza_sales$price
t = -10.8, df = 154, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.7375315 -0.5567684
sample estimates:
cor
-0.6564736
When we run a correlation, we are looking for three things:
-
The direction: is a positive or negative interaction?
-
The strength: how close is it to -1, 0, 1?
-
The p-value: Is it statistically significant?
The code above answers all three questions:
-
The direction: is negative.
-
The strength: about β0.66, indicating a moderately strong negative correlation.
-
The p-value: < 0.05 indicates that the relationship between price and volume is unlikely due to chance.
With a correlation coefficient of -0.66, we have a moderately strong negative correlation between price and volume. As price goes up, volume goes down - just what we saw in our graphs!
