Home » Mathematics » Computing Coefficient of Correlation: Calculation Process

Computing Coefficient of Correlation: Calculation Process

December 10, 2023 by JoyAnswer.org, Category : Mathematics

How do you calculate coefficient of correlation? Learn the process of calculating the coefficient of correlation. This article provides guidance on computing correlation coefficients between variables.

Computing Coefficient of Correlation: Calculation Process

How do you calculate coefficient of correlation?

The coefficient of correlation, often denoted as rr, is a statistical measure that quantifies the strength and direction of a linear relationship between two variables. There are different methods to calculate the coefficient of correlation, but one of the most common is Pearson's correlation coefficient. Here's how you can calculate it:

Pearson's Correlation Coefficient (rr):

Step 1: Understand the Formula:

The formula for Pearson's correlation coefficient is:

r=(XiXˉ)(YiYˉ)(XiXˉ)2(YiYˉ)2r = \frac{\sum{(X_i - \bar{X})(Y_i - \bar{Y})}}{\sqrt{\sum{(X_i - \bar{X})^2} \cdot \sum{(Y_i - \bar{Y})^2}}}


  • XiX_i and YiY_i are the individual data points.
  • Xˉ\bar{X} and Yˉ\bar{Y} are the means of the X and Y datasets, respectively.

Step 2: Calculate the Means:

Calculate the mean (Xˉ\bar{X}) and (Yˉ\bar{Y}) of the X and Y datasets.

Xˉ=Xin\bar{X} = \frac{\sum{X_i}}{n}Yˉ=Yin\bar{Y} = \frac{\sum{Y_i}}{n}

Where nn is the number of data points.

Step 3: Calculate the Numerator:

(XiXˉ)(YiYˉ)\sum{(X_i - \bar{X})(Y_i - \bar{Y})}

Subtract the mean of X from each data point in X, and the mean of Y from each data point in Y. Multiply these differences for each corresponding pair and sum them up.

Step 4: Calculate the Denominator:

(XiXˉ)2(YiYˉ)2\sqrt{\sum{(X_i - \bar{X})^2} \cdot \sum{(Y_i - \bar{Y})^2}}

Calculate the square of the differences between each data point and the mean for both X and Y. Sum these squared differences for each dataset and take the square root of the product of these sums.

Step 5: Calculate the Coefficient of Correlation:

r=NumeratorDenominatorr = \frac{\text{Numerator}}{\text{Denominator}}

Divide the numerator by the denominator to get the coefficient of correlation (rr).

Interpretation of rr:

  • r=1r = 1: Perfect positive correlation
  • r=1r = -1: Perfect negative correlation
  • r=0r = 0: No correlation


  • Pearson's correlation coefficient assumes a linear relationship. It may not accurately represent non-linear relationships.
  • This method is sensitive to outliers.

Computing the coefficient of correlation can be done using statistical software, spreadsheets, or programming languages like Python, R, or MATLAB, where built-in functions or libraries are available for such calculations.

What is the formula for computing the coefficient of correlation?

The formula for computing the Pearson correlation coefficient between two arrays x and y is:

correlation = covariance / (std_dev_x * std_dev_y)


  • covariance is the sum of the product of the centered data points, divided by the number of data points:
covariance = np.sum(centered_x * centered_y) / len(x)
  • centered_x is the array x with the mean subtracted from each element:
centered_x = x - np.mean(x)
  • centered_y is the array y with the mean subtracted from each element:
centered_y = y - np.mean(y)
  • std_dev_x is the standard deviation of the array x:
std_dev_x = np.std(x)
  • std_dev_y is the standard deviation of the array y:
std_dev_y = np.std(y)

Here is an example of how to calculate the correlation coefficient between two NumPy arrays:

import numpy as np

x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 5, 4, 3])

correlation = np.corrcoef(x, y)[0, 1]
Use code with caution. Learn more

This code outputs the following:


The correlation coefficient is a measure of the linear relationship between two variables. It is a number between -1 and 1, where:

  • -1 indicates a perfect negative correlation.
  • 0 indicates no linear correlation.
  • 1 indicates a perfect positive correlation.

Tags Coefficient of Correlation , Calculation Methodology

People also ask

  • How do you plot a polar graph?

    The center point of the graph (or "origin" in a rectangular grid) is the pole. You can label this with the letter O. Starting from the pole, draw a horizontal line to the right. This is the polar axis. ... If you have special polar graph paper, it will include many circles of different sizes, all centered on the pole. ...
    Learn the step-by-step process of plotting a polar graph. This guide provides clear instructions on creating a polar graph, helping you visualize and analyze mathematical data in a polar coordinate system. ...Continue reading

  • How do you determine whether a function is linear?

    If there exists only one real or complex solution of f ( x) + a for all real a. If f ( a + b) = f ( a) + f ( b) for all real a, b, and if c f ( x) = f ( c x) ... If the second derivative is 0. If the first derivative is constant. If there exist real numbers a, b such that f ( x) − ( a x + b) = 0 for all x.
    Learn how to determine whether a function is linear. This article provides insights into the key characteristics and tests used to identify linearity in mathematical functions. ...Continue reading

The article link is https://joyanswer.org/computing-coefficient-of-correlation-calculation-process, and reproduction or copying is strictly prohibited.