def t_EB()

in bayesmark/stats.py [0:0]


def t_EB(x, alpha=0.05, axis=-1):
    """Get t-statistic based error bars on mean of `x`.

    Parameters
    ----------
    x : :class:`numpy:numpy.ndarray` of shape (n_samples,)
        Data points to estimate mean. Must not be empty or contain ``NaN``.
    alpha : float
        The alpha level (``1-confidence``) probability (in (0, 1)) to construct confidence interval from t-statistic.
    axis : int
        The axis on `x` where we compute the t-statistics. The function is vectorized over all other dimensions.

    Returns
    -------
    EB : float
        Size of error bar on mean (``>= 0``). The confidence interval is ``[mean(x) - EB, mean(x) + EB]``. `EB` is
        ``inf`` when ``len(x) <= 1``. Will be ``NaN`` if there are any infinite values in `x`.
    """
    assert np.ndim(x) >= 1 and (not np.any(np.isnan(x)))
    assert np.ndim(alpha) == 0
    assert 0.0 < alpha and alpha < 1.0

    N = np.shape(x)[axis]
    if N <= 1:
        return np.full(np.sum(x, axis=axis).shape, fill_value=np.inf)

    confidence = 1 - alpha
    # loc cancels out when we just want EB anyway
    LB, UB = sst.t.interval(confidence, N - 1, loc=0.0, scale=1.0)
    assert not (LB > UB)
    # Just multiplying scale=ss.sem(x) is better for when scale=0
    EB = 0.5 * sst.sem(x, axis=axis) * (UB - LB)
    return EB