File:Correlation range dependence.svg

Summary

Description
English: Plot depicting how various measures of association are affected when the range of a quantitative variable is limited.
Date
Source Own work
Author Skbkekas
SVG development
InfoField
 
The SVG code is valid.
 
This plot was created with Matplotlib.
Category:Valid SVG created with Matplotlib code#Correlation%20range%20dependence.svg
 
The file size of this SVG plot may be irrationally large because its text has been converted to paths inhibiting translations.
Category:Path text SVG
Source code
InfoField

Python code

import numpy as np
import matplotlib.pyplot as plt

r = 0.9
X = np.random.normal(size=100)
Y = r*X + np.sqrt(1-r**2)*np.random.normal(size=100)

ii = np.flatnonzero( (X>0) * (X<1) )

XR = np.argsort(np.argsort(X))
YR = np.argsort(np.argsort(Y))

def pearson(X,Y):
    cc = np.cov(X,Y)
    return cc[0,1]/np.sqrt(cc[0,0]*cc[1,1])

r1 = pearson(X, Y)
r2 = pearson(X[ii], Y[ii])

s1 = pearson(XR, YR)
s2 = pearson(XR[ii], YR[ii])

plt.clf()
plt.hold(True)
plt.figure(figsize=(5,4))
plt.axes([0.13,0.13,0.8,0.8])
plt.fill((0,1,1,0,0), (-3,-3,3,3,-3), 'lightgrey', ec='lightgrey')
a = plt.plot(X, Y, 'o', color='orange')
b = plt.plot(X[ii], Y[ii], 'o', color='lightblue')
plt.xlim(-3,3)
plt.ylim(-3,3)
plt.xlabel("X", size=18)
plt.ylabel("Y", size=18)
bx = plt.legend((a,b), ["%.2f/%.2f" % (r1,s1), "%.2f/%.2f" % (r2,s2)],\
                'upper left', numpoints=1, handletextpad=0.00001)
bx.draw_frame(False)
plt.savefig("correlation_range_dependence.pdf")
plt.savefig("correlation_range_dependence.svg")

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
Category:CC-BY-3.0#Correlation%20range%20dependence.svg
Category:Self-published work Category:Correlation Category:Scatterplots
Category:CC-BY-3.0 Category:Correlation Category:Path text SVG Category:Scatterplots Category:Self-published work Category:Valid SVG created with Matplotlib code