Title: | Robust Re-Scaling to Better Recover Latent Effects in Data |
---|---|
Description: | Non-linear transformations of data to better discover latent effects. Applies a sequence of three transformations (1) a Gaussianizing transformation, (2) a Z-score transformation, and (3) an outlier removal transformation. A publication describing the method has the following citation: Gregory J. Hunt, Mark A. Dane, James E. Korkola, Laura M. Heiser & Johann A. Gagnon-Bartsch (2020) "Automatic Transformation and Integration to Improve Visualization and Discovery of Latent Effects in Imaging Data", Journal of Computational and Graphical Statistics, <doi:10.1080/10618600.2020.1741379>. |
Authors: | Gregory Hunt [aut, cre], Johann Gagnon-Bartsch [aut] |
Maintainer: | Gregory Hunt <[email protected]> |
License: | GPL-3 |
Version: | 1.0 |
Built: | 2025-02-07 03:42:26 UTC |
Source: | https://github.com/cran/rrscale |
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
asinh
asinh
An object of class list
of length 2.
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation
T_deriv the transformation with arguments Y, the data, lambda the parameter.
box_cox
box_cox
An object of class list
of length 2.
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
box_cox_exp
box_cox_exp
An object of class list
of length 2.
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
box_cox_negative
box_cox_negative
An object of class list
of length 2.
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
box_cox_plus1
box_cox_plus1
An object of class list
of length 2.
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
box_cox_plusmin
box_cox_plusmin
An object of class list
of length 2.
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation. The parameter lambda has two real elements (1) the power and (2) the additive shift to the data.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
box_cox_shift
box_cox_shift
An object of class list
of length 2.
Centers the data column-wise
center(x)
center(x)
x |
the data. |
Calculate the geometric mean
gm_mean(x)
gm_mean(x)
x |
the data. |
Y <- rlnorm(10) gm <- gm_mean(Y)
Y <- rlnorm(10) gm <- gm_mean(Y)
Returns list of transformations. Each transformation is a transformation function (“T”) accepting a parameter and the derivative of this transformation function (“T_deriv”).
list_transformations()
list_transformations()
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
log_box_cox
log_box_cox
An object of class list
of length 2.
T the transformation with arguments Y, the data, lambda the parameter, and boolean inverse to calculate inverse transformation.
T_deriv the transformation with arguments Y, the data, lambda the parameter.
power
power
An object of class list
of length 2.
This transformation is three steps (1) Gaussianize the data, (2) z-score Transform the data, and (3) remove extreme outliers from the data. The sequence of these transformations helps focus further analyses on consequential variance in the data rather than having it be focused on variation resulting from the feature's measurement scale or outliers.
rrscale( Y, trans_list = list(box_cox_negative = box_cox_negative, asinh = asinh), lims_list = list(box_cox_negative = c(-100, 100), asinh = list(0, 100)), opt_control = NULL, opt_method = "DEoptim", z = 4, q = 0.001, verbose = FALSE, log_dir = ".rrscale/", zeros = FALSE, opts = FALSE, seed = NULL )
rrscale( Y, trans_list = list(box_cox_negative = box_cox_negative, asinh = asinh), lims_list = list(box_cox_negative = c(-100, 100), asinh = list(0, 100)), opt_control = NULL, opt_method = "DEoptim", z = 4, q = 0.001, verbose = FALSE, log_dir = ".rrscale/", zeros = FALSE, opts = FALSE, seed = NULL )
Y |
Data matrix, data.frame, or list of vectors, to be transformed. |
trans_list |
List of transformations to be considered. See function list_transformations. Each element of the list should be a list containing the transformation function as the first element and the derivative of the transformation function as the second argument. The first argument of each function should be the data, the second the transformation parameter. |
lims_list |
List of optimization limits for each transformation from trans_list. This should be a list the same length as |
opt_control |
Optional optimization controlling parameters for DEoptim control argument. See the DEoptim package for details. |
opt_method |
Which optimization method to use. Defaults to DEoptim. Other choice is nloptr. |
z |
The O-step cutoff value. Points are removed if their robust z-score is above z in magnitude. |
q |
The Z-step winsorizing quantile cutoff. The quantile at which to winsorize the data when calculating the robust z-scores. |
verbose |
a boolean, if TRUE then save optimization output in log_dir. |
log_dir |
directory for verbose output. Defaults to ".rrscale/" |
zeros |
How to deal with zeros in the data set. If set to FALSE the algorithm will fail if it encounters a zero. If set to a number or 'NA' then the zeros are replaced by this number or 'NA'. |
opts |
Boolean determining if optimization output is returned. Defaults to FALSE. |
seed |
Sets the seed before running any other analyses. |
A list of output:
opts: the optimization output for all transformation families and all columns
pars: the optimal parameters for each column for the optimal family
par_hat: the estimated optimal paramter
NT: the original data
RR: the robust-rescaled data
G: gaussianized data
Z: robust z-transformed data
O: data with outliers removed
rr_fn: a function to apply the estimated RR transformation to new data. Takes arguments
Y: the data,
z: the z-score cutoff (defaults to 4),
q: the winsorizing quantile cutoff (defaults to 0.001),
lambda: the transformation parameter to use (defaults to the estimated one),
T: the transformation function family (defaults to the optimal estimated family),
mu: the mean to be used in the robust z-score step (re-estimates if NULL)
sigma: the s.d. to be used in the robust z-score step (re-estimates if NULL)
T: the optimal family
T_deriv: the derivative of the optimal family
T_name: name of the optimal family
alg_control: the parameters passed to the algorithm
Y <- rlnorm(10)%*%t(rlnorm(10)) rr.out <- rrscale(Y) Yt <- rr.out$RR
Y <- rlnorm(10)%*%t(rlnorm(10)) rr.out <- rrscale(Y) Yt <- rr.out$RR
This calculates right and left singular vectors of a data matrix possibly containing missing values.
svdc(X, nu = NULL, nv = NULL)
svdc(X, nu = NULL, nv = NULL)
X |
the data matrix of which to calcluate the completed SVD. |
nu |
the number of left singular vectors to calculate |
nv |
the nubmer of right singular vectors to calculate |
Y <- rnorm(10)%*%t(rnorm(10)) Y[1,1] <- NA svdc.out <- svdc(Y)
Y <- rnorm(10)%*%t(rnorm(10)) Y[1,1] <- NA svdc.out <- svdc(Y)
Winsorizes the data
winsor(x, fraction = 0.01)
winsor(x, fraction = 0.01)
x |
the data. |
fraction |
the top and bottom quantiles to cap. |
Y <- rlnorm(10)%*%t(rlnorm(10)) Yw <- winsor(Y,1E-2)
Y <- rlnorm(10)%*%t(rlnorm(10)) Yw <- winsor(Y,1E-2)