R: Harmonic Mean and Its Confidence Interval

Hmean {DescTools} | R Documentation

## Harmonic Mean and Its Confidence Interval

### Description

Calculates the harmonic mean and its confidence interval of a vector x.

### Usage

    Hmean(x, method = c("classic", "boot"), conf.level = NA,
          sides = c("two.sided","left","right"), na.rm = FALSE, ...)

### Arguments

`x` | a positive numeric vector. An object which is not a vector is coerced (if possible) by as.vector.
`method` | a vector of character strings representing the type of intervals required. The value should be any subset of the values `"classic"`, `"boot"`. See `boot.ci`.
`conf.level` | confidence level of the interval. Default is `NA`.
`sides` | a character string specifying the side of the confidence interval, must be one of `"two.sided"` (default), `"left"` or `"right"`. You can specify just the initial letter. `"left"` would be analogue to a hypothesis of `"greater"` in a `t.test`.
`na.rm` | logical, indicating whether `NA` values should be stripped before the computation proceeds. Defaults to `FALSE`.
`...` | further arguments are passed to the `boot` function. Supported arguments are `type` (`"norm"`, `"basic"`, `"stud"`, `"perc"`, `"bca"`), `parallel` and the number of bootstrap replicates `R`. If not defined those will be set to their defaults, being `"basic"` for `type`, option `"boot.parallel"` (and if that is not set, `"no"`) for `parallel` and `999` for `R`.

### Details

To compute the harmonic mean, `1/x` is first calculated, before the arithmetic mean and its confidence interval are computed by `MeanCI`. The harmonic mean is then the reciprocal of the arithmetic mean of the reciprocals of the values. The same applies to the confidence interval.

The harmonic mean is restricted to strictly positive inputs, if any argument is negative, then the result will be `NA`. If the lower bound of the confidence interval is not greater than zero, then the confidence interval is not defined, and thus `NA` will be reported.

Use `sapply` to calculate the measures from data frame, resp. from a matrix.

### Value

a numeric value.

### Author(s)

Andri Signorell <andri@signorell.net>

### References

Snedecor, G. W., Cochran, W. G. (1989) Statistical Methods, 8th ed. Ames, IA: Iowa State University Press

### See Also

`Gmean`

### Examples

    x <- runif(5)
    Hmean(x)

    m <- matrix(runif(50), nrow = 10)
    apply(m, 2, Hmean)

    sapply(as.data.frame(m), Hmean)

[Package DescTools version 0.99.28 Index]