Find Quantile for Target Subgroup Proportion
Source:R/find_k_inter_main.R
find_quantile_for_proportion.RdDetermines the quantile cutpoint that achieves a target proportion of observations in a subgroup. Useful for calibrating subgroup sizes.
Arguments
- data
A data.frame containing the variable of interest
- var_name
Character string specifying the variable name to analyze
- target_prop
Numeric value between 0 and 1 specifying the target proportion of observations to be included in the subgroup
- direction
Character string: "less" for values <= cutpoint (default), "greater" for values > cutpoint
- tol
Numeric tolerance for root finding algorithm. Default is 0.0001
Value
A list containing:
- quantile
The quantile value (between 0 and 1) that achieves the target proportion
- cutpoint
The actual data value corresponding to this quantile
- actual_proportion
The achieved proportion (should equal target_prop within tolerance)
Details
This function uses root finding (uniroot) to determine the quantile
that results in exactly the target proportion of observations being classified
into the subgroup. This is particularly useful when you want to ensure a
specific subgroup size regardless of the data distribution.
Examples
if (FALSE) { # \dontrun{
gbsg <- survival::gbsg
# Find ER cutpoint for 12.5% subgroup
result <- find_quantile_for_proportion(
data = gbsg,
var_name = "er",
target_prop = 0.125,
direction = "less"
)
print(result)
# Use in subgroup definition
subgroup_cuts = list(
er = list(type = "quantile", value = result$quantile)
)
} # }