means: Generalized means

Description Usage Arguments Notice See Also Examples

Description

Harmonic, geometric, quadratic, cubic, power and Lehmer means.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
harm(x, na.rm = TRUE)

geom(x, zero.rule = c("1p", "rm", "1"), na.rm = TRUE)

quad(x, na.rm = TRUE)

cubi(x, na.rm = TRUE)

powr(x, p = 1.5, na.rm = TRUE)

lehm(x, p = 2, na.rm = TRUE)

Arguments

x

numeric vector of values whose *mean is to be computed

na.rm

logical; should NA values be removed? (default TRUE)

zero.rule

for the geometric mean, how should zeros be dealt with? Add one before, and subtract one after the calculation (see lop1p), remove all zeros, or replace all zeros with 1.

p

exponential power. For the power mean p=-1, p=2 and p=3 gives the harmonic, quadratic and cubic means, respectively. For the Lehmer mean p=0, p=1 and p=2 gives the harmonic, arithmetic and contraharmonic means, respectively.

Notice

For some of these means zeros and/or negative values are undefined, or make otherwise little sense in context. Workarounds are given for the geometric mean, but if you end up using it on data ≤ 0, the wise call would be to reconsider whether using a geometric mean really makes sense in that case.

See Also

central.tendency

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
funl <- substitute(c(harm, geom, mean, quad, cubi))

xl <- list(c( 1, 2, 3, 5),
           c(-1, 1, 2, 3, 5),
           c( 0, 1, 2, 3, 5),
           c(-1, 0, 1, 2, 3, 5))

m <- sapply(xl, function(x) sapply(eval(funl), function(f) f(x)))
rownames(m) <- as.character(funl)[-1]
colnames(m) <- c("posi", "1neg", "zero", "1ngz")
round(m, 3)

harm(xl[[1]]); powr(xl[[1]], -1); lehm(xl[[1]], 0)

y <- c(0, 1, 5, 0, 6, 5, 9)

geom(y, zero.rule="1p")
geom(y, zero.rule="rm")
geom(y, zero.rule="1")

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.