Skip to content
Prev 177106 / 398503 Next

geometric mean to handle large number and negative values

Obviously, there's a discrepancy between the answer of geometric.mean1 and 
geometric.mean2 with complex inputs.  Having thought about it a little 
more, I think the problem is with my solution.

The log of a complex number decomposes as log(z) = log(abs(z)) +1i*Arg(z). 
 When you sum the second components, you need to take the answer modulo 
2*pi, since the phase angles wrap around.

Here's an alternative geometric mean function that takes that into 
account.

geometric.mean3 <- function(x) 
{
   a <- mean(log(abs(x)))
   b <- 1i/length(x) 
   c <- sum(Arg(x))%%(2*pi)
   exp(a+b*c)
}

geometric.mean3(comp.x)
# [1] 4.472136+0i

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}