Stop when the estimate is precise enough

Replace a guessed trial budget with a stated precision target.

A fixed trial budget has to be set in advance, and set for the least precise participant you can imagine, so everyone else is over-tested. If inference costs a fraction of a millisecond you can instead refit after every trial and stop each participant when their own estimate is precise enough.

You can try this without writing anything: the live task runs a similar loop in your browser.

  1. State the target

    A target is a statement about precision, not about trial count. Either a maximum posterior SD on some parameters, or a minimum confidence in a construct.

    import grintools as gt
    
    # p01 from the example data in "Analyse data you already have"
    counts = [[29, 2, 3, 6], [1, 32, 0, 2], [2, 3, 36, 4], [2, 6, 3, 29]]
    fit, con = gt.infer(counts)
    
    # stop when every correlation is known to within an SD of 0.35
    decision = gt.stop_on_precision(fit, sd_max=0.35, params=["rho"])
    decision.stop           # True / False
    print(decision.summary())
    #   stop = False  (combine='all')
    #       sd:rho_1         0.582 vs 0.350  [not met]
    
    decision.checks         # one dict per target: value, threshold, met, reachable
    decision.blocked_by     # targets the data may never be able to meet
    

    The summary names the worst of the four correlations, the one furthest from the target. Here that is rho_1. The rule is met only when that one is within the target too.

  2. Put it in the trial loop

    GRIN is fast enough to check after every trial. Wait until each stimulus has been shown at least 3 times, because the fit needs a few observations of every stimulus before it means anything.

    import numpy as np, grintools as gt
    
    counts = np.zeros((4, 4), dtype=int)
    MIN_PER_STIMULUS, MAX_TRIALS = 3, 400
    
    for n in range(1, MAX_TRIALS + 1):
        s = present_random_stimulus()          # your experiment
        r = collect_response()                 # your experiment
        counts[s, r] += 1
    
        if counts.sum(axis=1).min() < MIN_PER_STIMULUS:
            continue                           # too early to ask
    
        fit, con = gt.infer(counts)
        if gt.stop_on_precision(fit, sd_max=0.35, params=["rho"]).stop:
            print(f"target reached after {n} trials")
            break
    

    The JavaScript runs inside a <script type="module"> on a page served from the GRIN web folder, which holds the model and the ONNX runtime it loads.

  3. Always set a ceiling

    Some participants will not reach any given target, because the design does not contain the information. This is most likely for the correlations, and at high accuracy. Without a maximum you are running an experiment with no defined end.

    The example ceiling of 400 trials is 100 per stimulus. With a target as tight as 0.35 on the correlations, expect many participants to reach the ceiling before the target. Report the ceiling and how many participants hit it. A saving computed over a cohort where the slowest were quietly dropped is not a saving.

Two caveats worth knowing

Targets on correlations inherit a calibration issue. The correlation intervals run narrower than nominal, so a target on rho is met sooner than it should be. Either pass calibrated=True / calibrated = TRUE, or set the target a little tighter than you actually want.

Stopping on a construct probability is different from stopping on precision. A probability near one half can mean the data are uninformative, and more trials will fix that. It can also mean that the true answer sits near a boundary, and more trials will not fix that. A precision target is the safer default.

Next: steer stimulus levels into the informative range, or go back to all tutorials.