Skip to contents

For a binary gate, calculates the value of a focal continuous covariate at which the fitted prior probability of the positive class equals level.

Usage

mbmm_gate_threshold(
  fit,
  focal,
  hold_at = list(),
  level = 0.5,
  slope_tolerance = 1e-10
)

Arguments

fit

A binary "mbmm_gate" object.

focal

Name of the continuous focal variable.

hold_at

Named list providing fixed values for every other variable in the gate formula.

level

Probability level at which to calculate the crossing.

slope_tolerance

Small positive value used to determine whether the fitted gate is effectively flat in the focal covariate.

Value

A numeric threshold on the fitted gate-covariate scale. Returns NA_real_ with a message when the focal variable has no estimable linear effect.

Details

For the common intercept-plus-one-covariate model,

$$ \mathrm{logit}\{\pi(x)\} = \beta_0 + \beta_1 x, $$

the threshold is

$$ x^* = \frac{\mathrm{logit}(\mathrm{level})-\beta_0}{\beta_1}. $$

When additional covariates are included, their values must be supplied through hold_at. The function constructs the fitted design matrix at two focal values to identify the linear-predictor slope associated with the focal variable. This also correctly incorporates fixed contributions from other additive covariates.

This function returns a threshold on the scale used in the gate model. For standardized biomarkers, back-transformation and bootstrap uncertainty should be handled separately.

Examples

set.seed(1)

n <- 150
x <- rnorm(n)

z <- rbinom(
  n,
  1,
  mbmm_inv_logit(-0.5 + 1.5 * x)
)

logL <- data.frame(
  logL_pos = ifelse(z == 1, log(0.98), log(0.02)),
  logL_neg = ifelse(z == 1, log(0.02), log(0.98))
)

fit <- mbmm_fit_gate(
  logL = logL,
  formula = ~x,
  data = data.frame(x = x),
  classes = c("pos", "neg")
)

mbmm_gate_threshold(
  fit,
  focal = "x"
)
#> [1] 0.3469035