Research Question

Does the fuel efficiency of a car relate to its weight?

  • Dataset: mtcars, built into R.
  • Sample: 32 car models.
  • Explanatory Variable: Weight (wt), measured in 1,000 pounds.
  • Response Variable: Fuel Efficiency (mpg), measured in miles per US gallon.

Research Question: Do heavier cars have a lower fuel efficiency?

What is Correlation?

Pearson’s correlation measures the direction and strength of the linear relationship between two variables.

\[ -1 \leq r \leq 1 \]

  • \(r>0\): Positive relationship
  • \(r<0\): negative relationship
  • \(r\approx0\): Little linear relationship

The Mathematics

Pearson’s correlation coefficient:

\[ r= \frac{\sum (x_i-\bar{x})(y_i-\bar{y})} {\sqrt{\sum(x_i-\bar{x})^2\sum(y_i-\bar{y})^2}} \]

For the question, X is the car weight and Y is fuel efficiency.

If there is or is not a correlation between the data then: \[ H_0:\rho=0 \qquad H_A:\rho\neq0 \]

If p is equal to 0 then there is no linear correlation but if there is a number then there is a linear correlation.

Visualization 1: Scatterplot

Interpretation: The negative trend seems to suggest that the heavier a car is the lower the MPG.

Correlation and Significance

cat("Pearson correlation:", round(r, 3), "\n")
## Pearson correlation: -0.868
cat("P-value:", format.pval(p, digits = 3), "\n")
## P-value: 1.29e-10
if (p < 0.05) {
  cat("Conclusion: Reject the null hypothesis at the 5% level.")
} else {
  cat("Conclusion: Fail to reject the null hypothesis.")
}
## Conclusion: Reject the null hypothesis at the 5% level.
  • Negative correlation: Heavier cars tend to have lower fuel efficiency(MPG).
  • A p-value below 0.05 suggests there is evidence of a linear relationship between car weight and MPG.

Visualization 2: Distribution of MPG

Interpretation: This shows the fuel efficiency varying across the 32 cars and helps us to understand data besides just the correlation coefficient.

Interactive Visualization

Interpretation: Shows the exact points for each car with their MPG, Weight, and car name to better understand their specifications.

Conclusion

  • Car weight and MPG have a negative linear association in mtcars dataset.
  • Correlation test shows that there is association between car weight and MPG and that there is evidence of a linear relationship to show there is correlation.
  • There is also the possibility of other variables such as engines that may play a role in fuel efficiency besides just the weight.

Final Takeaway: Heavier cars in the mtcars dataset tend to have lower fuel efficiency, but there is the possibility of other variables besides just weight effecting it.