Last updated: 09:53:12 IST, 24 August, 2023

Decision Scenario

In the standard ‘cars’ dataset, check if there is any correlation between the ‘speed’ and the ‘dist’ variables.

Solution Approach

Check summary, scatter plot and do a correlation test using ‘pearson’ method.

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
plot(cars$speed,cars$dist)

# Test for correlation using 'pearson' method.
cor_res <- cor.test(x=cars$speed, y=cars$dist,method='pearson')
cor_res
## 
##  Pearson's product-moment correlation
## 
## data:  cars$speed and cars$dist
## t = 9.464, df = 48, p-value = 1.49e-12
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.6816422 0.8862036
## sample estimates:
##       cor 
## 0.8068949