Ejemplo n.º 1
0
def summary_stats_only_finite(array, alpha=0.05):
    """ This version of summary stats only considers values that aren't nan or
    inf. Creates summaries a single location based on bootstrap

    Args:
        array (np.array): np.array that is 1 x n (n is the number of bootstrap
                          replicates)

    Returns:
        summary_stats (np.array): np.array that is 1 x 9
                                  pos 0 average
                                  pos 1 min_ci at alpha
                                  pos 2 max_ci at alpha
                                  pos 3 variance
                                  pos 4 least extreme value
                                  pos 5 median
                                  pos 6 median absolute deviation
                                  pos 7 number of infinite values in bootstrap
                                  pos 8 number of nans in bootstrap
    """
    finite_vals = np.isfinite(array)
    num_inf = np.sum(np.isinf(array))
    num_nan = np.sum(np.isnan(array))
    if np.sum(finite_vals) == 0:
        return (np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
                num_inf, num_nan)
    else:
        these_stats = credible_interval(array[finite_vals], alpha)
        this_lev = least_extreme_value(these_stats)
        var = np.var(array[finite_vals])
        # median = np.median(array[finite_vals])
        mad = np.median(np.abs(array[finite_vals] - these_stats[3]))
        return (these_stats[0], these_stats[1], these_stats[2], var, this_lev,
                these_stats[3], mad, num_inf, num_nan)
Ejemplo n.º 2
0
def summary_stats_nan_zeros(array, alpha=0.05):
    """ This version of summary stats turns nans to 0. NOTE THAT THIS MODIFIES
    THE ARRAY

    Creates summaries for a single location based on bootstraps

    Args:
        array (np.array): np.array that is 1 x n (n is the number of bootstrap
                          replicates)

    Returns:
        summary_stats (np.array): np.array that is 1 x 9
                                  pos 0 average
                                  pos 1 min_ci at alpha
                                  pos 2 max_ci at alpha
                                  pos 3 variance
                                  pos 4 least extreme value
                                  pos 5 median
                                  pos 6 median absolute deviation
    """
    array[np.isnan(array)] = 0
    these_stats = credible_interval(array, alpha)
    this_lev = least_extreme_value(these_stats)
    var = np.var(array)
    median = np.median(array)
    mad = np.sum(np.abs(array - median)) / array.size
    return (these_stats[0], these_stats[1], these_stats[2], var, this_lev,
            median, mad)