
Perform quantile normalization on a numeric matrix/data.frame
Source:R/utils-quantile-normalize.R
quantile_normalize.Rd
This function will perform quantile normalization on two or more distributions of equal length. Quantile normalization is a technique used to make the distribution of values across different samples more similar. It ensures that the distributions of values for each sample have the same quantiles. This function takes a numeric matrix as input and returns a quantile-normalized matrix.
Value
A numeric matrix (or tibble if .return_tibble = TRUE) that has been quantile normalized. Each column represents a sample, and the quantile normalization ensures that the distributions of values for each sample have the same quantiles.
Details
This function performs quantile normalization on a numeric matrix by following these steps:
Sort each column of the input matrix.
Calculate the mean of each row across the sorted columns.
Replace each column's sorted values with the row means.
Unsort the columns to their original order.
See also
rowMeans
: Calculate row means.
apply
: Apply a function over the margins of an array.
order
: Order the elements of a vector.
Other Utility:
check_duplicate_rows()
,
convert_to_ts()
,
tidy_mcmc_sampling()
,
util_beta_aic()
,
util_binomial_aic()
,
util_cauchy_aic()
,
util_chisq_aic()
,
util_exponential_aic()
,
util_f_aic()
,
util_gamma_aic()
,
util_generalized_beta_aic()
,
util_generalized_pareto_aic()
,
util_geometric_aic()
,
util_hypergeometric_aic()
,
util_inverse_burr_aic()
,
util_inverse_pareto_aic()
,
util_inverse_weibull_aic()
,
util_logistic_aic()
,
util_lognormal_aic()
,
util_negative_binomial_aic()
,
util_normal_aic()
,
util_paralogistic_aic()
,
util_pareto1_aic()
,
util_pareto_aic()
,
util_poisson_aic()
,
util_t_aic()
,
util_triangular_aic()
,
util_uniform_aic()
,
util_weibull_aic()
,
util_zero_truncated_binomial_aic()
,
util_zero_truncated_geometric_aic()
,
util_zero_truncated_negative_binomial_aic()
,
util_zero_truncated_poisson_aic()
Examples
# Create a sample numeric matrix
data <- matrix(rnorm(20), ncol = 4)
# Perform quantile normalization
normalized_data <- quantile_normalize(data)
normalized_data
#> [,1] [,2] [,3] [,4]
#> [1,] 1.54004626 1.54004626 -0.42145863 -0.42145863
#> [2,] 0.09638238 0.37319866 0.09638238 0.09638238
#> [3,] -1.50679669 -0.42145863 0.37319866 0.37319866
#> [4,] -0.42145863 0.09638238 1.54004626 1.54004626
#> [5,] 0.37319866 -1.50679669 -1.50679669 -1.50679669
as.data.frame(normalized_data) |>
sapply(function(x) quantile(x, probs = seq(0, 1, 1 / 4)))
#> V1 V2 V3 V4
#> 0% -1.50679669 -1.50679669 -1.50679669 -1.50679669
#> 25% -0.42145863 -0.42145863 -0.42145863 -0.42145863
#> 50% 0.09638238 0.09638238 0.09638238 0.09638238
#> 75% 0.37319866 0.37319866 0.37319866 0.37319866
#> 100% 1.54004626 1.54004626 1.54004626 1.54004626
quantile_normalize(
data.frame(rnorm(30),
rnorm(30)),
.return_tibble = TRUE)
#> # A tibble: 30 × 2
#> rnorm.30. rnorm.30..1
#> <dbl> <dbl>
#> 1 -0.434 -0.694
#> 2 0.649 -0.445
#> 3 -1.88 -0.162
#> 4 0.683 0.263
#> 5 -1.14 0.600
#> 6 -0.298 -0.898
#> 7 -0.996 -0.996
#> 8 -1.52 -1.19
#> 9 0.229 1.82
#> 10 -0.898 -0.104
#> # ℹ 20 more rows