Fit normalization parameters on the stable interior of a distribution
Source:R/normalize-x.R
find_best_normalization.RdWinsorizes x, isolates the stable (non-sentinel, non-NA) interior,
selects a transformation type, fits its parameters and centering/scaling
constants, and returns a normalize_x_fit object that can be reused via
apply_normalization().
Separating fitting from scoring allows the same fitted model to be applied to new data (e.g. a holdout year) without re-estimating parameters, and ensures that sentinel observations do not distort the center and spread estimates used for standardization.
Arguments
- x
Numeric vector to fit on.
- range
Character range code (
"np","zp","zo","nz", or"lo;hi"). Required.- vtype
Optional transformation type override. One of
NULL(auto-detect),"asinh","logit","rank_normal","hurdle".- winsorize
Winsorization proportion. Default
0.98.- offset
Sentinel offset for fixed bounds. Default
0.001.- standardize
Logical. If
TRUE, fit centering and scaling constants. DefaultTRUE.- robust
Logical. If
TRUE, use median/MAD; otherwise mean/SD. DefaultTRUE.- zero_tol
Tolerance for zero detection. Default
1e-8.- one_tol
Tolerance for near-one detection. Default
1e-8.- boundary_mass_cutoff
Hurdle/rank_normal trigger threshold. Default
0.10.- hurdle_trans
Positive-part transformation for hurdle variables.
"rank"(default) or"logit".- hurdle_range
Rescaled output range for hurdle positive component. Default
c(1, 100).- verbose
Logical. If
TRUE, print a diagnostic summary. DefaultTRUE.
Value
An object of class normalize_x_fit — a named list containing
transformation type, parameters, centering/scaling constants, and
diagnostics. Pass this object to apply_normalization().