edu.sc.seis.fissuresUtil.bag
Class Statistics

java.lang.Object
  extended by edu.sc.seis.fissuresUtil.bag.Statistics

public class Statistics
extends java.lang.Object

Statistics.java Created: Wed Apr 4 22:27:52 2001


Field Summary
protected  double[] autocorrelation
           
protected  int beginIndex
           
protected  double[] dSeries
           
protected  int endIndex
           
protected  float[] fSeries
           
protected  int[] iSeries
           
protected  double[] minMaxMean
          index 0 has min, index 1 has max, index 2 has mean.
protected  boolean minMaxMeanCalculated
          Has min/max/mean already been calculated and cached.
protected  double[] partialautocorr
           
protected  short[] sSeries
           
protected  double variance
           
protected  boolean varianceCalculated
          Has the variable been calculated and cached.
 
Constructor Summary
Statistics(double[] dSeries)
          Creates a new Statistics instance.
Statistics(float[] fSeries)
          Creates a new Statistics instance.
Statistics(int[] iSeries)
          Creates a new Statistics instance.
Statistics(java.util.List<edu.iris.Fissures.model.QuantityImpl> vals)
           
Statistics(java.util.List<edu.iris.Fissures.model.QuantityImpl> vals, edu.iris.Fissures.model.UnitImpl unit)
           
Statistics(edu.iris.Fissures.seismogramDC.LocalSeismogramImpl seismo)
          Creates a new Statistics instance.
Statistics(short[] sSeries)
          Creates a new Statistics instance.
 
Method Summary
 double[] acf(int maxlag)
          Calculates the autocovariance function out to the given lag.
 double[] acf95conf(int maxlag)
          Describe acf95conf method here.
 double[] acfTRatio(int maxlag)
          Calculates the TRatio for the acf out to the given max lag.
 double binaryIndexSum(int start, int finish)
          Calulates the sum(i*yi) from beginIndex to endIndex-1.
 double binarySum(int start, int finish)
          Calulates the sum of the series from beginIndex to endIndex-1.
 double binarySumDevLag(int start, int finish, double mean, int lag)
          Describe binarySumDevLag method here.
 double binarySumDevSqr(int start, int finish, double mean)
          Calulates the sum of the square of the difference from the mean.
 double correlation(double[] other)
           
 double covariance(double[] other)
           
 double covariance(Statistics otherStat)
           
 int getLength()
          The length of the series.
 int[] histogram(double start, double width, int number)
          Creates a histogram of the values.
 double[] linearLeastSquares()
          Calculates the linear Least Squares slope and intercept for this series.
 double max()
          Finds the max value.
 double max(int beginIndex, int endIndex)
          Finds the max value between index beginIndex and endIndex-1.
 double maxDeviation()
          Finds the max deviation from the mean.
 double maxDeviation(int beginIndex, int endIndex)
          Finds the max deviation from the mean between index beginIndex and endIndex-1.
 double mean()
          Calulates mean of the data.
 double mean(int beginIndex, int endIndex)
          Finds the mean value between index beginIndex and endIndex-1.
 double min()
          Finds the min value.
 double min(int beginIndex, int endIndex)
          Finds the min value between index beginIndex and endIndex-1.
 double[] minMaxMean()
          Calculates the min, max and mean.
 double[] minMaxMean(int beginIndex, int endIndex)
          Calculates the min, max and mean from beginIndex to endIndex-1.
 double[] pacf(int maxlag)
          Computes the partial autocorrelation function, after Wei, William S.
 double pacf95conf(int maxlag)
          Calculates the 95 percent confidence for the pacf.
 double[] pacfTRatio(int maxlag)
          Calculates the TRatio for the pacf.
 double stddev()
          Calulates the standard deviation.
 java.lang.String toString()
           
 double var()
          Calualates the unbiased variance, ie 1/(n-1) SUM{(x-mean)^2}.
 double var(double mean)
          calculates the unbiased variance w.r.t the given mean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

iSeries

protected int[] iSeries

sSeries

protected short[] sSeries

fSeries

protected float[] fSeries

dSeries

protected double[] dSeries

minMaxMeanCalculated

protected boolean minMaxMeanCalculated
Has min/max/mean already been calculated and cached.


minMaxMean

protected double[] minMaxMean
index 0 has min, index 1 has max, index 2 has mean.


variance

protected double variance

varianceCalculated

protected boolean varianceCalculated
Has the variable been calculated and cached.


autocorrelation

protected double[] autocorrelation

partialautocorr

protected double[] partialautocorr

beginIndex

protected int beginIndex

endIndex

protected int endIndex
Constructor Detail

Statistics

public Statistics(int[] iSeries)
Creates a new Statistics instance.

Parameters:
iSeries - an int[] value

Statistics

public Statistics(short[] sSeries)
Creates a new Statistics instance.

Parameters:
sSeries - a short[] value

Statistics

public Statistics(float[] fSeries)
Creates a new Statistics instance.

Parameters:
fSeries - a float[] value

Statistics

public Statistics(double[] dSeries)
Creates a new Statistics instance.

Parameters:
dSeries - a double[] value

Statistics

public Statistics(edu.iris.Fissures.seismogramDC.LocalSeismogramImpl seismo)
           throws edu.iris.Fissures.FissuresException
Creates a new Statistics instance.

Parameters:
seismo - a LocalSeismogramImpl value
Throws:
edu.iris.Fissures.FissuresException

