e_scale_align: Align the distribution of one empirical distribution to an...

View source: R/e_scale_align.R

e_scale_alignR Documentation

Align the distribution of one empirical distribution to an empirical reference distribution

Description

Align the distribution of one empirical distribution to an empirical reference distribution

Usage

e_scale_align(
  var_to_scale = NULL,
  var_ref = NULL,
  scale_method = c("quantile", "zscore")[1],
  quantiles_to_match = c(0.1, 0.9),
  sw_plot = c(TRUE, FALSE)[2]
)

Arguments

var_to_scale

Variable to rescale

var_ref

Reference variable distribution

scale_method

Method of rescaling. "quantile" with c(0.1, 0.9) is remarkably good.

quantiles_to_match

For "quantile", which quantiles to match.

sw_plot

T/F to plot Reference, Original, and Scaled variables.

Value

var_scaled Scaled vector (NAs have been removed)

Examples

set.seed(76543)
e_scale_align(
  var_to_scale        = c(NA, rgamma( 40, shape = 3, rate = 2) + 4, NA)
, var_ref             = rgamma(100, shape = 3, rate = 1)
, scale_method        = c("quantile", "zscore")[1]
, quantiles_to_match  = c(0.1, 0.9)
, sw_plot             = c(TRUE, FALSE)[1]
)
set.seed(76543)
e_scale_align(
  var_to_scale        = c(NA, rgamma( 40, shape = 3, rate = 2) + 4, NA)
, var_ref             = rgamma(100, shape = 3, rate = 1)
, scale_method        = c("quantile", "zscore")[2]
, sw_plot             = c(TRUE, FALSE)[1]
)
# Scale to c(0, 1) bounded
e_scale_align(
  var_to_scale        = rnorm(100) |> sort()
, var_ref             = c(0, 1)
, scale_method        = c("quantile", "zscore")[1]
, quantiles_to_match  = c(0, 1)
, sw_plot             = c(TRUE, FALSE)[2]
)

erikerhardt/erikmisc documentation built on April 17, 2025, 10:48 a.m.