Guide for using threshold3 function

Duc-Khanh To

2026-11-05

GYI_normal <- function(par, mu, sigma){
  ff <- function(par, mu, sigma){
    tcf1 <- pnorm(par[1], mean = mu[1], sd = sigma[1])
    tcf2 <- pnorm(par[2], mean = mu[2], sd = sigma[2]) - 
      pnorm(par[1], mean = mu[2], sd = sigma[2])
    tcf3 <- 1 - pnorm(par[2], mean = mu[3], sd = sigma[3])
    return(tcf1 + tcf2 + tcf3 + par[3]*(par[1] - par[2]))
  }
  out_optim <- optim(par = par, fn = ff, method = "L-BFGS-B",
                     lower = c(-Inf, -Inf, 0), upper = c(Inf, Inf, Inf),
                     mu = mu, sigma = sigma, control = list(fnscale = -1))
  return(out_optim)
}

Simulated data

mu_true <- c(0, 2.5, 3.69)
sigma_true <- c(1, 1.1, 1.2)
true_GYI_normal <- GYI_normal(c(1.25, 3.1, 0.1), mu = mu_true, 
                              sigma = sigma_true)
true_GYI_normal
#> $par
#> [1] 1.232349 3.164977 0.000000
#> 
#> $value
#> [1] 2.162899
#> 
#> $counts
#> function gradient 
#>        9        9 
#> 
#> $convergence
#> [1] 0
#> 
#> $message
#> [1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"
n1 <- 30
n2 <- 30
n3 <- 30
X1 <- rnorm(n1, mu_true[1], sigma_true[1])
X2 <- rnorm(n2, mu_true[2], sigma_true[2])
X3 <- rnorm(n3, mu_true[3], sigma_true[3])

GYI

out_GYI_normal <- threshold3(x = X1, y = X2, z = X3, method = "GYI",
                             kernel_type = "gauss", bwd_type = "AZZ", B = 1000)
out_GYI_normal$opt_thresh
#> [1] 1.205782 3.134168
quantile(out_GYI_normal$out_bts[1,], probs = (1 + c(-1, 1)*0.95)/2, 
         type = 8, names = FALSE)
#> [1] 0.7866772 1.5308219
quantile(out_GYI_normal$out_bts[2,], probs = (1 + c(-1, 1)*0.95)/2, 
         type = 8, names = FALSE)
#> [1] 2.230346 4.073662
out_GYI_normal$ci_tau
#>               [,1]     [,2]
#> ci_tau_1 0.7866772 1.530822
#> ci_tau_2 2.2303459 4.073662
out_GYI_normal$c_alp
#> [1] 19.85217
data_test <- data.frame(biom = c(X1, X2, X3), 
                        diag = rep(c("1", "2", "3"), c(n1, n2, n3)))
out_GYI_normal_2 <- threshold3(formula = biom ~ diag, data = data_test, 
                               method = "GYI", kernel_type = "gauss", 
                               bwd_type = "AZZ", B = 1000)
out_GYI_normal_2$opt_thresh
#> [1] 1.205782 3.134168
out_GYI_normal_2$ci_tau
#>               [,1]     [,2]
#> ci_tau_1 0.7866772 1.530822
#> ci_tau_2 2.2303459 4.073662
out_GYI_normal_2$c_alp
#> [1] 19.85217

Explore the ROC surface interactively

Run the following chunks interactively to draw a joint region at the fixed thresholds 0.5 and 3.4.

out_roc_surface <- ROC_emp_surface(X1, X2, X3, ncp = 35)
CR_tcfs(out_roc_surface, cpts = c(0.5, 3.4), fill = TRUE)
rgl::rglwidget(width = 800, height = 800)
rgl::close3d()
out_roc_surface_2 <- ROC_emp_surface(formula = biom ~ diag, data = data_test, ncp = 35,
                                     color = "steelblue", alpha = 0.5)
rgl::rglwidget(
    width = 800,
    height = 800
)
CR_tcfs(out_roc_surface_2, cpts = c(0.5, 3.4), fill = TRUE)
rgl::rglwidget(width = 800, height = 800)
rgl::close3d()