Statistics

public Statistics(java.util.List<edu.iris.Fissures.model.QuantityImpl> vals)

Statistics

public Statistics(java.util.List<edu.iris.Fissures.model.QuantityImpl> vals,
                  edu.iris.Fissures.model.UnitImpl unit)
Method Detail

min

public double min()
Finds the min value.

Returns:
the minimum

min

public double min(int beginIndex,
                  int endIndex)
Finds the min value between index beginIndex and endIndex-1.

Parameters:
beginIndex - first index to search
endIndex - end index, last + 1
Returns:
a double value

max

public double max()
Finds the max value.

Returns:
a double value

max

public double max(int beginIndex,
                  int endIndex)
Finds the max value between index beginIndex and endIndex-1.

Parameters:
beginIndex - an int value
endIndex - an int value
Returns:
a double value

maxDeviation

public double maxDeviation()
Finds the max deviation from the mean.

Returns:
a double value

maxDeviation

public double maxDeviation(int beginIndex,
                           int endIndex)
Finds the max deviation from the mean between index beginIndex and endIndex-1.

Parameters:
beginIndex - an int value
endIndex - an int value
Returns:
a double value

mean

public double mean()
Calulates mean of the data.

Returns:
a double value

mean

public double mean(int beginIndex,
                   int endIndex)
Finds the mean value between index beginIndex and endIndex-1.

Parameters:
beginIndex - an int value
endIndex - an int value
Returns:
a double value

minMaxMean

public double[] minMaxMean()
Calculates the min, max and mean. The value at index 0 is the min, at index 1 is the max and at index 2 is the mean

Returns:
min, max, mean in a double[3]

minMaxMean

public double[] minMaxMean(int beginIndex,
                           int endIndex)
Calculates the min, max and mean from beginIndex to endIndex-1. The value at index 0 is the min, at index 1 is the max and at index 2 is the mean

Parameters:
beginIndex - first index
endIndex - last index +1
Returns:
min, max, mean in a double[3]

var

public double var()
Calualates the unbiased variance, ie 1/(n-1) SUM{(x-mean)^2}.

Returns:
variance

var

public double var(double mean)
calculates the unbiased variance w.r.t the given mean. This allows a psuedo-variance to be calculated based on a longer term mean.


stddev

public double stddev()
Calulates the standard deviation. This is a shortcut for Math.sqrt(var()); Note this uses the unbiased variance.

Returns:
the Standard deviation

covariance

public double covariance(double[] other)

covariance

public double covariance(Statistics otherStat)

correlation

public double correlation(double[] other)

linearLeastSquares

public double[] linearLeastSquares()
Calculates the linear Least Squares slope and intercept for this series. Note that this is calculated relative to the index of the array, with zero index as the first data point.

Returns:
the intercept in index 0 and the slope in index 1

acf

public double[] acf(int maxlag)
Calculates the autocovariance function out to the given lag.

Parameters:
maxlag - the maximum lag to calculate the acf
Returns:
the acf for the series out to maxlag

acf95conf

public double[] acf95conf(int maxlag)
Describe acf95conf method here.

Parameters:
maxlag - an int value
Returns:
a double[] value

acfTRatio

public double[] acfTRatio(int maxlag)
Calculates the TRatio for the acf out to the given max lag.

Parameters:
maxlag - the maximu lag
Returns:
the T ratio

pacf

public double[] pacf(int maxlag)
Computes the partial autocorrelation function, after Wei, William S. Time Series Analysis, pp 22-23.

Parameters:
maxlag - the maximum lag
Returns:
the pacf

pacf95conf

public double pacf95conf(int maxlag)
Calculates the 95 percent confidence for the pacf. This is just 1.96*sqrt(length)

Parameters:
maxlag - the maximum lag
Returns:
the 95 percent conf for the pacf

pacfTRatio

public double[] pacfTRatio(int maxlag)
Calculates the TRatio for the pacf.

Parameters:
maxlag - the maximum lag
Returns:
T ratio for the pacf

getLength

public int getLength()
The length of the series.


histogram

public int[] histogram(double start,
                       double width,
                       int number)
Creates a histogram of the values. Each value is added to the bin Math.floor((value-start)/width) and the returned int array has length number

Parameters:
start - binning start value
width - bin width
number - number of bins
Returns:
an histogram

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

binarySum

public double binarySum(int start,
                        int finish)
Calulates the sum of the series from beginIndex to endIndex-1. This is done recursively in halves to avoid rounding errors.

Parameters:
start - starting index
finish - last index +1
Returns:
the sum

binarySumDevSqr

public double binarySumDevSqr(int start,
                              int finish,
                              double mean)
Calulates the sum of the square of the difference from the mean. Sum ((xi-mean)^2)

Parameters:
start - first index
finish - last index+1
mean - the mean
Returns:
the result

binarySumDevLag

public double binarySumDevLag(int start,
                              int finish,
                              double mean,
                              int lag)
Describe binarySumDevLag method here.

Parameters:
start - an int value
finish - an int value
mean - a double value
lag - an int value
Returns:
a double value

binaryIndexSum

public double binaryIndexSum(int start,
                             int finish)
Calulates the sum(i*yi) from beginIndex to endIndex-1. This is done recursively in halves to avoid rounding errors. This is mainly used as one of the terms in a linear least squares.

Parameters:
start - starting index
finish - last index +1
Returns:
the sum