Skip to content

Planning the label budget

The planning formula

With \(n\) labels, \(N\) unlabelled predictions and optimal power tuning, the variance of the PPI estimate of a mean is

\[ \operatorname{Var}(\hat\theta) = \frac{\sigma_Y^2}{n} \left(1 - \frac{R^2}{1 + n/N}\right) \times \text{DEFF}, \]

so three numbers are needed:

  • \(\sigma_Y\), the standard deviation of the outcome (\(\sqrt{p(1-p)}\) for a proportion \(p\)),
  • \(R^2\), the share of the outcome variance explained by the predictions,
  • the design effect DEFF for clustered sampling (one otherwise).

The effective sample size \(n / (1 - R^2 / (1 + n/N))\) is the number of labels a classical study would need for the same precision.

Getting the design parameters

import fewlabels as fl

fl.DesignParameters(sd_y=0.4, r2=0.6)  # assumed values
fl.DesignParameters.from_proportion(prevalence=0.2, sensitivity=0.9, specificity=0.95)
fl.DesignParameters.from_pilot(y_pilot, preds_pilot, conservative=True, seed=0)

Small pilots are optimistic

An \(R^2\) estimated from 100 pilot cases can be far from the truth. With conservative=True (the default) the plan uses the lower bootstrap bound of \(R^2\) and the upper bound of \(\sigma_Y\), so the study is not underpowered when the pilot was lucky.

Margin of error

fl.required_labels(target_half_width=0.02, params=params, n_unlabeled=50_000)
fl.planning_table([100, 200, 400, 800], params, n_unlabeled=50_000)

Power

To show that a proportion differs from a reference value by at least effect:

fl.required_labels_for_power(effect=0.05, params=params, target_power=0.9)
fl.power(n=400, effect=0.05, params=params, alternative="larger")

Spending a budget

Labels cost money, and so can predictions (API calls, GPU time). Given a total budget, cost_optimal_allocation finds the split that minimises the variance:

plan = fl.cost_optimal_allocation(
    budget=10_000, cost_label=20.0, cost_prediction=0.05, params=params, max_unlabeled=200_000
)
print(plan.n_labeled, plan.n_unlabeled, plan.half_width)

Clustered sampling

If several cases come from the same unit, multiply the variance by the design effect:

params = params.with_design_effect(fl.design_effect(mean_cluster_size=4, icc=0.2))