1. What is Quantile Normalisation for?

2. Generate input data data

n = 1000
x = rbeta(n, 2, 5)
hist(x, breaks = 25, col = "red")

3. Transform

3.1. Rank the empirical data

  • an integer value is assigned to each datapoint
rank.x <- rank(x, na.last = "keep")  # returns the sample ranks 
head (rank.x, 20)
##  [1] 279 782 411 488 379 283 856 166   2 381 177 590 717 133 161 122 595
## [18] 673 404 502

3.2. Scale ranks to the interval

  • scale to interval \((0, 1)\), optionally with some offset \(k\)
    • divide by \(n + 1\)
    • optionally, modify using a contsnt that
k = 0          #  offset; within the interval (0,0.5)
scaled.ranks = (rank.x - k)/(n - 2*k + 1)
summary(scaled.ranks)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## 0.000999 0.250499 0.500000 0.500000 0.749501 0.999001
k = 3/8        # Blom     
scaled.ranks = (rank.x - k)/(n - 2*k + 1)
summary(scaled.ranks)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## 0.0006248 0.2503124 0.5000000 0.5000000 0.7496876 0.9993752

3.3. Apply \(\Phi^{-1}\) on scaled ranks

  • Get the quantiles of the standard normal distribution from the scaled ranks
    • that is the inverse of the CDF
normalized = qnorm(scaled.ranks) 
summary(normalized)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -3.2273 -0.6735  0.0000  0.0000  0.6735  3.2273
hist(normalized, breaks = 25, col = "red")

4. Function

4.1 Function definition

quant_normal <- function(x, k = 3/8) {
  if (!is.vector(x)) stop("A numeric vector is expected for x.")   
  if ((k < 0) || (k > 0.5)) stop("Select the offset within the interval (0,0.5).")   
  n <- length(na.omit(x))
  rank.x <- rank(x, na.last = "keep")
  normalized = qnorm((rank.x - k)/(n - 2*k + 1))
  return(normalized)
}

4.2. Function call

Why does this work?

##  [1] -2.3263479 -1.5632236 -1.2372346 -1.0068643 -0.8203791 -0.6588377
##  [7] -0.5129304 -0.3772336 -0.2481737 -0.1231352  0.0000000  0.1231352
## [13]  0.2481737  0.3772336  0.5129304  0.6588377  0.8203791  1.0068643
## [19]  1.2372346  1.5632236  2.3263479

##  [1] -2.3263479 -1.5632236 -1.2372346 -1.0068643 -0.8203791 -0.6588377
##  [7] -0.5129304 -0.3772336 -0.2481737 -0.1231352  0.0000000  0.1231352
## [13]  0.2481737  0.3772336  0.5129304  0.6588377  0.8203791  1.0068643
## [19]  1.2372346  1.5632236  2.3263479


Help me improve this site: uwe.menzel@matstat.org