Z-Score Part 2
Solution
Solution
Starting Equation
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y}}{\sqrt{\Sigma (x-\overline{x})^2 \Sigma (y-\overline{y})^2}}$$
Step 1
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y})}{\sqrt{ \Sigma (x-\overline{x})^2} \sqrt{ \Sigma (y-\overline{y})^2}}$$
Step 2 (Look at Variance Equation)
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y})}{\sqrt{ n\sigma_{y}^2} \sqrt{ n\sigma_{y}^2}}$$
Step 3
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y})}{n\sigma_{y} \sigma_{y}}$$
Step 4
$$r_{xy} = \frac{\Sigma z_{x}z_{y}}{n} $$
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y}}{\sqrt{\Sigma (x-\overline{x})^2 \Sigma (y-\overline{y})^2}}$$
Step 1
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y})}{\sqrt{ \Sigma (x-\overline{x})^2} \sqrt{ \Sigma (y-\overline{y})^2}}$$
Step 2 (Look at Variance Equation)
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y})}{\sqrt{ n\sigma_{y}^2} \sqrt{ n\sigma_{y}^2}}$$
Step 3
$$r_{xy} = \frac{\Sigma (x-\overline{x}) (y-\overline{y})}{n\sigma_{y} \sigma_{y}}$$
Step 4
$$r_{xy} = \frac{\Sigma z_{x}z_{y}}{n} $$
Let’s check with programming.
z1 = (xVals-xVals.mean())/xVals.std()
z2 = (yVals-yVals.mean())/yVals.std()
print(sum(z1*z2)/(100))
print(np.corrcoef(xVals,yVals)[0][1])
At this time, we will also explain what covariance is, and how is relates to the above equation.
Equation
$$ Cov_{x,y} = \frac{\Sigma (x_i-\overline{x})(y_i-\overline{y})}{n} $$
This equation describes the way in which the variances of two variables move together, but not in a normalized way. You’ll notice that the normalized way is our correlation which divides covariance by the standard deviation of both variables.
Equation
$$ r_{x,y} = \frac{Cov_{x,y} }{\sigma_{x}\sigma_{y}}$$