6. Pythagorean Means#

Suppose we have data points \(x_1, x_2, \dots, x_n\). The aritmetic mean, \(M_A\), which is the mean we are most familiar with is defined as follows,

\[ M_A = \frac{x_1 + x_2 + \dots + x_n}{n} \]

There are two other pythagorean means: the harmonic mean and the geometric mean. We will call these \(M_H\) and \(M_G\) respectively. They are defined as follows,

\[\begin{split} \begin{align} M_G &= \sqrt[n]{x_1 \cdot x_2 \dots x_n}, \\ M_H &= \frac{n}{\frac{1}{x_1} + \frac{1}{x_2} + \dots + \frac{1}{x_n}} \end{align} \end{split}\]

7. When should the geometric mean be used?#

The geometric mean should be used when your data can be naturally multiplied together. For example when working out the average return from compounding interest.

Let us suppose we invest £100 and get 10% return for 50 years (unrealistic I know). Calculate the aritmetic and geometric mean for this data.

import numpy as np
import matplotlib.pyplot as plt

n = 50
x = np.array([100 * 1.10 ** i for i in range(n)])
am = x.sum() / n
gm = x.prod() ** (1 / n)
hm = n / (1 / x).sum()

fig, ax = plt.subplots()
ax.plot(x)

mean_types = ["Arithmetic Mean", "Geometric Mean", "Harmonic Mean"]
colors = ["tab:orange", "tab:green", "tab:purple"]
for mean, mean_type, color in zip([am, gm, hm], mean_types, colors):
    ax.hlines(mean, 0, n, label=mean_type, linestyle="--", color=color)
    ax.legend()
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import numpy as np
      2 import matplotlib.pyplot as plt
      4 n = 50

ModuleNotFoundError: No module named 'numpy'