PSPP  Patches: patch #8052, Harmonic means for descriptive...
You are not allowed to post comments on this tracker with your current authentication level.
patch #8052: Harmonic means for descriptive statistics
Submitter:  Teppo Jussmäki <jssmk>  
Submitted:  Mon 20 May 2013 09:51:49 AM UTC  
Category:  None  Item Group:  None 
Status:  Need Info  Assigned to:  None 
Open/Closed:  Open 
Sun 26 May 2013 09:27:05 AM UTC, comment #5: 
Teppo Jussmäki <jssmk> 
Sun 26 May 2013 08:16:52 AM UTC, comment #4: The SPSS documentation doesn't mention any limits on the domain of the input. http://publib.boulder.ibm.com/infocenter/spssstat/v20r0m0/index.jsp?topic=%2Fcom.ibm.spss.statistics.help%2Fidh_mean.htm
In the special case, where a value is zero. It can be shown algebraically that the harmonic mean is also zero:
h = a.b / (a+b)
So I retract my previous statement. I think now that if the sumofreciprocals method is used, there should be a special case when one or more values are zero. But I still don't see why negative values should be treated specially.
I cannot find in the academic literature any indication that harmonic means are defined only for positive values.

John Darrington <jmd> 
Sat 25 May 2013 08:50:13 AM UTC, comment #3: I must admit I was a bit confused about the definition of harmonic mean of sets with nonpositive values. Wikipedia gives the definition of harmonic mean for positive real numbers. OpenOffice also produces errors with sets including zeros and negatives.
WolframAlpha does calculations for sets such as {2, 2, 3} > 9, and also {2, 2, 0} > 0, which should be handled as an exeption. In the Wikipedia definition, harmonic mean should always be less or equal with arithmetic mean. The zero handling in the Wolfram version is quite intuitive if you consider the resistance of parallel resistors: if even one resistor is zero, the circuit is equivalent of allzero resistors in parallel.
There seems to be different types of implementations in applications. Which one to follow? 
Teppo Jussmäki <jssmk> 
Sat 25 May 2013 05:33:36 AM UTC, comment #2: + /* Sum of reciprocals only needed for variables with only positive values */
I don't understand why there is this exception for values less than or equal to zero.
The harmonic mean is well defined for negative values, so we don't need to make a special case there. Where a value is exactly equal to zero, the reciprocal of course is infinite. However since we are dealing with floating point numbers, this will be recognised by the floating point library and the end result will be (correctly) NaN. So as far as I can see, we don't need to special case zero either. 
John Darrington <jmd> 
Tue 21 May 2013 03:13:33 AM UTC, comment #1: This looks nice to me. To apply this, we'd have to get the GNU copyright assignment process started. Are you willing to do that? I can give you instructions here, if you like, or you can email me at blp@cs.stanford.edu. 
Ben Pfaff <blp> 
Mon 20 May 2013 09:51:49 AM UTC, original submission:
Harmonic means for descriptive statistics (descriptives and frequencies). Calculated in moments.c. I separated counting of harmonic means in a new function void moments_calc_additional.
Example:
GET FILE="Speed_and_distance.sav".
WEIGHT BY Distance_km.
DESCRIPTIVES
Files modified:

Teppo Jussmäki <jssmk> 
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follow 5 latest changes.
Date  Changed by  Updated Field  Previous Value  =>  Replaced by 

20130521  jssmk  Attached File    Added harmonic_fixed.patch, #28127  
20130521  blp  Status  None  Need Info  
20130520  jssmk  Attached File    Added harmonic.diff, #28115  
Attached File    Added Speed_and_distance.sav, #28116  
CarbonCopy    Added jmd 
Thanks for making sure of the definition! I did not have any reliable good sources at hand.
I am going to review the code and do changes for accepting negative values and cheking for any zeros in the dataset.