Package org.djutils.stats.summarizers
Class Tally
java.lang.Object
org.djutils.stats.summarizers.Tally
- All Implemented Interfaces:
- Serializable,- Statistic,- TallyStatistic
- Direct Known Subclasses:
- EventBasedTally
The Tally class registers a series of values and provides mean, standard deviation, etc. of the registered values.
 
 Copyright (c) 2002-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
 for project information  https://simulation.tudelft.nl. The DSOL
 project is distributed under a three-clause BSD-style license, which can be found at
 
 https://simulation.tudelft.nl/dsol/3.0/license.html. 
- Author:
- Alexander Verbraeck, Peter Jacobs , Peter Knoppers
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionConvenience constructor that uses a NoStorageAccumulator to estimate quantiles.Tally(String description, QuantileAccumulator quantileAccumulator) Constructs a new Tally.
- 
Method SummaryModifier and TypeMethodDescriptiondouble[]getConfidenceInterval(double alpha) returns the confidence interval on either side of the mean.double[]getConfidenceInterval(double alpha, ConfidenceInterval side) returns the confidence interval based of the mean.doublegetCumulativeProbability(double quantile) Get, or estimate fraction of registered values between -infinity up to and including a given quantile.Returns the description of the statistic.doublegetMax()Returns the maximum value of any given observation, or NaN when no observations were registered.doublegetMin()Returns the minimum value of any given observation, or NaN when no observations were registered.longgetN()Return the current number of observations.doubleReturn the population excess kurtosis of the registered data.doubleReturn the (biased) population kurtosis of the registered data.doubleReturns the population mean of all observations since the initialization.doubleReturn the (biased) population skewness of the registered data.doubleReturns the current (biased) population standard deviation of all observations since the initialization.doubleReturns the current (biased) population variance of all observations since the initialization.doublegetQuantile(double probability) Compute the quantile for the given probability.doubleReturn the sample excess kurtosis of the registered data.doubleReturn the sample kurtosis of the registered data.doubleReturns the sample mean of all observations since the initialization.doubleReturn the (unbiased) sample skewness of the registered data.doubleReturns the current (unbiased) sample standard deviation of all observations since the initialization.doubleReturns the current (unbiased) sample variance of all observations since the initialization.doublegetSum()Return the sum of the values of the observations.voidInitialize the statistic.doubleregister(double value) Process one observed value.voidregister(double... values) Ingest an array of values.static StringReturn a string representing a footer for a textual table with a monospaced font that can contain multiple statistics.static StringReturn a string representing a header for a textual table with a monospaced font that can contain multiple statistics.Return a string representing a line with important statistics values for this statistic, for a textual table with a monospaced font that can contain multiple statistics.voidsetDescription(String description) Set a new description of the statistic.toString()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.stats.summarizers.StatisticformatFixed
- 
Field Details- 
semaphorethe synchronized lock.
 
- 
- 
Constructor Details- 
TallyConvenience constructor that uses a NoStorageAccumulator to estimate quantiles.- Parameters:
- description- the description of this tally
 
- 
TallyConstructs a new Tally.- Parameters:
- description- the description of this tally
- quantileAccumulator- the input series accumulator that can approximate or compute quantiles.
 
 
- 
- 
Method Details- 
initializepublic void initialize()Description copied from interface:StatisticInitialize the statistic.- Specified by:
- initializein interface- Statistic
 
- 
setDescriptionDescription copied from interface:StatisticSet a new description of the statistic.- Specified by:
- setDescriptionin interface- Statistic
- Parameters:
- description- the new description of the statistic
 
- 
registerpublic void register(double... values) Ingest an array of values.- Parameters:
- values- the values to register
 
- 
registerpublic double register(double value) Process one observed value.- Parameters:
- value- the value to process
- Returns:
- the value
 
- 
getDescriptionDescription copied from interface:StatisticReturns the description of the statistic.- Specified by:
- getDescriptionin interface- Statistic
- Returns:
- the description of the statistic
 
- 
getMaxpublic double getMax()Description copied from interface:TallyStatisticReturns the maximum value of any given observation, or NaN when no observations were registered.- Specified by:
- getMaxin interface- TallyStatistic
- Returns:
- the maximum value of any given observation
 
- 
getMinpublic double getMin()Description copied from interface:TallyStatisticReturns the minimum value of any given observation, or NaN when no observations were registered.- Specified by:
- getMinin interface- TallyStatistic
- Returns:
- the minimum value of any given observation
 
- 
getNpublic long getN()Description copied from interface:StatisticReturn the current number of observations.
- 
getSumpublic double getSum()Return the sum of the values of the observations.- Returns:
- the sum of the values of the observations
 
- 
getSampleMeanpublic double getSampleMean()Returns the sample mean of all observations since the initialization.- Returns:
- the sample mean
 
- 
getPopulationMeanpublic double getPopulationMean()Returns the population mean of all observations since the initialization.- Returns:
- the population mean
 
- 
getSampleStDevpublic double getSampleStDev()Returns the current (unbiased) sample standard deviation of all observations since the initialization. The sample standard deviation is defined as the square root of the sample variance.- Returns:
- the sample standard deviation
 
- 
getPopulationStDevpublic double getPopulationStDev()Returns the current (biased) population standard deviation of all observations since the initialization. The population standard deviation is defined as the square root of the population variance.- Returns:
- the population standard deviation
 
