Hello and welcome to a module on Pearson correlations. First, let's load in our data and the packages we'll be using today.
So we'll be importing Pandas as PD, Drive from Google.colab, numpy as np,
mapplotlib.pyplot as PLT and we'll be importing pearsonr from scipy.stats.
We'll be doing some scatter plots today, so that's why we've got matplotlib imported.
So let's go ahead and create our variables for the class data set. This should look very familiar.
Okay, and these are variables that we're used to seeing by now, and we know how these variables were created. So we're aware that
there are relationships between IV1, IV2, DV, and the rest of these variables here. So let's
investigate those relationships and see how closely related these variables actually are. Let's calculate
the Pearson correlation between IV2 and RDV. In another video, we created a scatter plot between
those two variables. Let's do that again and take a look. So we're going to create a scatter plot between
IV2 and RDB, create our line of best fit, and then actually produce our
scatter plot, label it, title it, and show it. If you need a review on how to do that,
go visit the scatter plot video to see more. So looking at this
scatter plot, we can see that our line is not completely flat, and it's not negative,
so we have a positive correlation here, but it's maybe not a very strong positive correlation. We might
guess that it's going to be moderate in size, which I already know what it's going to be, so
my guess is a very good guess. But judging from our trend line, we might expect to see a moderate positive
correlation between these two variables. Let's check with a Pearson calculation to see if that is the case.
So here, we are giving Python two values to put our functions
returns in because we know that we're going to get two returns
from this function. We're going to give it two arguments, RIV-2 and RDV.
It doesn't really matter what order you do them in, so long as they are both there.
Next, we'll be calculating the T value using this correlation coefficient up here that we've already
run. So N is equal to the length of DF. This is just returning how many data points are
in our data frame. Len is short for length. Our T value is calculated
using this formula, which uses the correlation coefficient, and next we're
going to print the results. Okay,
so we can see that we do have a moderate positive correlation between these two
because we have a point .3246. So let's do this again for some of our other variables.
What about the relationship between RIV1 and two IVs? Remember, two IVs was created
by multiplying RIV1 and RIV2. So we should expect to see a pretty strong correlation
here because the two are so highly related. Let's check out a visualization of this relationship by making a scatter
plot first. So just as before, we'll make our scatter plot. I'll go ahead and run this. And
yeah, we can see now our line looks very different. It's almost completely diagonal
and our scatter - our points - are spread very closely around
the line. So up here, we can see that things were spread out quite a bit more. Our line isn't
quite as diagonal and here we have a very different looking graph.
So it looks like a very strong correlation. Let's see if that's the case by running a Pearson correlation.
So just as above, we did all the same things, we just used two different variables this time. And we have a Pearson correlation
coefficient of 0.9303. That's pretty strong. And we should expect it again because
those two variables are so highly related since one is a transformation of the other. All right.
That's it for Pearson correlation coefficients. Happy coding!