Let's draw non-correlated values

The values are independently drawn from uniform random distributions


In [1]:
# ==  Basic import == #
# plot within the notebook
%matplotlib inline
# No annoying warnings
import warnings
warnings.filterwarnings('ignore')

In [32]:
import numpy as np

In [ ]:
x = np.random.rand(200)
y = np.random.rand(200)

See how it looks like


In [34]:
import matplotlib.pyplot as mpl
mpl.plot(x,y, ls="None",marker="s",ms=15, mfc="None")


Out[34]:
[<matplotlib.lines.Line2D at 0x108844290>]

Now let's create a variable that depends on x "z" plus some other random distribution (noise or other dependency)


In [36]:
z = x*3 + np.random.normal(0,scale=0.3,size=200)

In [37]:
mpl.plot(x,z, ls="None",marker="s",ms=15, mfc="None")


Out[37]:
[<matplotlib.lines.Line2D at 0x108937fd0>]

And measure the Pearson Correlation coefficient


In [38]:
from scipy import stats

First value rho, second p-value (see future lesson)


In [39]:
stats.pearsonr(x,y)


Out[39]:
(-0.0421453339804998, 0.55348068796395489)

In [40]:
stats.pearsonr(x,z)


Out[40]:
(0.94483025261099896, 6.3845709192655321e-98)

In [ ]: