umontreal.iro.lecuyer.stat.list

## Class ListOfTallies<E extends Tally>

- java.lang.Object
- umontreal.iro.lecuyer.stat.list.ListOfStatProbes<E>
- umontreal.iro.lecuyer.stat.list.ListOfTallies<E>

- All Implemented Interfaces:
- Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

- Direct Known Subclasses:
- ListOfTalliesWithCovariance

public class ListOfTallies<E extends Tally>extends ListOfStatProbes<E>

### Constructor Summary

Constructors Constructor and Description **ListOfTallies**()Constructs a new empty list of tallies.**ListOfTallies**(String name)Constructs a new empty list of tallies with name`name`.

### Method Summary

Methods Modifier and Type Method and Description `void`

**add**(double[] x)Adds the observation`x[i]`in tally`i`of this list, for`i = 0, ..., size() - 1`.`boolean`

**areAllNumberObsEqual**()Tests that every tally in this list contains the same number of observations.`void`

**average**(double[] r)Computes the average for each tally in this list, and stores the averages in the array`r`.`ListOfTallies<E>`

**clone**()Clones this object.`void`

**correlation**(DoubleMatrix2D c)Similar to`covariance`

for computing the sample correlation matrix.`double`

**correlation**(int i, int j)Returns the empirical correlation between the observations in tallies with indices`i`and`j`.`void`

**covariance**(DoubleMatrix2D c)Constructs and returns the sample covariance matrix for the tallies in this list.`double`

**covariance**(int i, int j)Returns the empirical covariance of the observations in tallies with indices`i`and`j`.`static ListOfTallies<Tally>`

**createWithTally**(int size)This factory method constructs and returns a list of tallies with`size`instances of`Tally`

.`static ListOfTallies<TallyStore>`

**createWithTallyStore**(int size)This factory method constructs and returns a list of tallies with`size`instances of`TallyStore`

.`int`

**numberObs**()Assuming that each tally in this list contains the same number of observations, returns the number of observations in tally 0, or 0 if this list is empty.`void`

**standardDeviation**(double[] std)For each tally in this list, computes the sample standard deviation, and stores the standard deviations into the array`std`.`void`

**variance**(double[] v)For each tally in this list, computes the sample variance, and stores the variances into the array`v`.### Methods inherited from class umontreal.iro.lecuyer.stat.list.ListOfStatProbes

`add, add, addAll, addAll, addArrayOfObservationListener, clear, clearArrayOfObservationListeners, contains, containsAll, equals, get, getName, hashCode, indexOf, init, isBroadcasting, isCollecting, isEmpty, isModifiable, iterator, lastIndexOf, listIterator, listIterator, notifyListeners, remove, remove, removeAll, removeArrayOfObservationListener, report, retainAll, set, setBroadcasting, setCollecting, setName, setUnmodifiable, size, subList, sum, toArray, toArray`

### Constructor Detail

#### ListOfTallies

public ListOfTallies()

Constructs a new empty list of tallies.

#### ListOfTallies

public ListOfTallies(String name)

Constructs a new empty list of tallies with name`name`.- Parameters:
`name`

- the name of the new list.

### Method Detail

#### createWithTally

public static ListOfTallies<Tally> createWithTally(int size)

This factory method constructs and returns a list of tallies with`size`instances of`Tally`

.- Parameters:
`size`

- the size of the list.- Returns:
- the created list.

#### createWithTallyStore

public static ListOfTallies<TallyStore> createWithTallyStore(int size)

This factory method constructs and returns a list of tallies with`size`instances of`TallyStore`

.- Parameters:
`size`

- the size of the list.- Returns:
- the created list.

#### add

public void add(double[] x)

Adds the observation`x[i]`in tally`i`of this list, for`i = 0, ..., size() - 1`. No observation is added if the value is`Double.NaN`, or if collecting is turned OFF. If broadcasting is ON, the given array is notified to all registered observers. The given array`x`not being stored by this object, it can be freely used and modified after the call to this method.- Parameters:
`x`

- the array of observations.- Throws:
`NullPointerException`

- if`x`is`null`.`IllegalArgumentException`

- if the length of`x`does not correspond to`size()`.

#### numberObs

public int numberObs()

Assuming that each tally in this list contains the same number of observations, returns the number of observations in tally 0, or 0 if this list is empty.- Returns:
- the number of observations.

#### areAllNumberObsEqual

public boolean areAllNumberObsEqual()

