
Plan Human Validation Sample Size for Prediction-Powered Inference (PPI++)
Source:R/ppi_power.R
ppi_sample_size.RdComputes the required number of human-coded validation annotations n_labeled
to achieve either a target standard error (target_se) or target two-sided
statistical power (power for a given effect) under optimal power-tuned
PPI++. Uses exact PPI++ asymptotic variance:
$$\mathrm{Var}(\hat{\theta}_{\mathrm{PPI++}}) = \frac{\sigma^2}{n}\left(1 - r^2 \frac{N}{n + N}\right),$$
where \(\sigma\) is the single-observation human-only standard error
scaling constant (\(\sigma = \mathrm{SE}_{\mathrm{human}}\sqrt{n_0}\)),
\(r \in [0, 1]\) is the correlation between human and LLM estimating
scores, and \(N\) is the unlabeled LLM-coded sample size.
Usage
ppi_sample_size(
target_se = NULL,
effect = NULL,
power = 0.8,
sd = NULL,
r = NULL,
n_total = NULL,
n_unlabeled = Inf,
pilot = NULL,
term = NULL,
alpha = 0.05,
min_n = 20L
)Arguments
- target_se
Optional positive target standard error for the focal parameter. Specify either
target_seoreffect.- effect
Optional non-zero target effect size for a two-sided Wald test at significance level
alphaand targetpower. Ignored iftarget_seis supplied.- power
Target statistical power in
(alpha, 1)when sizing byeffect. Default0.80.- sd
Positive single-observation SD scaling constant (\(\mathrm{SE}_{\mathrm{human}}\sqrt{n}\)). Inferred from
pilotifNULL.- r
Correlation magnitude in
[0, 1]between human and LLM scores (or estimating equations). Inferred frompilotifNULL.- n_total
Optional finite total corpus size (
n_labeled + n_unlabeled). When supplied, solvesn_labeledaccounting for the irreducible corpus floor \(\sigma / \sqrt{n_{\mathrm{total}}}\). Mutually exclusive with a finiten_unlabeled.- n_unlabeled
Unlabeled LLM-coded pool size
N(defaultInf, representing a large unlabeled corpus). Ignored ifn_totalis supplied.- pilot
Optional pilot
"llm_ppi"or continuous"llm_calibration"object from whichsdandrare estimated automatically.- term
Optional parameter term name to extract from a multi-term
"llm_ppi"pilot object. Defaults to the first non-intercept term.- alpha
Two-sided Type-I error rate in
(0, 1). Default0.05.- min_n
Minimum practical validation sample size floor. Default
20L.
Value
An S3 object of class "llm_ppi_sample_size" containing:
feasible: logical indicating whether the target is attainable givenn_total.n_labeled: required human validation sample size (integer, orNAif infeasible).n_unlabeled: resulting unlabeled sample size.n_human_only: human annotations required without PPI++.annotations_saved,savings_pct: human annotation savings from PPI++.target_se,achieved_se,achieved_power,effective_n,min_n_total_needed,params.
Details
Parameters (sd, r) may be supplied directly or automatically extracted from
a pilot ppi_mean(), ppi_lm(), ppi_glm(), ppi_clustered(),
ppi_lmer(), or continuous calibration_metrics() object via pilot.
Examples
# Size a validation subset out of a 2,000-text corpus for 80% power on beta = 0.25
plan <- ppi_sample_size(effect = 0.25, power = 0.80, sd = 1.2, r = 0.82, n_total = 2000)
plan
#>
#> ── PPI++ Human Validation Sample-Size Plan
#> Inputs (supplied): sd = 1.200 | r = 0.820 | Target SE = 0.0892
#> Required human validation n = 64 (vs. 181 human-only -> saves 117 annotations,
#> 64.6%)
#> Projected PPI++ SE = 0.0886 | Effective n = 183.3 | Power = 0.805
# Or size directly from a pilot PPI fit on ema_coded
data(ema_coded)
agg <- aggregate_scores(ema_coded, score_col = "llm_score")
pilot_fit <- ppi_lm(human_score ~ x + group, data = agg, pred_col = "llm_score")
ppi_sample_size(target_se = 0.06, n_total = 1500, pilot = pilot_fit, term = "x")
#>
#> ── PPI++ Human Validation Sample-Size Plan
#> Inputs (pilot_ppi++): sd = 1.163 | r = 1.000 | Target SE = 0.0600
#> Required human validation n = 20 (vs. 376 human-only -> saves 356 annotations,
#> 94.7%)
#> Projected PPI++ SE = 0.0301 | Effective n = 1489.0