def _perm_pval(bootstat, estimate, tail='two-sided'):
    """
    Compute p-values from a permutation test.

    Parameters
    ----------
    bootstat : 1D array
        Permutation distribution.
    estimate : float or int
        Point estimate.
    tail : str
        'upper': one-sided p-value (upper tail)
        'lower': one-sided p-value (lower tail)
        'two-sided': two-sided p-value

    Returns
    -------
    p : float
        P-value.
    """
    assert tail in ['two-sided', 'upper', 'lower'], 'Wrong tail argument.'
    assert isinstance(estimate, (int, float))
    bootstat = np.asarray(bootstat)
    assert bootstat.ndim == 1, 'bootstat must be a 1D array.'
    n_boot = bootstat.size
    assert n_boot >= 1, 'bootstat must have at least one value.'
    if tail == 'upper':
        p = np.greater_equal(bootstat, estimate).sum() / n_boot
    elif tail == 'lower':
        p = np.less_equal(bootstat, estimate).sum() / n_boot
    else:
        p = np.greater_equal(np.fabs(bootstat), abs(estimate)).sum() / n_boot
    return p
Compute p-values from a permutation test.

    Parameters
    ----------
    bootstat : 1D array
        Permutation distribution.
    estimate : float or int
        Point estimate.
    tail : str
        'upper': one-sided p-value (upper tail)
        'lower': one-sided p-value (lower tail)
        'two-sided': two-sided p-value

    Returns
    -------
    p : float
        P-value.