``````

In [1]:

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as pylab
from math import sqrt
import scipy.stats
#matplotlib inline

def stats(x):
print('min/max: {0} {1}'.format(min(x), max(x)))
print('moy +- ecart-type: {0} {1}'.format(np.mean(x), np.std(x)))# ddof=1
print('skewness / kurtosis: {0} {1}'.format(scipy.stats.skew(x), scipy.stats.kurtosis(x)))

``````

Statistiques descriptives

``````

In [2]:

vitesses = 3.6*np.loadtxt('donnees/vitesses-bt-b-a.txt') # en km/h
plt.figure()
plt.plot(vitesses,'.')
plt.ylabel('Vitesse (km/h)')

plt.figure()
plt.boxplot(vitesses)
plt.ylabel('Vitesse (km/h)')

plt.figure()
plt.hist(vitesses,20)
plt.xlabel('Vitesse (km/h)')
#plt.show()
stats(vitesses)

``````
``````

min/max: 19.5052248 147.3157908
moy +- ecart-type: 95.02027787226386 22.886233067266073
skewness / kurtosis: -0.8628733119651851 0.24283993707816043

``````
``````

In [3]:

# distribution avec une valeur aberrante (ou atypique)
x = [100]*100
x[99]=10

plt.boxplot(x)
plt.ylim((0,110))

``````
``````

Out[3]:

(0, 110)

``````

Intervalles de confiance

``````

In [4]:

# observation que les intervalles de confiance contiennent la vraie moyenne que dans un certains pourcentage des cas
normal = scipy.stats.norm()
n = 10
plt.figure()
means = []
meanStd = []
for i in range(20):
x=normal.rvs(n)
means.append(x.mean())
meanStd.append(1.96*x.std()/sqrt(n))
plt.errorbar(list(range(1,len(means)+1)),means, yerr=meanStd, fmt='o')
plt.title('20 intervalles de confiance à 95% pour la moyenne\n'
+'d\'un échantillon de 10 observations tirées de la loi normale centrée réduite')
plt.xticks(list(range(1,len(means)+1)))
plt.grid()
plt.show()

``````
``````

``````