Correlation and standard deviation If the standard deviation of x, sd(x), increases, the correlation cor(x,y) increases as well. Why? If the standard deviation increases 10%, the correlation increases 10% as well. Why?
 A: It depends on how you increase the standard deviation. Typically, when some process increases the standard deviation of $x$ then the correlation decreases. But there are many variations

*

*Decreasing correlation when you increase the standard deviation of $x$ by adding some extra noise to it.


*Equal correlation when you scale the $x$ variable while keeping $y$ the same.


*Increasing correlation if you increase the standard deviation of $x$ by adding/subtracting a positive/negative correlated $y$ variable to it.

layout(matrix(1:4,2))
par(mar = c(5,5,1,1))

### create data
n = 300
set.seed(1)
xy = MASS::mvrnorm(n, mu = c(0,0), Sigma = matrix(c(1,0.62,0.62,1),2))
x = xy[,1]
y = xy[,2]
noise = rnorm(n, mean = 0, sd = sqrt(2.24))

plot(x,y, xlim = c(-3.5,3.5), ylim = c(-3.5,3.5), pch = 20, main = "original")
plot(x+noise,y, xlim = c(-3.5,3.5), ylim = c(-3.5,3.5), pch = 20, main = "less correlation")
plot(x+y,y, xlim = c(-3.5,3.5), ylim = c(-3.5,3.5), pch = 20, main = "more correlation")
plot(1.8*x,y, xlim = c(-3.5,3.5), ylim = c(-3.5,3.5), pch = 20, main = "same correlation")

A: Pearson's R Correlation
Let's say we are using a Pearson correlation as an example, the formula for deriving r is as follows:
$$
r = \frac{\Sigma(x_i-\bar{x})(y_i-\bar{y})}{\sqrt{\Sigma(x_i-\bar{x})^2\Sigma(y_i-\bar{y})^2}}
$$
You can see at the bottom of the formula that this correlation requires the sum of squares for each variable. Variance is the average of the sum of squares and of course standard deviation is the  square root of this variance. Hence if one variable fluctuates in ways dissimilar to the other, it will directly affect the outcome.
Simulate Correlation
We can simulate this in R by creating a strong correlation of values, then slightly alter the last units to cause a shift in variance. I have also fit regression lines just to visualize what this does in terms of the squared distances away from the distribution of data. First, I create an x and y with 5 values each.
#### Simulate Strong Negative Correlation ####
x1 <- c(20,30,40,30,10)
y1 <- c(40,20,10,30,50)

You can check their standard deviation below:
sd(x1)
sd(y1)

You will see their SD is 11.40 and 15.81 respectively. We can then craft a Pearson correlation by hand like so:
mean.x1 <- mean(x1)
mean.y1 <- mean(y1)
numerator <- sum((x1-mean.x1)*(y1-mean.y1))
denominator <- sqrt(sum((x1-mean.x1)^2)*sum((y1-mean.y1)^2))
pearson <- numerator/denominator
pearson

Or simply use this function:
cor(x1,y1)

The correlation for each will be the same ($r$ = -.97). We can plot this using the code below, along with a regression line to show how much our data points deviate from the line:
plot(x1,y1,col="blue")
title("Pearson r = -.97")
fit1 <- lm(y1~x1)
abline(fit1, 
       col = "red")


Alter Standard Deviation
To show how standard deviation affects correlation, we have to use a method that doesn't apply a constant to all the values, but will shift the standard deviation in a way that doesn't completely alter the relationship the original values had. To do so, we can simply double the last two units of x and y, which will change the standard deviation of each.
#### Double Last Units to Modify Variance ####
x2 <- c(20,30,40,30,20)
y2 <- c(40,20,10,30,100)
sd(x2)
sd(y2)

You will now see the SD has decreased for x2 (8.37) and increased for y2 (35.36). We can then repeat the same steps for these two variables.
mean.x2 <- mean(x2)
mean.y2 <- mean(y2)
numerator <- sum((x2-mean.x2)*(y2-mean.y2))
denominator <- sqrt(sum((x2-mean.x2)^2)*sum((y2-mean.y2)^2))
pearson <- numerator/denominator
pearson
cor(x2,y2)
plot(x2,y2,col="blue")
title("Pearson r = -.76")
fit2 <- lm(y2~x2)
abline(fit2, 
       col = "red")


You will see that just doubling the last values shifts the linearity of the distribution and the correlation is less clean now, hence a lower value.