Tests that every tally in this list contains the same number of observations. This returns`true`if and only if all tallies have the same number of observations, or if this list is empty. If observations are always added using the`add`

method from this class, and not`add`

from`Tally`

, this method always returns`true`.- Returns:
- the success indicator of the test.

#### average

public void average(double[] r)

Computes the average for each tally in this list, and stores the averages in the array`r`. If the tally`i`has no observation, the`Double.NaN`value is stored in the array, at index`i`.**Overrides:**`average`

in class`ListOfStatProbes<E extends Tally>`

- Parameters:
`r`

- the array to be filled with averages.

#### variance

public void variance(double[] v)

For each tally in this list, computes the sample variance, and stores the variances into the array`v`. If, for some tally`i`, there are not enough observations for estimating the variance,`Double.NaN`is stored in the array.- Parameters:
`v`

- the array to be filled with sample variances.- Throws:
`NullPointerException`

- if`v`is`null`.`IllegalArgumentException`

- if`v.length`does not correspond to`size`

.

#### standardDeviation

public void standardDeviation(double[] std)

For each tally in this list, computes the sample standard deviation, and stores the standard deviations into the array`std`. This is equivalent to calling`variance`

and performing a square root on every element of the filled array.- Parameters:
`std`

- the array to be filled with standard deviations.- Throws:
`NullPointerException`

- if`std`is`null`.`IllegalArgumentException`

- if`std.length`does not correspond to`size()`.

#### covariance

public double covariance(int i, int j)

Returns the empirical covariance of the observations in tallies with indices`i`and`j`. If*x*_{1},…,*x*_{n}represent the observations in tally`i`whereas*y*_{1},…,*y*_{n}represent the observations in tally`j`, then the covariance is given by*S*_{X, Y}= ∑_{k=1}^{n}(*x*_{k}- bar(X)_{n})(*y*_{k}- bar(Y)_{n}) = [tex2html_wrap_indisplay275](∑_{k=1}^{n}*x*_{k}*y*_{k}- ∑_{k=1}^{n}*x*_{k}∑_{r=1}^{n}*y*_{r}).`Double.NaN`if the tallies do not contain the same number of observations, or if they contain less than two observations. This method throws an exception if the underlying tallies are not capable of storing observations, i.e. if the tallies are not TallyStores. The`ListOfTalliesWithCovariance`

subclass provides an alternative implementation of this method which does not require the observations to be stored.- Parameters:
`i`

- the index of the first tally.`j`

- the index of the second tally.- Returns:
- the value of the covariance.
- Throws:
`ArrayIndexOutOfBoundsException`

- if one or both indices are out of bounds.

#### correlation

public double correlation(int i, int j)

Returns the empirical correlation between the observations in tallies with indices`i`and`j`. If the tally`i`contains a sample of the random variate*X*and the tally`j`contains a sample of*Y*, this corresponds toCor(*X*,*Y*) = Cov(*X*,*Y*)/((X)(Y))^{1/2}.This method uses

`covariance`

to obtain an estimate of the covariance, and`variance`

in class`Tally`

to obtain the sample variances.- Parameters:
`i`

- the index of the first tally.`j`

- the index of the second tally.- Returns:
- the value of the correlation.
- Throws:
`ArrayIndexOutOfBoundsException`

- if one or both indices are out of bounds.

#### covariance

public void covariance(DoubleMatrix2D c)

Constructs and returns the sample covariance matrix for the tallies in this list. The given*d*×*d*matrix`c`, where*d*=`size()`, is filled with the computed sample covariances. Element`c.get (i, j)`corresponds to the result of`covariance (i, j)`.- Parameters:
`c`

- the matrix to be filled with the sample covariances.- Throws:
`NullPointerException`

- if`c`is`null`.`IllegalArgumentException`

- if the number of rows or columns in`c`does not correspond to`size()`.

#### correlation

public void correlation(DoubleMatrix2D c)

Similar to`covariance`

for computing the sample correlation matrix.- Parameters:
`c`

- the matrix to be filled with the correlations.- Throws:
`NullPointerException`

- if`c`is`null`.`IllegalArgumentException`

- if the number of rows or columns in`c`does not correspond to`size`

.

#### clone

public ListOfTallies<E> clone()

Clones this object. This makes a shallow copy of this list, i.e., this does not clone all the tallies in the list. The created clone is modifiable, even if the original list is unmodifiable.**Overrides:**`clone`

in class`ListOfStatProbes<E extends Tally>`

**SCaVis 2.0 © jWork.ORG**