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.