Skip to contents

Tests whether the candidate arm (an hr_effort_escalate() policy, say) is non-inferior to each of the comparators (fixed efforts, say), with hr_report()'s non-inferiority test at margin and Holm's procedure over the comparisons, and reports what each arm cost, the requests sent at a raised effort included.

Usage

hr_effort_check(
  bench,
  candidate,
  comparators = NULL,
  margin = 0.05,
  registration = NULL,
  cost_test = TRUE,
  B = 2000,
  seed = 1
)

# S3 method for class 'hr_effort_check'
print(x, ...)

Arguments

bench

An hr_benchmark() result.

candidate

The arm under test, one name.

comparators

The arms it is compared with; every other arm when NULL.

margin

The non-inferiority margin, a proportion in (0, 1).

registration

NULL, or an hr_register_contrasts() result.

cost_test

Whether a verdict also needs candidate to be cheaper (for contrasts built here).

B, seed

Bootstrap resamples and seed, passed to hr_report().

x

An hr_effort_check.

...

Ignored.

Value

An object of class hr_effort_check, a list of

contrasts

One row per comparison: new, reference, label, margin, estimate, lower, level, accuracy_holds, cost_diff, cost_upper, cost_holds, verdict and p_value, from hr_report()'s ni table.

cost

One row per arm: arm, accuracy (the mean of correct over reportable rows), usd (mean per run, NA when a run has no price), calls (model requests per run), escalations (raises per run), escalated_calls (requests per run sent at a raised effort) and resolved (the share of raises whose stage fired none of the same triggers again, NA with none), then priced, as_of and certain, where usd's prices came from, as in hr_report()'s cost table.

best_fixed

The most accurate comparator.

post_hoc

TRUE when no registration was given.

report

The hr_report() the contrasts come from.

Details

With a registration from hr_register_contrasts(), made before the benchmark ran, its contrasts with candidate as new are the ones tested, at their registered margins, and the result is confirmatory. Without one, the contrasts are built here from candidate, comparators and margin, all confirmatory so Holm's procedure covers them, and the result is marked post hoc (post_hoc = TRUE): the margin was stated after the benchmark was scored, so it is evidence for a decision to run a registered comparison, not a verdict. Either way the benchmark's rows must be on the test or final split, as hr_report() requires for a test.

The cost table reads each run's trace: the requests it sent, the raises an escalation policy made (hr_effort_log()) and the requests the raised stages sent. Its usd is the run's cost from the benchmark, which already counts every request, raised or not.

Examples

ref <- hr_reference(sprintf("q%02d", 1:40), labels = rep("yes", 40),
                    cluster = sprintf("c%02d", rep(1:20, each = 2)), split = "test")
arm_at <- function(name, effort) {
  hr_arm(name, function(item, ctx) {
    tr <- ctx$trace
    a <- hr_call(ctx$client, paste("first", item), model = "gpt-5.6-luna", trace = tr,
                 label = "task.draft", effort = effort)
    b <- hr_call(ctx$client, paste("final", item), model = "gpt-5.6-luna", trace = tr,
                 label = "task.final", effort = effort)
    b$text
  })
}
# Four hard items: the first step finds nothing at low effort, and the
# answer is wrong unless the final step reasons at high effort.
cl <- hr_mock_client(function(m, p) {
  hard <- grepl("q0[1-4]", m[[1]]$content)
  if (grepl("first", m[[1]]$content) && hard) return("NOT_IN_DOCUMENT")
  if (hard && identical(p$effort, "low")) "no" else "yes"
})
esc <- hr_effort_escalate(replies = c(not_in_document = "NOT_IN_DOCUMENT"))
arms <- list(arm_at("low", "low"), arm_at("high", "high"), arm_at("escalate", esc))
bench <- hr_benchmark(arms, ref, runs = 5, client = cl,
                      governor = hr_governor(max_calls = 2000, max_cost_usd = 5))
chk <- hr_effort_check(bench, "escalate", margin = 0.1, cost_test = FALSE, B = 200)
chk
#> <hr_effort_check> escalate against low, high (post hoc: no registration)
#>   vs low          margin 10.0 pts, difference +10.0 pts, lower bound -6.7: non-inferior
#>   vs high         margin 10.0 pts, difference +0.0 pts, lower bound -9.9: non-inferior
#>   best fixed comparator: high
#>       arm accuracy usd calls escalations escalated_calls resolved priced as_of
#>       low      0.9  NA     2         0.0             0.0       NA  FALSE  <NA>
#>      high      1.0  NA     2         0.0             0.0       NA  FALSE  <NA>
#>  escalate      1.0  NA     2         0.1             0.1        1  FALSE  <NA>
#>  certain
#>     TRUE
#>     TRUE
#>     TRUE
#>   usd is NA for low, high, escalate: no price set for a model of those arms (set one with hr_register_model() or hr_load_models())