lehmer_mean: Lehmer mean

Description Usage Arguments Details Value Note References See Also Examples

Description

Calculate a Lehmer mean.

Usage

1
2
3
mean_lehmer(r)

mean_contraharmonic(x, w = rep(1, length(x)), na.rm = FALSE)

Arguments

r

A finite number giving the order of the Lehmer mean.

x

A strictly positive numeric vector.

w

A strictly positive numeric vector of weights, the same length as x. The default is to equally weight each element of x.

na.rm

Should missing values in x and w be removed?

Details

The function mean_lehmer() returns a function to compute the Lehmer mean of order r of x with weights w, which is calculated as the arithmetic mean of x with weights w * x^(r-1). This is also called the counter-harmonic mean. See Bullen (2003, p. 245) for a definition, or https://en.wikipedia.org/wiki/Lehmer_mean.

The Lehmer mean of order 2 is sometimes called the contraharmonic mean. The function mean_contraharmonic() simply calls mean_lehmer(2)(). Like the generalized mean, the contraharmonic mean is the solution to an optimal prediction problem: choose m to minimize ∑ w (x / m - 1)^2. The Lehmer mean of order -1 has a similar interpretation, replacing x / m with m / x, and together these bound the harmonic and arithmetic means.

Both x and w should be strictly positive. This is not enforced, but the results may not make sense if the Lehmer mean in not defined.

The Lehmer mean is an alternative to the generalized mean that generalizes the Pythagorean means. The function mean_lehmer(1)() is identical to mean_artithmetic(), mean_lehmer(0)() is identical to mean_harmonic(), and mean_lehmer(0.5)() is identical to mean_geometric() with two values and no weights.

Value

mean_lehmer() returns a function:

function(x, w = rep(1, length(x)), na.rm = FALSE).

mean_contraharmonic() returns a numeric value.

Note

mean_lehmer() can be defined on the extended real line, so that r = -Inf/Inf returns min()/max(), to agree with the definition in, e.g., Bullen (2003). This is not implemented, and r must be finite.

References

Bullen, P. S. (2003). Handbook of Means and Their Inequalities. Springer Science+Business Media.

Lehmer, D. H. (1971). On the Compounding of Certain Means. Journal of Mathematical Analysis and Applications, 36(1): 183-200.

See Also

mean_generalized for the generalized mean, an alternative to the Lehmer mean.

logmean_generalized for the generalized logarithmic mean.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Make some data

x <- 2:3
w <- c(0.25, 0.75)

# The Pythagorean means are special cases of the Lehmer mean

all.equal(mean_lehmer(1)(x, w), mean_arithmetic(x, w))
all.equal(mean_lehmer(0)(x, w), mean_harmonic(x, w))
all.equal(mean_lehmer(0.5)(x), mean_geometric(x))

#--------------------

# When r < 1, the generalized mean is larger than the corresponding
# Lehmer mean

mean_lehmer(-1)(x, w) < mean_generalized(-1)(x, w)

# The reverse is true when r > 1

mean_lehmer(3)(x, w) > mean_generalized(3)(x, w)

# This implies the contraharmonic mean is larger than the quadratic
# mean, and therefore the Pythagorean means

mean_contraharmonic(x, w) > mean_arithmetic(x, w)
mean_contraharmonic(x, w) > mean_geometric(x, w)
mean_contraharmonic(x, w) > mean_harmonic(x, w)

# and the logarithmic mean

mean_contraharmonic(2:3) > logmean(2, 3)

# The difference between the arithmetic mean and contraharmonic mean
# is proportional to the variance of x

weighted_var <- function(x, w) mean_arithmetic(x^2, w) - mean_arithmetic(x, w)^2

mean_arithmetic(x, w) + weighted_var(x, w) / mean_arithmetic(x, w)
mean_contraharmonic(x, w)

#--------------------

# It is easy to modify the weights to turn a Lehmer mean of order r
# into a Lehmer mean of order s because the Lehmer mean can be expressed
# as an arithmetic mean

r <- 2
s <- -3
mean_lehmer(r)(x, w)
mean_lehmer(s)(x, w * x^(r - 1) / x^(s - 1))

# The weights can also be modified to turn a Lehmer mean of order r
# into a generalized mean of order s

mean_lehmer(r)(x, w)
mean_generalized(s)(x, weights_transmute(1, s)(x, w * x^(r - 1)))

# and vice versa

mean_lehmer(r)(x, weights_transmute(s, 1)(x, w) / x^(r - 1))
mean_generalized(s)(x, w)

#--------------------

# Quote contributions for a price index based on the Lehmer mean
# are easy to calculate

weights_scale(w * x^(r - 1)) * (x - 1)

gpindex documentation built on Feb. 3, 2021, 1:06 a.m.