Exemplo n.º 1
0
def bootstrap_from_outcomes(
    data, outcome, bootstrap_outcomes, ci_method="percentile", alpha=0.05, n_cores=1
):
    """Set up results table containing mean, standard deviation and confidence interval
    for each estimated parameter.

    Args:
        data (pandas.DataFrame): original dataset.
        outcome (callable): function of the data calculating statistic of interest.
            Needs to return a pandas Series.
        bootstrap_outcomes (pandas.DataFrame): DataFrame of bootstrap_outcomes in the
            bootstrap samples.
        ci_method (str): method of choice for confidence interval computation.
        n_cores (int): number of jobs for parallelization.
        alpha (float): significance level of choice.

    Returns:
        results (pandas.DataFrame): table of results.

    """

    check_inputs(data=data, ci_method=ci_method, alpha=alpha)

    summary = pd.DataFrame(bootstrap_outcomes.mean(axis=0), columns=["mean"])

    summary["std"] = bootstrap_outcomes.std(axis=0)

    cis = compute_ci(data, outcome, bootstrap_outcomes, ci_method, alpha, n_cores)
    summary["lower_ci"] = cis["lower_ci"]
    summary["upper_ci"] = cis["upper_ci"]

    cov = bootstrap_outcomes.cov()

    out = {"summary": summary, "cov": cov, "outcomes": bootstrap_outcomes}

    return out
Exemplo n.º 2
0
def test_bca_ci(setup, expected):
    bca_ci = compute_ci(setup["df"], g, setup["estimates"], ci_method="bca")
    aaae(bca_ci, expected["bca_ci"])
Exemplo n.º 3
0
def test_percentile_ci(setup, expected):
    percentile_ci = compute_ci(setup["df"],
                               g,
                               setup["estimates"],
                               ci_method="percentile")
    aaae(percentile_ci, expected["percentile_ci"])
Exemplo n.º 4
0
def test_normal_ci(setup, expected):
    normal_ci = compute_ci(setup["df"],
                           g,
                           setup["estimates"],
                           ci_method="normal")
    aaae(normal_ci, expected["normal_ci"])
Exemplo n.º 5
0
def test_t_ci(setup, expected):
    t_ci = compute_ci(setup["df"], g, setup["estimates"], ci_method="t")
    aaae(t_ci, expected["t_ci"])