- 
getSampleVariancepublic double getSampleVariance()Returns the current (unbiased) sample variance of all observations since the initialization. The calculation of the sample variance in relation to the population variance is undisputed. The formula is:
 S2 = (1 / (n - 1)) * [ Σx2 - (Σx)2 / n ]
 which can be calculated on the basis of the calculated population variance σ2 as follows:
 S2 = σ2 * n / (n - 1)- Returns:
- the current sample variance of this tally
 
- 
getPopulationVariancepublic double getPopulationVariance()Returns the current (biased) population variance of all observations since the initialization. The population variance is defined as:
 σ2 = (1 / n) * [ Σx2 - (Σx)2 / n ]- Returns:
- the current population variance of this tally
 
- 
getSampleSkewnesspublic double getSampleSkewness()Return the (unbiased) sample skewness of the registered data. There are different formulas to calculate the unbiased (sample) skewness from the biased (population) skewness. Minitab, for instance calculates unbiased skewness as:
 Skewunbiased = Skewbiased [ ( n - 1) / n ] 3/2
 whereas SAS, SPSS and Excel calculate it as:
 Skewunbiased = Skewbiased √[ n ( n - 1)] / (n - 2)
 Here we follow the last mentioned formula. All formulas converge to the same value with larger n.- Returns:
- the sample skewness of the registered data
 
- 
getPopulationSkewnesspublic double getPopulationSkewness()Return the (biased) population skewness of the registered data. The population skewness is defined as:
 Skewbiased = [ Σ ( x - μ ) 3 ] / [ n . S3 ]
 where S2 is the sample variance. So the denominator is equal to [ n . sample_var3/2 ] .- Returns:
- the skewness of the registered data
 
- 
getSampleKurtosispublic double getSampleKurtosis()Return the sample kurtosis of the registered data. The sample kurtosis can be defined in multiple ways. Here, we choose the following formula:
 Kurtunbiased = [ Σ ( x - μ ) 4 ] / [ ( n - 1 ) . S4 ]
 where S2 is the sample variance. So the denominator is equal to [ ( n - 1 ) . sample_var2 ] .- Returns:
- the sample kurtosis of the registered data
 
- 
getPopulationKurtosispublic double getPopulationKurtosis()Return the (biased) population kurtosis of the registered data. The population kurtosis is defined as:
 Kurtbiased = [ Σ ( x - μ ) 4 ] / [ n . σ4 ]
 where σ2 is the population variance. So the denominator is equal to [ n . pop_var2 ] .- Returns:
- the population kurtosis of the registered data
 
- 
getSampleExcessKurtosispublic double getSampleExcessKurtosis()Return the sample excess kurtosis of the registered data. The sample excess kurtosis is the sample-corrected value of the excess kurtosis. Several formulas exist to calculate the sample excess kurtosis from the population kurtosis. Here we use:
 ExcessKurtunbiased = ( n - 1 ) / [( n - 2 ) * ( n - 3 )] [ ( n + 1 ) * ExcessKurtbiased + 6]
 This is the excess kurtosis that is calculated by, for instance, SAS, SPSS and Excel.- Returns:
- the sample excess kurtosis of the registered data
 
- 
getPopulationExcessKurtosispublic double getPopulationExcessKurtosis()Return the population excess kurtosis of the registered data. The kurtosis value of the normal distribution is 3. The excess kurtosis is the kurtosis value shifted by -3 to be 0 for the normal distribution.- Returns:
- the population excess kurtosis of the registered data
 
- 
getQuantilepublic double getQuantile(double probability) Compute the quantile for the given probability.- Parameters:
- probability- the probability for which the quantile is to be computed. The value should be between 0 and 1, inclusive.
- Returns:
- the quantile for the probability
- Throws:
- IllegalArgumentException- when the probability is less than 0 or larger than 1
 
- 
getCumulativeProbabilitypublic double getCumulativeProbability(double quantile) Get, or estimate fraction of registered values between -infinity up to and including a given quantile.- Parameters:
- quantile- the given quantile
- Returns:
- the estimated or observed fraction of registered values between -infinity up to and including the given quantile. When this TallyInterface has registered zero values; this method shall return NaN.
- Throws:
- IllegalArgumentException- when quantile is NaN
 
- 
getConfidenceIntervalpublic double[] getConfidenceInterval(double alpha) returns the confidence interval on either side of the mean.- Parameters:
- alpha- Alpha is the significance level used to compute the confidence level. The confidence level equals 100*(1 - alpha)%, or in other words, an alpha of 0.05 indicates a 95 percent confidence level.
- Returns:
- the confidence interval of this tally
- Throws:
- IllegalArgumentException- when alpha is less than 0 or larger than 1
 
- 
getConfidenceIntervalreturns the confidence interval based of the mean.- Parameters:
- alpha- Alpha is the significance level used to compute the confidence level. The confidence level equals 100*(1 - alpha)%, or in other words, an alpha of 0.05 indicates a 95 percent confidence level.
- side- the side of the confidence interval with respect to the mean
- Returns:
- the confidence interval of this tally
- Throws:
- IllegalArgumentException- when alpha is less than 0 or larger than 1
- NullPointerException- when side is null
 
- 
toString
- 
reportHeaderReturn a string representing a header for a textual table with a monospaced font that can contain multiple statistics.- Returns:
- header for the textual table.
 
- 
reportLineDescription copied from interface:StatisticReturn a string representing a line with important statistics values for this statistic, for a textual table with a monospaced font that can contain multiple statistics.- Specified by:
- reportLinein interface- Statistic
- Returns:
- line with most important values of the statistic
 
 
-