papaya
Class Descriptive.Weighted

java.lang.Object
  extended by papaya.Descriptive.Weighted
Enclosing class:
Descriptive

public static class Descriptive.Weighted
extends Object

Contains methods related to weighted datasets.


Method Summary
static float mean(float[] data, float[] weights)
          Returns the weighted mean of a data sequence.
static float rms(float sumOfProducts, float sumOfSquaredProducts)
          Returns the weighted RMS (Root-Mean-Square) of a data sequence.
static float var(float[] data, float[] weights, boolean unbiased)
          Returns the weighted variance of a data sequence of length N There are (unfortunately) many different definitions of the unbiased weighted variance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

mean

public static float mean(float[] data,
                         float[] weights)
Returns the weighted mean of a data sequence. Used when the values in a set of data do not share equal importance. That is Sum (data[i] * weights[i]) / Sum ( weights[i] ).


rms

public static float rms(float sumOfProducts,
                        float sumOfSquaredProducts)
Returns the weighted RMS (Root-Mean-Square) of a data sequence. That is Sum( data[i] * data[i] * weights[i]) / Sum( data[i] * weights[i] ), or in other words sumOfProducts / sumOfSquaredProducts.

Parameters:
sumOfProducts - == Sum( data[i] * weights[i] ).
sumOfSquaredProducts - == Sum( data[i] * data[i] * weights[i] ).

var

public static float var(float[] data,
                        float[] weights,
                        boolean unbiased)
Returns the weighted variance of a data sequence of length N There are (unfortunately) many different definitions of the unbiased weighted variance. Here, we use the following formula
 weighted.var(x,w,unbiased=true) = biasCorrection * Sum ( w[i] * (x[i] - mu_w)^2  ) / Sum(w[i]).
 
where mu_w corresponds to the weighted mean and the biasCorrection term
 biasCorrection = ( Sum(w[i]) )^2  / ( ( Sum(w[i]) )^2 - Sum( w[i]^2 )  ).
 
corrects for the bias in the variance. weighted.var(x,w,unbiased=false) computes the biased weighted variance and is given by the formula above, but without the correction factor.

The formula above agrees with that presented in the NIST Information Technology Laboratory page. The algorithm used, is a one-pass formula credited to "D. H. D. West (1979). Communications of the ACM, 22, 9, 532-535: Updating Mean and Variance Estimates: An Improved Method", and spelled out under the
weighted incremental algorithm section of the link.

Parameters:
unbiased - set to true to return the unbiased variance (division by (N-1)), false to return the biased value (division by N).
Returns:
the weighted variance.


Processing library papaya by Adila Faruk. (C) 2014