Sample Statistics of Empirical Data

The SampleStatistics class provides methods for data manipulation and calculating such simple sample statistics of empirical data as moments, central moments, min, max. Samples are objects of classes which have a java Collection interface (e.g. ArrayList, Vector etc.).

Table 20.43. Methods for samples and sample statistics

MethodDescription
addSample(_sample)adds the data sample _sample to the sample
clear()clears the data sample
computeCentralMoment(int p)computes the central moment of order p of the sample
computeMoment(int p)computes the moment of order p of the sample
computeSum()computes the sum of the elements of the sample
getMax()finds the maximum of the elements of the sample
getMin()computes minimum of the elements of the sample
setSample()sets a data sample

Example 20.6. Sample statistics of empirical data

from biz.sc.math.distributions import * 
from biz.sc.math.distributions.continuous import * 
from java.util import Arrays
from random import *

_min = 0.1
_max = 0.3

rand=Random()
rand.seed(10)

_uni = UniformDistribution(_min, _max)

vector = []

for i in range (100):
    vector.append(rand.random())

sample = SampleStatistics(Arrays.asList(vector))

print 'Min: %1.4f' % sample.getMin()
print 'Max: %1.4f' % sample.getMax()
print 'Moment: %1.4f' % sample.computeMoment(3)

Output:

Min: 0.0011
Max: 0.9988
Moment: 0.5562