0
$\begingroup$

In the function normalizeMedianValues in the package limma, column counts are normalised such that their column medians are equal to the average of the column medians.

What I'd like to understand is why the medians are first log transformed, followed by the subtraction of the mean medians, then reversed with an exp() function. What is the mathematical or statistical reasoning behind this? What happens if you don't do the log or exp transformation? Here is the code:

normalizeMedianValues <- function(x) 
#   Normalize columns of a matrix to have the same median value
#   Gordon Smyth
#   24 Jan 2011.  Last modified 24 Jan 2011.
{
    narrays <- NCOL(x)
    if(narrays==1) return(x)
    cmed <- log(apply(x, 2, median, na.rm=TRUE))
    cmed <- exp(cmed - mean(cmed))
    t(t(x)/cmed)
}

M <- cbind(Array1=rnorm(10, mean = 100),Array2=2*rnorm(10, mean = 100))

normalizeMedianValues(M)
$\endgroup$

1 Answer 1

1
$\begingroup$

In your example, the normalised values are about the same size as the original values. That's the point of subtracting the log mean. If you instead used

normalizeMedianValues1<- function(x) {
    narrays <- NCOL(x)
    if(narrays==1) return(x)
    cmed <- apply(x, 2, median, na.rm=TRUE)
    t(t(x)/cmed)
}

the normalised values would all be around 1.

Another way to write the code, which might be clearer, is

    cmed <- apply(x, 2, median, na.rm=TRUE)
    scale<-exp(mean(log(cmed)))
    t(t(x)/cmed)*scale

We divide each column by its median, making them all have a median of 1, then multiply by the geometric mean of the medians, so the normalised columns all have a median that's equal to scale, a value in the middle of the data range in some sense.

$\endgroup$
1
  • $\begingroup$ Great answer, your alternative way of writing the code really helped me understand the problem (and develop a better way of writing a function that works in long-format data). My initial question was really focused on the rationale for exp(mean(log(cmed))), but I now know its the geometric mean (which I've heard of but never really used). I'm guessing its used here over arithmetic mean purely because it is better suited to skewed values? $\endgroup$
    – SpikyClip
    Jul 2, 2023 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.