# The mean of natural log of some data

I have the following data in natural log:

N = [0.929, -1.745, 1.677, 0.701, 0.128]

O = [2.233, -2.513, 1.204, 1.938, 2.533]


I want to calculate the mean ratio of these two data sets. Since they are in natural log, I took the difference of the data sets, which is equal to

[1.304, -0.768, -0.473, 1.237, 2.405]


Then I computed the mean, and it was equal to 0.741, however, the correct mean is 1.29.

How is the correct answer is 1.29?

• The ratio is the exponential of the difference in logs. – whuber Jan 9 at 17:17
• Welcome to Cross Validated! What should I do when someone answers my question?. – MarianD Jan 10 at 23:33
• @whuber, yeah I should have exponentiated the difference, thanks a lot. – Ramy Maher Jan 11 at 9:14

If you have datapoints $$x_1, \ldots, x_n$$ and $$y_1, \ldots, y_n$$ and you want to find the mean ratio $$\frac{1}{n} \sum_{i=1}^n \frac{x_i}{y_i}$$, this is not equal to the exponentiated mean of the log ratios. In other words, this is not the same as computing $$\exp\left(\frac{1}{n}\sum_{i=1}^n \log \frac{x_i}{y_i}\right)$$, which is what it sounds like you are finding. Your quantity instead equals

$$\exp\left(\frac{1}{n}\sum_{i=1}^n \log \frac{x_i}{y_i}\right) = \exp\left(\frac{1}{n} \log \left(\prod_{i=1}^n \frac{x_i}{y_i}\right)\right) = \left(\prod_{i=1}^n \frac{x_i}{y_i}\right)^{\frac{1}{n}}$$

which is the geometric mean of the ratios.

• I believe the question meant the mean of the ratio, not the geometric mean. Thanks a lot for your explanations I appreciate it. – Ramy Maher Jan 11 at 9:19
• I understand -- I am saying that the way in which you computed your answer to get 0.741 is actually finding the log of the geometric mean, so that is why your answer is different from what you expected. – Izzy Jan 11 at 17:53

You calculated the mean of logarithms of ratios, not the mean of ratios themselves.

To obtain ratios from their logarithms, you have to raise $$e$$ to power of them.

In Python and NumPy:

import numpy as np

logs = [1.304, -0.768, -0.473, 1.237, 2.405]     # Logarithms of ratios
ratios = np.exp(logs)                            # You omitted this!

np.mean(ratios)

• Yes, you are right, I have omitted that, but the result of that is 3.859. The confidence interval is [0.09,2.49], which implies that the mean is 1.29. Thank you very much for your help. – Ramy Maher Jan 10 at 11:28
• @RamyMaher, you're welcome. Your confidence interval is probably calculated from the other, larger sample, so it is questionable to expect the resulted mean 3.859 will be in such an interval. With your sample data, the resulted mean is correct. – MarianD Jan 10 at 23:31

I have known what exactly I have done wrongly.

The exact solution in R is as follows:

dif=(New-Old)

m=mean(dif)

st=sd(dif)

CI=m+c(-1,1)*qt(0.975,4)*st *sqrt(1/5)

ExpCI=exp(CI) # equals [0.09 2.49]

MEAN=mean(ExpCI) # equals 1.29