Class DistributionStatistics
java.lang.Object
com.amalgamasimulation.core.statistics.DistributionStatistics
Provides statistical analysis for a series of numerical (double) values,
including mean, standard deviation, percentile calculations, and confidence
intervals.
Typical usage:
// Simple example
DistributionStatistics stats = new DistributionStatistics();
stats.add(2.5);
stats.add(3.0);
Interval ci = stats.confidenceInterval95();
// Stream-based example of usage from a list
List<Double> values = Arrays.asList(2.5, 3.0, 4.1, 5.0);
DistributionStatistics statsFromStream = values.stream()
.collect(DistributionStatistics::new,
DistributionStatistics::add,
DistributionStatistics::combine);
Author: Andrey Malykhanov-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double value) Adds a new value to the values.doubleaverage()Returns the arithmetic mean (average) of the values.voidcombine(DistributionStatistics other) Merges anotherDistributionStatisticsinstance into this one.confidenceInterval(double percent) Returns the confidence interval for the sample mean at the given confidence level.Returns the 95% confidence interval for the sample mean using Student’s t-distribution.intcount()Returns the number of values added.static DistributionStatisticsempty()booleanisEmpty()doublemax()Returns the maximum value.doublemedian()Returns the median (50th percentile) of the values.doublemin()Returns the minimum value.doublepercentile(double percentile) Returns the specified percentile value.range()Returns the range as anIntervalfrommin()tomax(), orInterval.EMPTYif no values have been addeddoublestDev()Returns the sample standard deviation of the values, orNaNif less than two values are present.toString()values()Returns a list of all values currently stored, sorted in ascending order.
-
Constructor Details
-
DistributionStatistics
public DistributionStatistics()
-
-
Method Details
-
empty
-
add
public void add(double value) Adds a new value to the values.- Parameters:
value- the numerical value to add
-
combine
Merges anotherDistributionStatisticsinstance into this one.- Parameters:
other- the otherDistributionStatisticswhose values will be added to this instance
-
count
public int count()Returns the number of values added.- Returns:
- the count of values
-
average
public double average()Returns the arithmetic mean (average) of the values.- Returns:
- the mean of the values, or
NaNif no values have been added
-
median
public double median()Returns the median (50th percentile) of the values.- Returns:
- the median value
- See Also:
-
max
public double max()Returns the maximum value.- Returns:
- the maximum value, or
NaNif no values have been added
-
min
public double min()Returns the minimum value.- Returns:
- the minimum value, or
NaNif no values have been added
-
stDev
public double stDev()Returns the sample standard deviation of the values, orNaNif less than two values are present.- Returns:
- the standard deviation, or
NaNt
-
range
Returns the range as anIntervalfrommin()tomax(), orInterval.EMPTYif no values have been added- Returns:
- an
Intervalrepresenting the range of values
-
values
Returns a list of all values currently stored, sorted in ascending order.- Returns:
- a
List<Double>of stored values
-
confidenceInterval95
Returns the 95% confidence interval for the sample mean using Student’s t-distribution.- Returns:
- an
Intervalrepresenting the 95% confidence interval, orInterval.UNIVERSEif fewer than two values
-
isEmpty
public boolean isEmpty() -
confidenceInterval
Returns the confidence interval for the sample mean at the given confidence level.- Parameters:
percent- confidence level between 0 and 1 (e.g., 0.95 for 95%)- Returns:
- an
Intervalrepresenting the confidence interval; returnsInterval.UNIVERSEif fewer than 2 values - Throws:
IllegalArgumentException- ifpercentis not between 0 and 1
-
percentile
public double percentile(double percentile) Returns the specified percentile value.- Parameters:
percentile- a value between 0 and 1 (e.g., 0.95 for 95th percentile)- Returns:
- the percentile value
- Throws:
IllegalArgumentException- ifpercentileis not between 0 and 1
-
toString
-