Intervalli di confidenza bootstrap

Pensiero statistico in Python (Parte 2)

Justin Bois

Lecturer at the California Institute of Technology

Funzione per repliche bootstrap

def bootstrap_replicate_1d(data, func):
    """Generate bootstrap replicate of 1D data."""
    bs_sample = np.random.choice(data, len(data))
    return func(bs_sample)

bootstrap_replicate_1d(michelson_speed_of_light, np.mean)
299859.20000000001
bootstrap_replicate_1d(michelson_speed_of_light, np.mean)
299855.70000000001
bootstrap_replicate_1d(michelson_speed_of_light, np.mean)
299850.29999999999
Pensiero statistico in Python (Parte 2)

Molte repliche bootstrap

bs_replicates = np.empty(10000)

for i in range(10000): bs_replicates[i] = bootstrap_replicate_1d( michelson_speed_of_light, np.mean)
Pensiero statistico in Python (Parte 2)

Istogramma delle repliche bootstrap

_ = plt.hist(bs_replicates, bins=30, normed=True)
_ = plt.xlabel('mean speed of light (km/s)')
_ = plt.ylabel('PDF')
plt.show()
Pensiero statistico in Python (Parte 2)

Stima bootstrap della media

ch2-2.011.png

Pensiero statistico in Python (Parte 2)

Intervallo di confidenza di una statistica

  • Se ripetessimo le misure molte volte, il p% dei valori osservati cadrebbe nell'intervallo di confidenza al p%.
Pensiero statistico in Python (Parte 2)

Intervallo di confidenza bootstrap

conf_int = np.percentile(bs_replicates, [2.5, 97.5])
array([ 299837.,  299868.])

ch2-2.016.png

Pensiero statistico in Python (Parte 2)

Passons à la pratique !

Pensiero statistico in Python (Parte 2)

Preparing Video For Download...