-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.py
42 lines (39 loc) · 1.36 KB
/
bootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sklearn
import numpy as np
import warnings
import scikits.bootstrap as skbootstrap
def getRho(data):
N = len(data)
total = np.sum(data)
crossNeg = (N-total)/2
crossPos = N-crossNeg
return float(crossPos)/(crossPos + crossNeg)
def bootstrapRho(data, n_samples=10000, alpha=0.05):
N = len(data)
rhos = []
# Generate n_samples new means from transition data
for i in np.arange(0, n_samples):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
resample = sklearn.utils.resample(data)
total = np.sum(resample)
crossNeg = (N-total)/2
crossPos = N-crossNeg
rhos.append(float(crossPos)/(crossPos + crossNeg))
return np.std(rhos, ddof = N-1)
def bootstrapSKRho(data, n_samples=10000, alpha=0.05):
"""
This function samples the confidence interval of n_samples means
"""
N = len(data)
rhos = []
# Generate n_samples new means from transition data
for i in np.arange(0, n_samples):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
resample = sklearn.utils.resample(data)
total = np.sum(resample)
crossNeg = (N-total)/2
crossPos = N-crossNeg
rhos.append(float(crossPos)/(crossPos + crossNeg))
return skbootstrap.ci(data=rhos, statfunction=np.mean, output='errorbar')