Skip to content

Commit 21944de

Browse files
basic commit
1 parent 8dd944a commit 21944de

File tree

103 files changed

+313110
-313110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+313110
-313110
lines changed

ISP/Figures/F6_6_sem.py

+88-88
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
1-
'''Scatterplot of normally distributed data, with Standard Deviation and Standard Error'''
2-
3-
# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License
4-
5-
# Import standard packages
6-
import numpy as np
7-
import matplotlib.pyplot as plt
8-
from scipy import stats
9-
import seaborn as sns
10-
11-
# additional packages
12-
# Import formatting commands if directory "Utilities" is available
13-
import os
14-
import sys
15-
sys.path.append(os.path.join('..', 'Code_Quantlets', 'Utilities'))
16-
try:
17-
from ISP_mystyle import setFonts, showData
18-
19-
except ImportError:
20-
# Ensure correct performance otherwise
21-
def setFonts(*options):
22-
return
23-
def showData(*options):
24-
plt.show()
25-
return
26-
27-
from F7_10_roc import arrow_bidir
28-
29-
# Generate the data
30-
np.random.seed(123)
31-
x = np.random.randn(100) + 5
32-
33-
# Calculate "standard devation" and "standard error" locations
34-
sdVal = np.std(x, ddof=1)
35-
seVal = stats.sem(x)
36-
sd = np.mean(x) + sdVal*np.r_[-1, 1]
37-
se = np.mean(x) + seVal*np.r_[-1, 1]
38-
39-
# Set up the plot
40-
sns.set_style('ticks')
41-
sns.set_context('poster')
42-
setFonts()
43-
44-
# Plot the data
45-
plt.plot(x,'.')
46-
plt.axhline(np.mean(x), color=0.7*np.ones(3))
47-
plt.axhline(sd[0], ls='--')
48-
plt.axhline(sd[1], ls='--')
49-
50-
# Lines for SEM
51-
lh = []
52-
lh.append( plt.axhline(se[0], ls='--', color='r') )
53-
lh.append( plt.axhline(se[1], ls='--', color='r') )
54-
55-
# make the lines long-dashed
56-
dashes = [20, 5] # 20 points on, 5 off
57-
for ii in range(len(lh)):
58-
lh[ii].set_dashes(dashes)
59-
60-
curAxis = plt.gca()
61-
curAxis.set_xticklabels( () )
62-
63-
# Make the arrows
64-
plt.arrow(10, np.mean(x), 0, sdVal,
65-
width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k')
66-
plt.arrow(10, np.mean(x), 0, -sdVal,
67-
width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k')
68-
69-
plt.arrow(35, np.mean(x)-4*seVal, 0, 3*seVal,
70-
width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k')
71-
plt.arrow(35, np.mean(x)+4*seVal, 0, -3*seVal,
72-
width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k')
73-
74-
#plt.text(10, 5.5, '$\pm$ 1SD', family='sans-seriv', fontsize=28)
75-
#plt.text(35, 5.2, '$\pm$ 1SEM', family='sans-seriv', fontsize=28)
76-
plt.text(10, 5.5, '$\pm$ 1SD', fontsize=28)
77-
plt.text(35, 5.2, '$\pm$ 1SEM', fontsize=28)
78-
plt.annotate('mean', (70,np.mean(x)),xycoords='data', fontsize=28,
79-
xytext=(75, 5.5), textcoords='data',
80-
arrowprops=dict(facecolor='black', shrink=0.05))
81-
82-
83-
# Add the text
84-
85-
86-
# Save and show
87-
outFile = ('standardError.png')
88-
showData(outFile)
1+
'''Scatterplot of normally distributed data, with Standard Deviation and Standard Error'''
2+
3+
# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License
4+
5+
# Import standard packages
6+
import numpy as np
7+
import matplotlib.pyplot as plt
8+
from scipy import stats
9+
import seaborn as sns
10+
11+
# additional packages
12+
# Import formatting commands if directory "Utilities" is available
13+
import os
14+
import sys
15+
sys.path.append(os.path.join('..', 'Code_Quantlets', 'Utilities'))
16+
try:
17+
from ISP_mystyle import setFonts, showData
18+
19+
except ImportError:
20+
# Ensure correct performance otherwise
21+
def setFonts(*options):
22+
return
23+
def showData(*options):
24+
plt.show()
25+
return
26+
27+
from F7_10_roc import arrow_bidir
28+
29+
# Generate the data
30+
np.random.seed(123)
31+
x = np.random.randn(100) + 5
32+
33+
# Calculate "standard devation" and "standard error" locations
34+
sdVal = np.std(x, ddof=1)
35+
seVal = stats.sem(x)
36+
sd = np.mean(x) + sdVal*np.r_[-1, 1]
37+
se = np.mean(x) + seVal*np.r_[-1, 1]
38+
39+
# Set up the plot
40+
sns.set_style('ticks')
41+
sns.set_context('poster')
42+
setFonts()
43+
44+
# Plot the data
45+
plt.plot(x,'.')
46+
plt.axhline(np.mean(x), color=0.7*np.ones(3))
47+
plt.axhline(sd[0], ls='--')
48+
plt.axhline(sd[1], ls='--')
49+
50+
# Lines for SEM
51+
lh = []
52+
lh.append( plt.axhline(se[0], ls='--', color='r') )
53+
lh.append( plt.axhline(se[1], ls='--', color='r') )
54+
55+
# make the lines long-dashed
56+
dashes = [20, 5] # 20 points on, 5 off
57+
for ii in range(len(lh)):
58+
lh[ii].set_dashes(dashes)
59+
60+
curAxis = plt.gca()
61+
curAxis.set_xticklabels( () )
62+
63+
# Make the arrows
64+
plt.arrow(10, np.mean(x), 0, sdVal,
65+
width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k')
66+
plt.arrow(10, np.mean(x), 0, -sdVal,
67+
width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k')
68+
69+
plt.arrow(35, np.mean(x)-4*seVal, 0, 3*seVal,
70+
width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k')
71+
plt.arrow(35, np.mean(x)+4*seVal, 0, -3*seVal,
72+
width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k')
73+
74+
#plt.text(10, 5.5, '$\pm$ 1SD', family='sans-seriv', fontsize=28)
75+
#plt.text(35, 5.2, '$\pm$ 1SEM', family='sans-seriv', fontsize=28)
76+
plt.text(10, 5.5, '$\pm$ 1SD', fontsize=28)
77+
plt.text(35, 5.2, '$\pm$ 1SEM', fontsize=28)
78+
plt.annotate('mean', (70,np.mean(x)),xycoords='data', fontsize=28,
79+
xytext=(75, 5.5), textcoords='data',
80+
arrowprops=dict(facecolor='black', shrink=0.05))
81+
82+
83+
# Add the text
84+
85+
86+
# Save and show
87+
outFile = ('standardError.png')
88+
showData(outFile)

ISP/Figures/F6_7_skewness.py

+70-70
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
''' Example for Skewness and Kurtosis '''
2-
3-
# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License
4-
5-
# Import standard packages
6-
import numpy as np
7-
import scipy.stats as stats
8-
import matplotlib.pyplot as plt
9-
import os
10-
import seaborn as sns
11-
12-
# additional packages
13-
from matplotlib.mlab import frange
14-
15-
# Import formatting commands if directory "Utilities" is available
16-
import os
17-
import sys
18-
sys.path.append(os.path.join('..', 'Code_Quantlets', 'Utilities'))
19-
try:
20-
from ISP_mystyle import showData
21-
22-
except ImportError:
23-
# Ensure correct performance otherwise
24-
def showData(*options):
25-
plt.show()
26-
return
27-
28-
sns.set(context='poster', style='ticks', palette='deep')
29-
30-
def skewness(ax):
31-
'''Normal and skewed distribution'''
32-
33-
t = frange(-6,10,0.1) # generate the desirded x-values
34-
normal = stats.norm.pdf(t,1,1.6)
35-
chi2 = stats.chi2.pdf(t,3)
36-
37-
ax.plot(t, normal, '--', label='normal')
38-
ax.plot(t, chi2, label='positive skew')
39-
ax.xaxis.set_ticks_position('bottom')
40-
ax.yaxis.set_ticks_position('left')
41-
ax.legend()
42-
43-
def kurtosis(ax):
44-
''' Distributions with different kurtosis'''
45-
46-
# Generate the data
47-
t = frange(-3,3,0.1) # generate the desirded x-values
48-
platykurtic = stats.laplace.pdf(t)
49-
50-
wigner = np.zeros(np.size(t))
51-
wignerIndex = np.abs(t) <= 1
52-
wigner[wignerIndex] = 2/np.pi * np.sqrt(1-t[wignerIndex]**2)
53-
54-
ax.plot(t, platykurtic, label='kurtosis=3')
55-
ax.plot(t, wigner, '--', label='kurtosis=-1')
56-
ax.xaxis.set_ticks_position('bottom')
57-
ax.yaxis.set_ticks_position('left')
58-
ax.legend()
59-
60-
if __name__=='__main__':
61-
# Make 2 plots, side-by-side
62-
fig, axs = plt.subplots(1,2)
63-
64-
# In the first plot demonstrate "skewness", in the second plot "kurtosis"
65-
skewness(axs[0])
66-
kurtosis(axs[1])
67-
68-
# Save and show
69-
outFile = 'Skewness.png'
70-
showData(outFile)
1+
''' Example for Skewness and Kurtosis '''
2+
3+
# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License
4+
5+
# Import standard packages
6+
import numpy as np
7+
import scipy.stats as stats
8+
import matplotlib.pyplot as plt
9+
import os
10+
import seaborn as sns
11+
12+
# additional packages
13+
from matplotlib.mlab import frange
14+
15+
# Import formatting commands if directory "Utilities" is available
16+
import os
17+
import sys
18+
sys.path.append(os.path.join('..', 'Code_Quantlets', 'Utilities'))
19+
try:
20+
from ISP_mystyle import showData
21+
22+
except ImportError:
23+
# Ensure correct performance otherwise
24+
def showData(*options):
25+
plt.show()
26+
return
27+
28+
sns.set(context='poster', style='ticks', palette='deep')
29+
30+
def skewness(ax):
31+
'''Normal and skewed distribution'''
32+
33+
t = frange(-6,10,0.1) # generate the desirded x-values
34+
normal = stats.norm.pdf(t,1,1.6)
35+
chi2 = stats.chi2.pdf(t,3)
36+
37+
ax.plot(t, normal, '--', label='normal')
38+
ax.plot(t, chi2, label='positive skew')
39+
ax.xaxis.set_ticks_position('bottom')
40+
ax.yaxis.set_ticks_position('left')
41+
ax.legend()
42+
43+
def kurtosis(ax):
44+
''' Distributions with different kurtosis'''
45+
46+
# Generate the data
47+
t = frange(-3,3,0.1) # generate the desirded x-values
48+
platykurtic = stats.laplace.pdf(t)
49+
50+
wigner = np.zeros(np.size(t))
51+
wignerIndex = np.abs(t) <= 1
52+
wigner[wignerIndex] = 2/np.pi * np.sqrt(1-t[wignerIndex]**2)
53+
54+
ax.plot(t, platykurtic, label='kurtosis=3')
55+
ax.plot(t, wigner, '--', label='kurtosis=-1')
56+
ax.xaxis.set_ticks_position('bottom')
57+
ax.yaxis.set_ticks_position('left')
58+
ax.legend()
59+
60+
if __name__=='__main__':
61+
# Make 2 plots, side-by-side
62+
fig, axs = plt.subplots(1,2)
63+
64+
# In the first plot demonstrate "skewness", in the second plot "kurtosis"
65+
skewness(axs[0])
66+
kurtosis(axs[1])
67+
68+
# Save and show
69+
outFile = 'Skewness.png'
70+
showData(outFile)

0 commit comments

Comments
 (0)