Build a split-selection function for inequality-aware tree fitting. The returned function evaluates candidate predictors by the reduction in within-node concentration index produced by each admissible split.
Usage
ci_splitfun(rank_name, outcome_name, type = c("CI", "CIg", "CIc", "L"))Arguments
- rank_name
Name of the socioeconomic rank variable in the model frame when the response is not supplied as a two-column matrix.
- outcome_name
Name of the outcome variable in the model frame when the response is not supplied as a two-column matrix.
- type
One of
"CI","CIg","CIc", or"L"selecting the inequality index used for split scoring."L"uses observed socioeconomic levels in the first response column rather than fractional ranks.
Value
A function with signature
function(model, trafo, data, subset, weights, whichvar, ctrl) suitable
for tree-splitting workflows. It returns the first admissible partysplit
found among whichvar, or NULL if no candidate variable yields a valid
split.
Details
The split function can recover the two-column response either from a matrix-
like response in the first model-frame column, or from separate columns named
by rank_name and outcome_name.
Examples
data(kenya, package = "ineqTrees")
kenya_model_vars <- c(
"wealth",
"deadu5_num",
"rural",
"ed",
"reg",
"unskilled"
)
kenya_model_data <- kenya[
stats::complete.cases(kenya[, kenya_model_vars]),
kenya_model_vars
]
set.seed(20260512)
kenya_model_data <- kenya_model_data[
sample.int(nrow(kenya_model_data), 800L),
,
drop = FALSE
]
splitfun <- ci_splitfun(
rank_name = "wealth",
outcome_name = "deadu5_num",
type = "CI"
)
ctrl <- ci_tree_control(minsplit = 100, minbucket = 50, minprob = 0.05)
split <- splitfun(
model = NULL,
trafo = NULL,
data = kenya_model_data,
subset = seq_len(nrow(kenya_model_data)),
weights = rep(1, nrow(kenya_model_data)),
whichvar = match("reg", names(kenya_model_data)),
ctrl = ctrl
)
partykit::character_split(split, kenya_model_data)
#> $name
#> [1] "reg"
#>
#> $levels
#> [1] "Lamu, Taita Taveta, Garissa, Isiolo, Meru, Kitui, Machakos, Nyandarua, Nyeri, Kirinyaga, Murang'a, Trans Nzoia, Nandi, Baringo, Laikipia, Nakuru, Kajiado, Vihiga, Busia, Kisumu, Migori, Nairobi"
#> [2] "Mombasa, Kwale, Kilifi, Tana River, Wajir, Mandera, Marsabit, Tharaka-Nithi, Embu, Makueni, Kiambu, Turkana, West Pokot, Samburu, Uasin Gishu, Elgeyo-Marakwet, Narok, Kericho, Bomet, Kakamega, Bungoma, Siaya, Homa Bay, Kisii, Nyamira"
#>