When we try to infer something from what we have heard or read, the first step we do is relate a few of the parameters or scenes, etc. with each other and then proceed. Correlation means to find out the association between the two variables and Correlation coefficients are used to find out how strong the is relationship between the two variables. The most popular correlation coefficient is Pearson’s Correlation Coefficient. It is very commonly used in linear regression.
This article was published as a part of the Data Science Blogathon.
Pearson’s Correlation Coefficient, often denoted as r, measures the strength and direction of a linear relationship between two continuous variables. It ranges from -1 to 1, where:
Consider the example of car price detection where we have to detect the price considering all the variables that affect the price of the car such as carlength, curbweight, carheight, carwidth, fueltype, carbody, horsepower, etc.
Correlation can be found out between continuous variables using python:
We can see in the above scatterplot, as the carlength, curbweight, carwidth increases price of the car also increases. So, we can say that there is a positive correlation between the above three variables with car price. Here, we also see that there is no correlation between the carheight and car price.
Cars with high prices have very low mileage as compared to the low range of cars. Hence, in this case, we can say that there is a negative correlation between car price and mileage.
Value of ‘r’ ranges from ‘-1’ to ‘+1’. Value ‘0’ specifies that there is no relation between the two variables. A value greater than ‘0’ indicates a positive relationship between two variables where an increase in the value of one variable increases the value of another variable. Value less than ‘0’ indicates a negative relationship between two variables where an increase in the value of one decreases the value of another variable.
Pearson correlation draws a line of best fit through two variables, indicating the distance of data points from this line. A ‘r’ value near +1 or -1 implies all data points are close to the line. An ‘r’ value close to ‘0’ suggests data points are scattered around the line.
Considering the same example of the car price, let’s find out the ‘r’ value using ‘pearsonr’ function in python.
As stated earlier, the value of Pearson correlation for Price vs Curbweight is 0.835 and as there is no correlation between Price and Carheight, hence the Pearson Correlation value between Price & Carheight is near to 0 which is 0.12.
Understanding Pearson’s Correlation Coefficient is foundational for anyone delving into statistics or data analysis. This guide has demystified the calculation and interpretation of r, offering insights into the strength and direction of linear relationships between variables. Armed with this knowledge, beginners can make informed decisions about data relationships. As a widely used statistical tool, Pearson’s Correlation Coefficient provides a valuable entry point into quantitative analysis, unlocking possibilities for deeper exploration and comprehension of data patterns. Embrace the power of correlation to unravel meaningful insights from your datasets.
A. Calculate covariance, standard deviation for each variable, and then divide covariance by the product of standard deviations. This standardized measure gauges the strength and direction of the linear relationship.
A. In Excel, use =CORREL(array1, array2)
. This formula quickly provides the Pearson correlation coefficient (r) for assessing the relationship between datasets.
A. In R, use the cor()
function with numeric vectors x
and y
. It returns the Pearson correlation coefficient, leveraging R’s statistical capabilities.
A. Ranges from -1 to 1. Positive values indicate a positive correlation, negative values imply the opposite. Values closer to 1 or -1 signify stronger correlation, while around 0 suggests weak or negligible correlation.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,