Optimal thresholds and joint TCF regions

Select the operating point

Supply three independent groups in increasing diagnostic order. At thresholds \(a\le b\), the rule assigns values at or below \(a\) to class 1, values in \((a,b]\) to class 2, and values above \(b\) to class 3. The population TCFs are \(F_1(a)\), \(F_2(b)-F_2(a)\), and \(1-F_3(b)\).

set.seed(34)
training <- list(x = rnorm(30), y = rnorm(30, 2.5, 1.1),
                 z = rnorm(30, 3.69, 1.2))
assessment <- list(x = rnorm(60), y = rnorm(60, 2.5, 1.1),
                   z = rnorm(60, 3.69, 1.2))

selected <- with(training, threshold3(x, y, z, method = "all",
                                      bwd_type = "AZZ", ci = FALSE))
selected$summary
#>   method      tau1     tau2  tcf1_opt  tcf2_opt  tcf3_opt
#> 1    GYI 1.2057823 3.134176 0.8754966 0.5689515 0.6577541
#> 2    CtP 0.9079079 3.193366 0.8033791 0.6365273 0.6429702
#> 3     MV 1.0628524 3.224185 0.8425075 0.6193967 0.6352587

GYI maximizes the sum of the kernel TCF estimates, CtP minimizes their Euclidean distance to \((1,1,1)\), and MV maximizes their product. All three criteria search under \(a\le b\) and consider coincident thresholds. CtP and MV start from the best ordered grid pair and refine it on the feasible set.

The formula interface uses the same group ordering. Here the levels are supplied explicitly.

train_data <- data.frame(
  marker = unlist(training, use.names = FALSE),
  group = rep(c("low", "middle", "high"), lengths(training))
)
fit_formula <- threshold3(marker ~ group, data = train_data,
                          diag_levels = c("low", "middle", "high"),
                          bwd_type = "AZZ", ci = FALSE)
#> Warning: The order of diagnostic groups does not agree with the ordering based
#> on increasing sample means. The analysis proceeds using the supplied group
#> order.
fit_formula$opt_thresh
#> [1] 1.205782 3.134176

Assess the selected rule on independent data

Pass independent observations on the same marker scale in assessment. The thresholds and training kernel estimates still come from training. All counts for the joint region come from assessment, with the selected pair held fixed. Conditional on training, the target is the population TCF triplet of that fitted rule.

fit <- with(training, threshold3(x, y, z, method = "GYI",
                                 bwd_type = "AZZ", assessment = assessment,
                                 B = 199, seed = 34))
fit$opt_thresh
#> [1] 1.205782 3.134176
fit$c_alp
#> [1] 8.337986
head(t(fit$out_bts))
#>          tau1     tau2         ll
#> [1,] 1.205782 3.134176  3.5967972
#> [2,] 1.205782 3.134176 13.9793443
#> [3,] 1.205782 3.134176  1.6604651
#> [4,] 1.205782 3.134176  0.6388799
#> [5,] 1.205782 3.134176  2.9266258
#> [6,] 1.205782 3.134176  2.5685083

The first two rows of out_bts repeat the selected thresholds. The third row contains the bootstrap statistics. On the assessment sample, the binomial deviance uses the observed counts. In the bootstrap it uses the simulated counts. If the observed count is 0 or \(n_j\) in group \(j\), the binomial generating probability is \((k_j+0.5)/(n_j+1)\). With coincident thresholds the middle interval is empty, so the region lies on the \(\mathrm{TCF}_2=0\) plane and the cutoff uses only the outer groups.

To check a candidate triplet, compare the joint deviance with c_alp. The binomial log-likelihood calculation below handles matching endpoint values without taking the product of zero and an infinite logarithm.

a <- fit$opt_thresh[1L]
b <- fit$opt_thresh[2L]
counts <- with(assessment, c(sum(x <= a), sum(a < y & y <= b), sum(z > b)))
n <- lengths(assessment)
candidate <- c(0.85, 0.55, 0.70)
deviance <- 2 * sum(dbinom(counts, n, counts / n, log = TRUE) -
                    dbinom(counts, n, candidate, log = TRUE))
c(deviance = deviance, cutoff = fit$c_alp, inside = deviance <= fit$c_alp)
#>  deviance    cutoff    inside 
#> 0.3493381 8.3379864 1.0000000

Use the training data with bootstrap threshold refitting

When assessment is omitted, threshold3() builds the region using the same data that selected the thresholds. Each bootstrap replicate refits the thresholds using the original bandwidths. The original kernel estimates of the TCFs serve as reference values. This workflow also returns ci_tau, a separate percentile interval for each threshold.

fit_refit <- with(training, threshold3(x, y, z, method = "GYI",
                                       bwd_type = "AZZ", B = 199, seed = 34))
fit_refit$ci_tau
#>               [,1]     [,2]
#> ci_tau_1 0.7983105 1.521807
#> ci_tau_2 2.2430061 4.084847
fit_refit$c_alp
#> [1] 19.38482
sum(!is.finite(fit_refit$out_bts["ll", ]))
#> [1] 0

A coincident bootstrap pair gives an infinite statistic when the original kernel estimate of TCF2 is positive. Check that c_alp is finite before interpreting the region.

Draw the regions

Run these examples interactively. threshold3(..., plot = TRUE) draws the bootstrap-calibrated region. The red point gives the empirical TCFs on the sample used for inference. The plot axes are TCF1, TCF3, and TCF2.

with(training, threshold3(x, y, z, method = "GYI", bwd_type = "AZZ",
                          assessment = assessment, B = 199, seed = 34,
                          plot = TRUE))

For a fixed pair and chi-squared calibration, draw the assessment ROC surface first and add the region with CR_tcfs(). This call uses three degrees of freedom for distinct thresholds and two for coincident thresholds.

roc <- with(assessment, ROC_emp_surface(x, y, z, ncp = 35))
CR_tcfs(roc, cpts = fit$opt_thresh, fill = TRUE)