# How to calculate r

The correlation coefficient, commonly denoted as “r,” is a statistical measure that describes the strength and direction of a linear relationship between two variables. In this article, we will go through the steps of calculating r, using the Pearson correlation coefficient method.

**Step 1: Understand the Pearson correlation coefficient**

The Pearson correlation coefficient ranges from -1 to 1, where -1 indicates a strong negative relationship, 1 indicates a strong positive relationship, and 0 indicates no relationship between the two variables. The closer r is to either -1 or 1, the stronger the linear relationship between the variables.

**Step 2: Gather data**

First, you must have data points for your two variables (x and y). The data should be in pairs (x₁,y₁), (x₂,y₂), … , (xₙ,yₙ), where n is the number of observations.

**Step 3: Calculate means and standard deviations of variables**

Calculate the mean of both x (mean_x) and y (mean_y) values using the following formula:

mean_x = Σx / n

mean_y = Σy / n

Next, calculate the standard deviations for both x (std_x) and y (std_y) using:

std_x = sqrt(Σ(x – mean_x)² / n)

std_y = sqrt(Σ(y – mean_y)² / n)

**Step 4: Compute deviations from means**

For each observation, compute deviations from their respective means for both x and y:

dev_x = x – mean_x

dev_y = y – mean_y

**Step 5: Calculate r**

Now, we’re ready to calculate r. Use the following formula:

r = Σ(dev_x * dev_y) / sqrt(Σ(dev_x²) * Σ(dev_y²))

Here’s a step-by-step process:

1. Multiply each pair of deviations: dev_x * dev_y.

2. Sum the results from step 1.

3. Square each deviation from step 4: dev_x² and dev_y².

4. Sum the squared deviations separately: Σ(dev_x²) and Σ(dev_y²).

5. Multiply these sums together: Σ(dev_x²) * Σ(dev_y²).

6. Take the square root of the product in step 5: sqrt(Σ(dev_x²) * Σ(dev_y²)).

7. Divide the sum from step 2 by the result in step 6: Σ(dev_x * dev_y) / sqrt(Σ(dev_x²) * Σ(dev_y²)).

**Conclusion**

Congratulations, you have now calculated r, the correlation coefficient that represents the strength and direction of a linear relationship between two variables! Remember that interpreting r begins by looking at its sign (+ or -), which indicates a positive or negative relationship, while the closer the absolute value of r is to 1, the stronger the relationship between variables.