# pingouin.compute_bootci

pingouin.compute_bootci(x, y=None, func='pearson', method='cper', paired=False, confidence=0.95, n_boot=2000, decimals=2, seed=None, return_dist=False)[source]

Bootstrapped confidence intervals of univariate and bivariate functions.

Parameters
x1D-array or list

First sample. Required for both bivariate and univariate functions.

y1D-array, list, or None

Second sample. Required only for bivariate functions.

funcstr or custom function

Function to compute the bootstrapped statistic. Accepted string values are:

• 'pearson': Pearson correlation (bivariate, requires x and y)

• 'spearman': Spearman correlation (bivariate)

• 'cohen': Cohen d effect size (bivariate)

• 'hedges': Hedges g effect size (bivariate)

• 'mean': Mean (univariate, requires only x)

• 'std': Standard deviation (univariate)

• 'var': Variance (univariate)

methodstr

Method to compute the confidence intervals:

• 'norm': Normal approximation with bootstrapped bias and standard error

• 'per': Basic percentile method

• 'cper': Bias corrected percentile method (default)

pairedboolean

Indicates whether x and y are paired or not. Only useful when computing bivariate Cohen d or Hedges g bootstrapped confidence intervals.

confidencefloat

Confidence level (0.95 = 95%)

n_bootint

Number of bootstrap iterations. The higher, the better, the slower.

decimalsint

Number of rounded decimals.

seedint or None

Random seed for generating bootstrap samples.

return_distboolean

If True, return the confidence intervals and the bootstrapped distribution (e.g. for plotting purposes).

Returns
ciarray

Desired converted effect size

Notes

Results have been tested against the bootci Matlab function.

References

• DiCiccio, T. J., & Efron, B. (1996). Bootstrap confidence intervals. Statistical science, 189-212.

• Davison, A. C., & Hinkley, D. V. (1997). Bootstrap methods and their application (Vol. 1). Cambridge university press.

Examples

1. Bootstrapped 95% confidence interval of a Pearson correlation

>>> import pingouin as pg
>>> x = [3, 4, 6, 7, 5, 6, 7, 3, 5, 4, 2]
>>> y = [4, 6, 6, 7, 6, 5, 5, 2, 3, 4, 1]
>>> stat = np.corrcoef(x, y)
>>> ci = pg.compute_bootci(x, y, func='pearson', seed=42)
>>> print(stat, ci)
0.7468280049029223 [0.27 0.93]

1. Bootstrapped 95% confidence interval of a Cohen d

>>> stat = pg.compute_effsize(x, y, eftype='cohen')
>>> ci = pg.compute_bootci(x, y, func='cohen', seed=42, decimals=3)
>>> print(stat, ci)
0.1537753990658328 [-0.327  0.562]

1. Bootstrapped confidence interval of a standard deviation (univariate)

>>> import numpy as np
>>> stat = np.std(x, ddof=1)
>>> ci = pg.compute_bootci(x, func='std', seed=123)
>>> print(stat, ci)
1.6787441193290351 [1.21 2.16]

1. Bootstrapped confidence interval using a custom univariate function

>>> from scipy.stats import skew
>>> skew(x), pg.compute_bootci(x, func=skew, n_boot=10000, seed=123)
(-0.08244607271328411, array([-1.03,  0.77]))

1. Bootstrapped confidence interval using a custom bivariate function

>>> stat = np.sum(np.exp(x) / np.exp(y))
>>> ci = pg.compute_bootci(x, y, func=lambda x, y: np.sum(np.exp(x)
...                           / np.exp(y)), n_boot=10000, seed=123)
>>> print(stat, ci)
26.80405184881793 [12.76 45.15]

1. Get the bootstrapped distribution around a Pearson correlation

>>> ci, bstat = pg.compute_bootci(x, y, return_dist=True)
>>> print(bstat.size)
2000