Skip to contents

Evaluate all admissible cutpoints of a numeric predictor and return the split with the largest weighted concentration-index gain.

Usage

best_numeric_split(
  x,
  y,
  wt,
  varid,
  ctrl,
  ci_fun,
  return = c("split", "candidate")
)

Arguments

x

A numeric predictor vector without infinite values.

y

A two-column numeric matrix whose first column is the socioeconomic ranking variable and whose second column is the health outcome.

wt

A numeric vector of case weights with the same length as x.

varid

Integer identifier of the splitting variable, passed to partykit::partysplit().

ctrl

A list-like control object containing minbucket and minprob.

ci_fun

A concentration-index scoring function, typically created by ci_factory().

return

Either "split" to return only a partykit::partysplit() object, or "candidate" to also return the gain and left-child routing needed by the greedy tree builder.

Value

A partysplit object describing the best admissible binary split, or NULL if no split is available because all x values are tied or all candidate splits violate the control constraints.

Details

Candidate cutpoints are formed at midpoints between distinct sorted values of x. The midpoint is computed so that it stays finite and inside the half-open interval [lower, upper), which keeps x <= cutpoint routing identical to the partition that was scored. Each candidate is filtered using ctrl$minbucket and ctrl$minprob before being scored with weighted_ci_gain().

Examples

x <- c(2, 4, 6, 8, 10)
y <- cbind(
  ses = c(10, 20, 30, 40, 50),
  health = c(1, 0, 1, 0, 1)
)
wt <- rep(1, 5)
ctrl <- list(minbucket = 1, minprob = 0)

split <- best_numeric_split(
  x = x,
  y = y,
  wt = wt,
  varid = 1,
  ctrl = ctrl,
  ci_fun = ci_factory("CI")
)
split$breaks
#> [1] 3