Skip to contents

Compute logit sensitivity and specificity and their sampling covariance for one test measured at nested cutoffs on the same participants.

Usage

dta_threshold_effects(
  data,
  studyID = "study_id",
  threshold = "threshold",
  tp = "TP",
  fn = "FN",
  fp = "FP",
  tn = "TN",
  positive = c("higher", "lower"),
  zero_cell = c("none", "add_half")
)

Arguments

data

Data frame with one row per study and reported cutoff. Both reference-standard strata must be represented at each cutoff.

studyID, threshold

Names of the study identifier and numeric cutoff columns. Use comparable cutoffs on the same scale across studies.

tp, fn, fp, tn

Names of the true-positive, false-negative, false-positive, and true-negative count columns. Counts must be finite nonnegative integers, with constant positive stratum totals across cutoffs within each study.

positive

Use "higher" for a positive result at or above the cutoff, or "lower" for a positive result at or below it.

zero_cell

Use "none" (default) to require finite logits. With "add_half", if a stratum has a zero marginal count at any cutoff, add 0.5 to each reconstructed score bin in that stratum.

Value

A list containing effects with raw marginal counts, logits (yi) and sampling variances (vi), sampling_covariance with one labeled matrix per study, score_bins with raw counts and per-bin adjustments in increasing score order, and cutoffs with the threshold and endpoint corresponding to each effect label. The list also records the positivity direction and correction policy. For "higher", bins include their lower cutoff. For "lower", bins include their upper cutoff. Studies follow first appearance in data. Within each study, effects and covariance blocks are ordered by ascending cutoff, sensitivity then specificity.

Details

Sort each study's cutoffs and reconstruct disjoint score bins by differencing cumulative counts. Each logit is a function of these multinomial bin counts. A joint delta approximation accounts for the overlap between cutoffs within a stratum. Cross-stratum covariances are zero conditional on the stratum totals. Empty bins alone do not trigger a correction, and singular covariance blocks are retained. A correction applies to the whole stratum, including cutoffs whose logits were already finite.

Examples

counts <- data.frame(study_id = "s1", threshold = 1:2,
                     TP = c(40, 30), FN = c(10, 20),
                     FP = c(30, 10), TN = c(70, 90))
prepared <- dta_threshold_effects(counts)
prepared$score_bins
#>   study_id bin lower upper diseased non_diseased diseased_added
#> 1       s1   1  -Inf     1       10           70              0
#> 2       s1   2     1     2       10           20              0
#> 3       s1   3     2   Inf       30           10              0
#>   non_diseased_added
#> 1                  0
#> 2                  0
#> 3                  0