geometricmean: The geometric mean In compositions: Compositional Data Analysis

Description

Computes the geometric mean.

Usage

 1 2 3 4 5 6 7 geometricmean(x,...) geometricmeanRow(x,...) geometricmeanCol(x,...) gsi.geometricmean(x,...) gsi.geometricmeanRow(x,...) gsi.geometricmeanCol(x,...)

Arguments

 x a numeric vector or matrix of data ... further arguments to compute the mean

Details

The geometric mean is defined as:

geometricmean(x) := \code{prod(x)^(1/length(x))}

The geometric mean is actually computed by exp(mean(log(c(unclass(x))),...)).

Value

The geometric means of x as a whole (geometricmean), its rows (geometricmeanRow) or its columns (geometricmeanCol).

Missing Policy

The the first three functions take the geometric mean of all non-missing values. This is because they should yield a result in term of data analysis.

Contrarily, the gsi.* functions inherit the arithmetic IEEE policy of R through exp(mean(log(c(unclass(x))),...)). Thus, NA codes a not available i.e. not measured, NaN codes a below detection limit, and 0.0 codes a structural zero. If any of the elements involved is 0, NA or NaN the result is of the same type. Here 0 takes precedence over NA, and NA takes precedence over NaN. For example, if a structural 0 appears, the geometric mean is 0 regardless of the presence of NaN's or NA's in the rest. Values below detection limit become NaN's if they are coded as negative values.

Author(s)

K.Gerald v.d. Boogaart http://www.stat.boogaart.de

Examples

 1 2 3 4 5 6 geometricmean(1:10) geometricmean(c(1,0,NA,NaN)) # 0 X <- matrix(c(1,NA,NaN,0,1,2,3,4),nrow=4) X geometricmeanRow(X) geometricmeanCol(X)

Example output

Attaching package: 'tensorA'

The following object is masked from 'package:base':

norm

Welcome to compositions, a package for compositional data analysis.
Find an intro with "? compositions"

Attaching package: 'compositions'

The following objects are masked from 'package:stats':

cor, cov, dist, var

The following objects are masked from 'package:base':

%*%, scale, scale.default

 4.528729
 0
[,1] [,2]
[1,]    1    1
[2,]   NA    2
[3,]  NaN    3
[4,]    0    4
 1 2 3 0
 0.000000 2.213364

compositions documentation built on Jan. 5, 2022, 5:09 p.m.