x <- 2:3
w <- c(0.25, 0.75)
# The Pythagorean means are special cases of the Lehmer mean.
all.equal(lehmer_mean(1)(x, w), arithmetic_mean(x, w))
all.equal(lehmer_mean(0)(x, w), harmonic_mean(x, w))
all.equal(lehmer_mean(0.5)(x), geometric_mean(x))
# When r < 1, the generalized mean is larger than the corresponding
# Lehmer mean.
lehmer_mean(-1)(x, w) < generalized_mean(-1)(x, w)
# The reverse is true when r > 1.
lehmer_mean(3)(x, w) > generalized_mean(3)(x, w)
# This implies the contraharmonic mean is larger than the quadratic
# mean, and therefore the Pythagorean means.
contraharmonic_mean(x, w) > arithmetic_mean(x, w)
contraharmonic_mean(x, w) > geometric_mean(x, w)
contraharmonic_mean(x, w) > harmonic_mean(x, w)
# ... and the logarithmic mean
contraharmonic_mean(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) {
arithmetic_mean((x - arithmetic_mean(x, w))^2, w)
}
arithmetic_mean(x, w) + weighted_var(x, w) / arithmetic_mean(x, w)
contraharmonic_mean(x, w)
Run the code above in your browser using DataLab