Class BasicStatsMV

java.lang.Object
org.bzdev.math.stats.BasicStatsMV
Direct Known Subclasses:
BasicStatsMV.Population, BasicStatsMV.Sample

public abstract class BasicStatsMV extends Object
Class to compute the mean and variance for multiple values.. This class provides the variances for a vector of measurements or random variables measured or evaluated multiple times. The inner classes are subclasses of this class:
  • Sample is used to compute the variances for the case in which the dataset whose variances are computed is a representative sample.
  • Population is used to compute the variances for the case where the dataset represents every case being computed.
See West D.H.D, Updating mean and variance estimates: An improved method. Commm. ACM22, 9 (Sept 1979, 532--535) for the algorithm. The implementation uses Kahan's summation algorithm to further improve the accuracy.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Class to compute the variance for a total set of values, as opposed to a sample of values.
    static class 
    Class to compute a sample variance.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BasicStatsMV(double[][] arrays, int n)
    Constructor given an array containing the initial dataset used to compute a variance.
    protected
    BasicStatsMV(double[] means, double[] variances, long m)
    Constructor given means, uncorrected variances, and a data-set size
    protected
    BasicStatsMV(int n)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double[] values)
    Add a new vector of values.
    Add the values from another BasicStatsMV object.
    protected abstract double
    The elements of the variances array that is computed will be scaled by a correction factor.
    double[]
    Get a the mean values.
    double[]
    getMeans(double[] results)
    Get a the mean values.
    double[]
    Get the standard deviations.
    double[]
    getSDevs(double[] results)
    Get the standard deviations.
    double[]
    Get the variances.
    double[]
    getVariances(double[] results)
    Get the variances.
    int
    Get the number of variables.
    long
    Get the number of data-point arrays that were entered.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BasicStatsMV

      protected BasicStatsMV(int n)
      Constructor. The method add(double[]) must be called repeatedly to provide the dataset used to compute the variance and mean array.
      Parameters:
      n - the number of variables
    • BasicStatsMV

      protected BasicStatsMV(double[] means, double[] variances, long m)
      Constructor given means, uncorrected variances, and a data-set size
      Parameters:
      means - an array of length n containing the mean values for n variables
      variances - an array of length n containing the variances for n variables
      m - the data-set size
      Throws:
      IllegalArgumentException - the array lengths differ
    • BasicStatsMV

      protected BasicStatsMV(double[][] arrays, int n) throws IllegalArgumentException
      Constructor given an array containing the initial dataset used to compute a variance. Note: More data can be added using the add(double[]) method.
      Parameters:
      arrays - an array, each component of which is an array containing the values for n variables
      n - the number of variables
      Throws:
      IllegalArgumentException - the arrays argument was too short
  • Method Details

    • size

      public long size()
      Get the number of data-point arrays that were entered.
      Returns:
      the number of data-point tarrays that were entered
    • length

      public int length()
      Get the number of variables. This is the length of each array that will be entered (if an array is longer than this value, only the first n elements will be used.
      Returns:
      the number of variables.
    • getCorrection

      protected abstract double getCorrection()
      The elements of the variances array that is computed will be scaled by a correction factor. This factor should be 1.0 when the dataset represents a total population. For a sample of a population, the factor is m/(m-1) where m is the sample size (the number of factors.
      Returns:
      the correction factor; Double.NaN if the factor cannot be computed due to too few entries
    • add

      public BasicStatsMV add(double[] values) throws IllegalArgumentException
      Add a new vector of values. The vector's length must be at least n, where n is the number of variables.
      Parameters:
      values - a vector of values (the first n entries will be used)
      Returns:
      this object
      Throws:
      IllegalArgumentException - the argument array was too short
    • addAll

      public BasicStatsMV addAll(BasicStatsMV stats)
      Add the values from another BasicStatsMV object.
      Parameters:
      stats - the BasicStats object whose values should be added
      Returns:
      this object
    • getVariances

      public double[] getVariances() throws IllegalStateException
      Get the variances.
      Returns:
      the variances
      Throws:
      IllegalStateException - the data set was too small or missing
    • getVariances

      public double[] getVariances(double[] results) throws IllegalStateException
      Get the variances. If the argument array is too short or is null, a new array will be allocated. The returned value will be the argument array if that is long enough or a newly allocated array otherwise.
      Parameters:
      results - an array to hold the variances
      Returns:
      the variances
      Throws:
      IllegalStateException - the data set was too small or missing
    • getSDevs

      public double[] getSDevs() throws IllegalStateException
      Get the standard deviations.
      Returns:
      the standard deviations
      Throws:
      IllegalStateException - the data set was too small or missing
    • getSDevs

      public double[] getSDevs(double[] results) throws IllegalStateException
      Get the standard deviations. If the argument array is too short or is null, a new array will be allocated. The returned value will be the argument array if that is long enough or a newly allocated array otherwise.
      Parameters:
      results - an array to hold the standard deviations
      Returns:
      the standard deviations
      Throws:
      IllegalStateException - the data set was too small or missing
    • getMeans

      public double[] getMeans() throws IllegalStateException
      Get a the mean values.
      Returns:
      the mean values
      Throws:
      IllegalStateException - the data set was too small or missing
    • getMeans

      public double[] getMeans(double[] results) throws IllegalStateException
      Get a the mean values. If the argument array is too short or is null, a new array will be allocated. The returned value will be the argument array if that is long enough or a newly allocated array otherwise.
      Parameters:
      results - an array to hold the means
      Returns:
      the mean values
      Throws:
      IllegalStateException - the data set was too small or missing