99
1010class bootstrap :
1111 '''Computes the summary statistic and a bootstrapped confidence interval.
12+
1213 Keywords:
1314 x1, x2: array-like
1415 The data in a one-dimensional array form. Only x1 is required.
1516 If x2 is given, the bootstrapped summary difference between
1617 the two groups (x2-x1) is computed.
1718 NaNs are automatically discarded.
19+
1820 paired: boolean, default False
1921 Whether or not x1 and x2 are paired samples. If 'paired' is None then
2022 the data will not be treated as paired data in the subsequent calculations.
2123 If 'paired' is 'baseline', then in each tuple of x, other groups will be
2224 paired up with the first group (as control). If 'paired' is 'sequential',
2325 then in each tuple of x, each group will be paired up with the previous
2426 group (as control).
27+
2528 statfunction: callable, default np.mean
2629 The summary statistic called on data.
30+
2731 smoothboot: boolean, default False
2832 Taken from seaborn.algorithms.bootstrap.
2933 If True, performs a smoothed bootstrap (draws samples from a kernel
3034 destiny estimate).
35+
3136 alpha: float, default 0.05
3237 Denotes the likelihood that the confidence interval produced
3338 does not include the true summary statistic. When alpha = 0.05,
3439 a 95% confidence interval is produced.
40+
3541 reps: int, default 5000
3642 Number of bootstrap iterations to perform.
43+
3744 Returns:
3845 An `bootstrap` object reporting the summary statistics, percentile CIs,
3946 bias-corrected and accelerated (BCa) CIs, and the settings used.
47+
4048 summary: float
4149 The summary statistic.
50+
4251 is_difference: boolean
4352 Whether or not the summary is the difference between two groups.
4453 If False, only x1 was supplied.
45- is_paired: boolean
46- Whether or not the difference reported is between 2 paired groups.
54+
55+ is_paired : string, default None
56+ The type of the experiment under which the data are obtained
57+
4758 statistic: callable
4859 The function used to compute the summary.
60+
4961 reps: int
5062 The number of bootstrap iterations performed.
63+
5164 stat_array: array.
5265 A sorted array of values obtained by bootstrapping the input arrays.
66+
5367 ci: float
5468 The size of the confidence interval reported (in percentage).
69+
5570 pct_ci_low, pct_ci_high: floats
5671 The upper and lower bounds of the confidence interval as computed
5772 by taking the percentage bounds.
73+
5874 pct_low_high_indices: array
5975 An array with the indices in `stat_array` corresponding to the
6076 percentage confidence interval bounds.
77+
6178 bca_ci_low, bca_ci_high: floats
6279 The upper and lower bounds of the bias-corrected and accelerated
6380 (BCa) confidence interval. See Efron 1977.
81+
6482 bca_low_high_indices: array
6583 An array with the indices in `stat_array` corresponding to the BCa
6684 confidence interval bounds.
85+
6786 pvalue_1samp_ttest: float
6887 P-value obtained from scipy.stats.ttest_1samp. If 2 arrays were
6988 passed (x1 and x2), returns 'NIL'.
7089 See https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.stats.ttest_1samp.html
90+
7191 pvalue_2samp_ind_ttest: float
7292 P-value obtained from scipy.stats.ttest_ind.
73- If a single array was given (x1 only), or if `paired` is True ,
93+ If a single array was given (x1 only), or if `paired` is not None ,
7494 returns 'NIL'.
7595 See https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.stats.ttest_ind.html
96+
7697 pvalue_2samp_related_ttest: float
7798 P-value obtained from scipy.stats.ttest_rel.
78- If a single array was given (x1 only), or if `paired` is False ,
99+ If a single array was given (x1 only), or if `paired` is None ,
79100 returns 'NIL'.
80101 See https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.stats.ttest_rel.html
102+
81103 pvalue_wilcoxon: float
82104 P-value obtained from scipy.stats.wilcoxon.
83- If a single array was given (x1 only), or if `paired` is False ,
105+ If a single array was given (x1 only), or if `paired` is None ,
84106 returns 'NIL'.
85107 The Wilcoxons signed-rank test is a nonparametric paired test of
86108 the null hypothesis that the related samples x1 and x2 are from
87109 the same distribution.
88110 See https://docs.scipy.org/doc/scipy-1.0.0/reference/scipy.stats.wilcoxon.html
111+
89112 pvalue_mann_whitney: float
90113 Two-sided p-value obtained from scipy.stats.mannwhitneyu.
91114 If a single array was given (x1 only), returns 'NIL'.
92115 The Mann-Whitney U-test is a nonparametric unpaired test of the null
93116 hypothesis that x1 and x2 are from the same distribution.
94117 See https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.stats.mannwhitneyu.html
118+
95119 '''
96120 def __init__ (self , x1 , x2 = None ,
97- paired = False ,
121+ paired = None ,
98122 statfunction = None ,
99123 smoothboot = False ,
100124 alpha_level = 0.05 ,
@@ -136,7 +160,7 @@ def __init__(self, x1, x2=None,
136160 if len (x1 ) != len (x2 ):
137161 raise ValueError ('x1 and x2 are not the same length.' )
138162
139- if (x2 is None ) or (paired is True ) :
163+ if (x2 is None ) or (paired is not None ) :
140164
141165 if x2 is None :
142166 tx = x1
@@ -146,7 +170,7 @@ def __init__(self, x1, x2=None,
146170 ttest_2_paired = 'NIL'
147171 wilcoxonresult = 'NIL'
148172
149- elif paired is True :
173+ elif paired is not None :
150174 diff = True
151175 tx = x2 - x1
152176 ttest_single = 'NIL'
@@ -169,7 +193,7 @@ def __init__(self, x1, x2=None,
169193 pct_low_high = np .nan_to_num (pct_low_high ).astype ('int' )
170194
171195
172- elif x2 is not None and paired is False :
196+ elif x2 is not None and paired is None :
173197 diff = True
174198 x2 = pd .Series (x2 ).dropna ()
175199 # Generate statarrays for both arrays.
@@ -249,7 +273,7 @@ def __repr__(self):
249273 else :
250274 stat = self .statistic
251275
252- diff_types = {True : 'paired' , False : 'unpaired' }
276+ diff_types = {'sequential' : 'paired' , 'baseline' : 'paired' , None : 'unpaired' }
253277 if self .is_difference :
254278 a = 'The {} {} difference is {}.' .format (diff_types [self .is_paired ],
255279 stat , self .summary )
@@ -265,6 +289,7 @@ def jackknife_indexes(data):
265289 From the scikits.bootstrap package.
266290 Given an array, returns a list of arrays where each array is a set of
267291 jackknife indexes.
292+
268293 For a given set of data Y, the jackknife sample J[i] is defined as the
269294 data set Y with the ith data point deleted.
270295 """
@@ -312,4 +337,4 @@ def bca(data, alphas, statarray, statfunction, ostat, reps):
312337 nvals = np .round ((reps - 1 )* avals )
313338 nvals = np .nan_to_num (nvals ).astype ('int' )
314339
315- return nvals
340+ return nvals
0 commit comments