d3 / d3

Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

Home Page:https://d3js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add harmonic mean and geometric mean

lulunac27a opened this issue · comments

Harmonic mean is the sum of all reciprocals (which is one divided by a number), and the geometric mean is the product of numbers raised to one divided by number of items in a list.
Harmonic mean = $\dfrac{n}{x_{1} + x_{2} + x_{3} + ... + x_{n}}$
For example, the harmonic mean of 2, 3, and 5 is 3/(1/2+1/3+1/5) = 3/(15/30+10/30+6/30) = 3/(31/30) = 3*30/31 = 90/31 = 2 28/30 = 2 14/15
Geometric mean = $\sqrt[n]{{x_{1} \times x_{2} \times x_{3} \times ... \times x_{n}}}$

For example, the geometric mean of 2, 3, and 5 is (235)^(1/3)=30^(1/3)=3.1072

Sources:
https://byjus.com/maths/harmonic-mean/
https://www.scribbr.com/statistics/geometric-mean/

For an harmonic mean I don't think there is much more to do than X => 1 / d3.mean(X, d => 1/d).

For a geometric mean, see https://observablehq.com/@fil/d3-gmdn (the notebook is not only about the gmdn “joke”, it contains a solid implementation of the geometric mean). Task tracked at d3/d3-array#194