I'm trying to describe mean differences between two populations $x_1$ and $x_2$, which are non-zero and positive. Their distribution is approximately beta with a positive skew. For example, with R:

# x1 <- round(rbeta(10, 1, 100)*1000, 1)
# x2 <- x1 + round(rbeta(10, 1, 100)*100, 1)
x1 <- c(1.7, 12.6, 22.3, 37.3, 15.2, 7.1, 31, 4.4, 9.5, 1.9)
x2 <- c(1.9, 14.2, 25.6, 39.2, 15.9, 8.7, 32.2, 7, 9.7, 1.9)

The two ways I can think of to determine the mean relative differences yield different numbers:

mean((x2 - x1)/x1)             # 0.1365628
(mean(x2) - mean(x1))/mean(x1) # 0.09300699

Why are they different, and which method is more descriptive of what I'm looking for? I.e., is $x_2$ 13.6% or 9.3% greater than $x_1$?


3 Answers 3


In the first formula, mean((x1 - x2)/x1) you are describing the differences between paired members of each group, (Wikipedia). Think of individuals before and after treatment.

In the second formula, (mean(x2) - mean(x1))/mean(x1), you are describing the differences between two, presumably independent, groups as a whole. Think of two independent samples.

Perhaps if you rephrase your question the answer will become apparent.

  1. What is the mean difference between individuals?
  2. What is the difference between the means of two groups?

It's difficult to determine what you are attempting from your example since x2 is derived from x1. From your description I would lean toward #2 since you mention 2 populations. However, from your R example I would lean to #1 since it looks like you are simulating some effect on individuals.

  • $\begingroup$ Thanks for reading in-between the lines. Yes, x1 and x2 are in fact time-series results of scenarios based on the same input data. Thus the first equation is more descriptive of describing the mean differences between individual days. $\endgroup$
    – Mike T
    Commented Jan 24, 2012 at 20:30

They are different because of Jensen's inequality: an expected value of a nonlinear function is not equal to the nonlinear function of expected values.

I am not sure we can answer the question of what's better for you. If x1 is close to zero, then the first method would generate Cauchy normal variates, and if the population mean is zero, so would the second method. If both population means are zeroes, then whatever you do with them in terms of their ratios will end up as 0/0.


If you use an approximation of R's all.equal you have

$$ \begin{aligned} \text{Mean Relative Difference (MRD)} &= \frac{1}{N \times \text{scale}} \sum_{i=1}^{N} |target_i - current_i| \\ \text{where scale } &= \frac{1}{N} \sum_{i=1}^{N} |target_i| \end{aligned} $$

or in code as

# based of all.equal.numeric
my.all.equal <- function(target, current){ # similar to all.equal
  N <- length(target)
  scale <- (sum(abs(target)/N))
  sum(abs(target - current)/(N * scale))}

Thus, for your problem

target <- c(1.7, 12.6, 22.3, 37.3, 15.2, 7.1, 31, 4.4, 9.5, 1.9)
current <- c(1.9, 14.2, 25.6, 39.2, 15.9, 8.7, 32.2, 7, 9.7, 1.9)
> all.equal(target, current)
[1] "Mean relative difference: 0.09425939"
> my.all.equal(target, current)
[1] 0.09300699

So you can see my.all.equal and (mean(x2) - mean(x1))/mean(x1) round to the same number

(mean(x2) - mean(x1))/mean(x1) # 0.09300699

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.