BookmarkSubscribeRSS Feed

Geometric mean for zero values

Started ‎08-07-2019 by
Modified ‎08-07-2019 by
Views 3,872

One is sometimes precluded from using the geometric mean to descrtibe the location of data by the presence of zeros. SAS estimates the geometric mean as zero when there are zeros in the data. Here is a reasonable alternative:

 

 

/* A simple SQL implementation of a generalised geometric mean 
   for cases when the data contains some zeros. The GEOMEAN function from SAS
   returns zero if any of the data is zero. The generalised geometric
   mean is computed as a weighted average of zero and the geometric mean 
   of positive values. 

   This estimator was proposed by:
   Habib, Elsayed A. E. (2012) Geometric mean for negative and zero values. 
   IJRRAS 11 (3), p. 419-432.

   This implementation accounts for negative values by treating them as if
   they were zeros.
*/

title "Estimators of the geometric mean for the set {0, 1, 2, 3, 4}";

data test;
do x = 0 to 4;
    output;
    end;
run;

proc sql;
select 
    case when min(x) <= 0 then 0 else exp(mean(log(x))) end 
        as geoMean "Standard SAS geometric mean",
    exp(mean(log(x))) 
        as geoMeanPos "Geometric mean of positive values",
    exp(mean(log(x))) * count(log(x)) / count(x) 
        as geoMean0 "Weighted average geometric mean"
from test;
quit;
Standard
SAS
geometric
mean
Geometric
mean of
positive
values
Weighted
average
geometric
mean
0 2.213364 1.770691

 

 

 

Contributors
Version history
Last update:
‎08-07-2019 12:54 PM
Updated by:

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags