Beginner’s Guide to Pearson’s Correlation Coefficient
This article was published as a part of the Data Science Blogathon.
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.
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.
Let’s focus on some statistical explanation of it. Pearson’s Correlation coefficient is represented as ‘r’, it measures how strong is the linear association between two continuous variables using the formula:
Values of Pearson’s Correlation are:
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 attempts to draw a line of best fit through the spread of two variables. Hence, it specifies how far away all these data points are from the line of best fit. Value of ‘r’ equal to near to +1 or -1 that means all the data points are included on or near to the line of best fit respectively. Value of ‘r’ closer to the ‘0’ data points is around the line of best fit.
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.
Assumptions for a Pearson Correlation:
1. Data should be derived from random or least representative samples, draw a meaningful statistical inference.
2. Both variables should be continuous and normally distributed.
3. There should be Homoscedasticity, which means the variance around the line of best fit should be similar.
4. Extreme outliers influence the Pearson Correlation Coefficient. You need to consider outliers that are unusual only on one variable, called as ‘univariate variable’ or for both of the variables known as ‘multivariate outliers’. 2 variables are measured independently from each other pairs. e.g. If we plot age vs amount then, we can certainly, see that there is a correlation between the age of a person and loan the amount is given to that person, as age increases the loan amount given to the
person decreases and vice versa. But if we plot the loan amount vs age, it is not possible to draw any conclusion from it. It would violate the assumption.
Leave a Reply Your email address will not be published. Required fields are marked *