Gmean.Rd
Calculates the geometric mean, its confidence interval and the geometric standard deviation of a vector x.
a positive numeric vector. An object which is not a vector is coerced (if possible) by as.vector.
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
.
confidence level of the interval. Default is NA
.
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
.
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
.
The geometric mean is defined as: $$\sqrt[n]{x_{1}\cdot x_{2}\cdot x_{3} \ldots \cdot x_{n}}$$
The geometric mean and geometric standard deviation are restricted to positive inputs (because otherwise the answer can have an imaginary component). Hence if any argument is negative, the result will be NA
. If any argument is zero, then the geometric mean is zero.
For strict positive values the geometric mean is computed as exp(MeanCI(log(x)))
.
Considerations (Roenfeldt 2018)
"The calculation of the geometric mean requires that all values are non-zero and positive. So what should you do if you have data that do not meet this requirement? If you have values that equal zero, you have a few options:
Adjust your scale so that you add 1 to every number in the data set, and then subtract 1 from the resulting geometric mean.
Ignore zeros or missing data in your calculations.
Convert zeros to a very small number (often called "below the detection limit") that is less than the next smallest number in the data set.
If you have negative numbers, you will need to convert those numbers to a positive value before calculating the geometric mean. You can then assign the resulting geometric mean a negative value. If your data set contains both positive and negative values, you will have to separate them and find the geometric means for each group, and you can then find the weighted average of their individual geometric means to find the total geometric mean for the full data set. If none of these options appeals to you, you are not alone! There is controversy among statisticians about what is the best method for dealing with these values. You may want to calculate several types of averages and decide what makes the most sense for you and the results you are trying to report."
a numeric value.
Snedecor, G. W., Cochran, W. G. Cochran (1989) Statistical Methods, 8th ed. Ames, IA: Iowa State University Press
Roenfeldt K. (2018) Better than Average: Calculating Geometric Means Using SAS, Henry M. Jackson Foundation for the Advancement of Military Medicine, https://www.lexjansen.com/wuss/2018/56_Final_Paper_PDF.pdf
x <- runif(5)
Gmean(x)
#> [1] 0.5530259
m <- matrix(runif(50), nrow = 10)
apply(m, 2, Gmean)
#> [1] 0.4581177 0.3276712 0.5416991 0.6546986 0.1140152
sapply(as.data.frame(m), Gmean)
#> V1 V2 V3 V4 V5
#> 0.4581177 0.3276712 0.5416991 0.6546986 0.1140152
# ......................................................
# example in https://www.stata.com/manuals13/rameans.pdf
x <- c(5,4,-4,-5,0,0,NA,7)
# positives only
Gmean(x[x>0], na.rm=TRUE, conf.level=0.95)
#> mean lwr.ci upr.ci
#> 5.192494 2.578990 10.454477
# add 5 to original values and remove zeros
Gmean(NAIfZero(x+5), na.rm=TRUE, conf.level = 0.95)
#> mean lwr.ci upr.ci
#> 5.477226 2.109600 14.220706