Class Statistic

    • Field Detail

      • min

        protected double min
        Holds the minimum of the observed data.
      • max

        protected double max
        Holds the maximum of the observed data
      • num

        protected double num
        Holds the number of observations observed
      • myValue

        protected double myValue
        Holds the last value observed
      • sumxx

        protected double sumxx
        Holds the sum the lag-1 data, i.e. from the second data point on variable for collecting lag1 covariance
      • firstx

        protected double firstx
        Holds the first observed data point, needed for von-neuman statistic
      • moments

        protected double[] moments
        Holds the first 4 statistical central moments
      • myJsum

        protected double myJsum
        Holds sum = sum + j*x
    • Constructor Detail

      • Statistic

        public Statistic()
        Creates a Statistic with name "null"
      • Statistic

        public Statistic​(java.lang.String name)
        Creates a Statistic with the given name
        Parameters:
        name - A String representing the name of the statistic
      • Statistic

        public Statistic​(double[] values)
        Creates a Statistic \based on the provided array
        Parameters:
        values - an array of values to collect statistics on
      • Statistic

        public Statistic​(java.lang.String name,
                         double[] values)
        Creates a Statistic with the given name based on the provided array
        Parameters:
        name - A String representing the name of the statistic
        values - an array of values to collect statistics on
    • Method Detail

      • collectStatistics

        public static Statistic collectStatistics​(double[] x)
        Returns a statistic that summarizes the passed in array of values
        Parameters:
        x - the values to compute statistics for
        Returns:
        a Statistic summarizing the data
      • newInstance

        public static Statistic newInstance​(Statistic stat)
        Creates a instance of Statistic that is a copy of the supplied Statistic All internal state is the same (including whether the collection is on or off) and the collection rule. The only exception is for the id of the returned Statistic If this statistic has saved data, the new instance will also have that data.
        Parameters:
        stat - the stat to copy
        Returns:
        a copy of the supplied Statistic
      • newInstance

        public final Statistic newInstance()
        Creates a instance of Statistic that is a copy of the supplied Statistic All internal state is the same (including whether the collection is on or off) and the collection rule. The only exception is for the id of the returned Statistic. If this statistic has saved data, the new instance will also have that data.
        Returns:
        a copy of the supplied Statistic
      • getIndexOfMin

        public static int getIndexOfMin​(double[] x)
        Returns the index associated with the minimum element in the array For ties, this returns the first found
        Parameters:
        x - the array of data
        Returns:
        the index associated with the minimum element
      • getMin

        public static double getMin​(double[] x)
        Parameters:
        x - the array of data
        Returns:
        the minimum value in the array
      • getIndexOfMax

        public static int getIndexOfMax​(double[] x)
        Returns the index associated with the maximum element in the array For ties, this returns the first found
        Parameters:
        x - the array of data
        Returns:
        the index associated with the maximum element
      • getMax

        public static double getMax​(double[] x)
        Parameters:
        x - the array of data
        Returns:
        the maximum value in the array
      • getMedian

        public static double getMedian​(double[] data)
        Returns the median of the data. The array is sorted
        Parameters:
        data - the array of data, must not be null
        Returns:
        the median of the data
      • countLessEqualTo

        public static int countLessEqualTo​(double[] data,
                                           double x)
        Parameters:
        data - the data to count
        x - the ordinate to check
        Returns:
        the number of data points less than or equal to x
      • countLessThan

        public static int countLessThan​(double[] data,
                                        double x)
        Parameters:
        data - the data to count
        x - the ordinate to check
        Returns:
        the number of data points less than x
      • countGreaterEqualTo

        public static int countGreaterEqualTo​(double[] data,
                                              double x)
        Parameters:
        data - the data to count
        x - the ordinate to check
        Returns:
        the number of data points greater than or equal to x
      • countGreaterThan

        public static int countGreaterThan​(double[] data,
                                           double x)
        Parameters:
        data - the data to count
        x - the ordinate to check
        Returns:
        the number of data points greater than x
      • getOrderStatistics

        public static double[] getOrderStatistics​(double[] data)
        Parameters:
        data - the data to sort
        Returns:
        a copy of the sorted array in ascending order representing the order statistics
      • getCount

        public final double getCount()
        Description copied from interface: StatisticAccessorIfc
        Gets the count of the number of the observations.
        Returns:
        A double representing the count
      • getSum

        public final double getSum()
        Description copied from interface: StatisticAccessorIfc
        Gets the sum of the observations.
        Returns:
        A double representing the unweighted sum
      • getAverage

        public final double getAverage()
        Description copied from interface: StatisticAccessorIfc
        Gets the unweighted average of the observations.
        Returns:
        A double representing the average or Double.NaN if no observations.
      • get2ndCentralMoment

        public final double get2ndCentralMoment()
        Returns the 2nd statistical central moment
        Returns:
        the 2nd statistical central moment
      • get3rdCentralMoment

        public final double get3rdCentralMoment()
        Returns the 3rd statistical central moment
        Returns:
        the 3rd statistical central moment
      • get4thCentralMoment

        public final double get4thCentralMoment()
        Returns the 4th statistical central moment
        Returns:
        the 4th statistical central moment
      • getCentralMoments

        public final double[] getCentralMoments()
        The 0th moment is the count, the 1st central moment zero, the 2nd, 3rd, and 4th central moments
        Returns:
        an array holding the central moments, 0, 1, 2, 3, 4
      • get2ndRawMoment

        public final double get2ndRawMoment()
        Returns the 2nd statistical raw moment (about zero)
        Returns:
        the 2nd statistical raw moment (about zero)
      • get3rdRawMoment

        public final double get3rdRawMoment()
        Returns the 3rd statistical raw moment (about zero)
        Returns:
        the 3rd statistical raw moment (about zero)
      • get4thRawMoment

        public final double get4thRawMoment()
        Returns the 4th statistical raw moment (about zero)
        Returns:
        the 4th statistical raw moment (about zero)
      • getDeviationSumOfSquares

        public final double getDeviationSumOfSquares()
        Description copied from interface: StatisticAccessorIfc
        Gets the sum of squares of the deviations from the average This is the numerator in the classic sample variance formula
        Returns:
        A double representing the sum of squares of the deviations from the average
      • getVariance

        public final double getVariance()
        Description copied from interface: StatisticAccessorIfc
        Gets the sample variance of the observations.
        Returns:
        A double representing the generate variance or Double.NaN if 1 or less observations.
      • getMin

        public final double getMin()
        Description copied from interface: StatisticAccessorIfc
        Gets the minimum of the observations.
        Returns:
        A double representing the minimum
      • getMax

        public final double getMax()
        Description copied from interface: StatisticAccessorIfc
        Gets the maximum of the observations.
        Returns:
        A double representing the maximum
      • getLastValue

        public final double getLastValue()
        Description copied from interface: StatisticAccessorIfc
        Gets the last observed data point
        Returns:
        A double representing the last observations
      • getKurtosis

        public final double getKurtosis()
        Description copied from interface: StatisticAccessorIfc
        Gets the kurtosis of the data
        Returns:
        A double representing the kurtosis
      • getSkewness

        public final double getSkewness()
        Description copied from interface: StatisticAccessorIfc
        Gets the skewness of the data
        Returns:
        A double representing the skewness
      • checkMean

        public final boolean checkMean​(double mean)
        Checks if the supplied value falls within getAverage() +/- getHalfWidth()
        Parameters:
        mean - the value to check
        Returns:
        true if the supplied value falls within getAverage() +/- getHalfWidth()
      • getHalfWidth

        public double getHalfWidth​(double level)
        Returns the half-width for a confidence interval on the mean with confidence level based on StudentT distribution
        Parameters:
        level - the confidence level
        Returns:
        the half-width
      • getStandardError

        public final double getStandardError()
        Description copied from interface: StatisticAccessorIfc
        Gets the standard error of the observations. Simply the generate standard deviation divided by the square root of the number of observations
        Returns:
        A double representing the standard error or Double.NaN if < 1 observation
      • getLeadingDigitRule

        public final int getLeadingDigitRule​(double a)
        Description copied from interface: StatisticAccessorIfc
        Computes the right most meaningful digit according to (int)Math.floor(Math.log10(a*getStandardError())) See doi 10.1287.opre.1080.0529 by Song and Schmeiser
        Parameters:
        a - the std error multiplier
        Returns:
        the meaningful digit
      • getLag1Covariance

        public final double getLag1Covariance()
        Description copied from interface: StatisticAccessorIfc
        Gets the lag-1 generate covariance of the unweighted observations. Note: See Box, Jenkins, Reinsel, Time Series Analysis, 3rd edition, Prentice-Hall, pg 31
        Returns:
        A double representing the generate covariance or Double.NaN if <=2 observations
      • getLag1Correlation

        public final double getLag1Correlation()
        Description copied from interface: StatisticAccessorIfc
        Gets the lag-1 generate correlation of the unweighted observations. Note: See Box, Jenkins, Reinsel, Time Series Analysis, 3rd edition, Prentice-Hall, pg 31
        Returns:
        A double representing the generate correlation or Double.NaN if <=2 observations
      • getVonNeumannLag1TestStatistic

        public final double getVonNeumannLag1TestStatistic()
        Description copied from interface: StatisticAccessorIfc
        Gets the Von Neumann Lag 1 test statistic for checking the hypothesis that the data are uncorrelated Note: See Handbook of Simulation, Jerry Banks editor, McGraw-Hill, pg 253.
        Returns:
        A double representing the Von Neumann test statistic
      • getVonNeumannLag1TestStatisticPValue

        public final double getVonNeumannLag1TestStatisticPValue()
        Description copied from interface: StatisticAccessorIfc
        Returns the asymptotic p-value for the Von Nueumann Lag-1 Test Statistic:

        Normal.stdNormalComplementaryCDF(getVonNeumannLag1TestStatistic());

        Returns:
        the p-value
      • getObsWeightedSum

        public final double getObsWeightedSum()
        Returns the observation weighted sum of the data i.e. sum = sum + j*x where j is the observation number and x is jth observation
        Returns:
        the observation weighted sum of the data
      • collect

        public void collect​(double x)
        Description copied from interface: CollectorIfc
        Collect on the supplied value
        Parameters:
        x - a double representing the observation
      • reset

        public void reset()
        Description copied from interface: CollectorIfc
        Resets the collector as if no observations had been collected.
      • asString

        public java.lang.String asString()
      • toString

        public java.lang.String toString()
        Description copied from interface: StatisticAccessorIfc
        Returns a String representation of the Statistic
        Specified by:
        toString in interface StatisticAccessorIfc
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String with basic summary statistics
      • getSummaryStatistics

        public java.lang.String getSummaryStatistics()
        Returns the summary statistics values Name Count Average Std. Dev.
        Returns:
        the string of summary statistics
      • getSummaryStatisticsHeader

        public java.lang.String getSummaryStatisticsHeader()
        Returns the header for the summary statistics Name Count Average Std. Dev.
        Returns:
        the header
      • estimateSampleSize

        public final long estimateSampleSize​(double desiredHW)
        Estimates the number of observations needed in order to obtain a getConfidenceLevel() confidence interval with plus/minus the provided half-width
        Parameters:
        desiredHW - the desired half-width, must be greater than zero
        Returns:
        the estimated sample size
      • estimateSampleSize

        public static long estimateSampleSize​(double desiredHW,
                                              double stdDev,
                                              double level)
        Estimate the sample size based on a normal approximation
        Parameters:
        desiredHW - the desired half-width (must be bigger than 0)
        stdDev - the standard deviation (must be bigger than or equal to 0)
        level - the confidence level (must be between 0 and 1)
        Returns:
        the estimated sample size