public static double moment(FlatDataCollection flatDataCollection, int r, double mean) {
        int n = 0;
        double moment=0.0;
        
        Iterator<Double> it = flatDataCollection.iteratorDouble();
        while(it.hasNext()) {
            Double v = it.next();
            if(v != null) {
                ++n;
                moment+=Math.pow(v-mean, r);
            }
        }

        if(n<=1) {
            throw new IllegalArgumentException("The provided collection must have more than 1 elements.");
        }
        
        moment/=n;
        
        return moment;
    }
public static double moment ( FlatDataCollection flatDataCollection , int r , double mean ) { int n = 0 ; double moment = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null ) { ++ n ; moment += Math . pow ( v - mean , r ) ; } } if ( n <= 1 ) { throw new IllegalArgumentException ( "The provided collection must have more than 1 elements." ) ; } moment /= n ; return moment ; }
Calculates Moment R if the mean is known.

@param flatDataCollection
@param r
@param mean
@return