Class DistributionStatistics

java.lang.Object
com.amalgamasimulation.core.statistics.DistributionStatistics

public class DistributionStatistics extends Object
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 Details

    • DistributionStatistics

      public DistributionStatistics()
  • Method Details

    • empty

      public static DistributionStatistics empty()
    • add

      public void add(double value)
      Adds a new value to the values.
      Parameters:
      value - the numerical value to add
    • combine

      public void combine(DistributionStatistics other)
      Merges another DistributionStatistics instance into this one.
      Parameters:
      other - the other DistributionStatistics whose 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 NaN if 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 NaN if no values have been added
    • min

      public double min()
      Returns the minimum value.
      Returns:
      the minimum value, or NaN if no values have been added
    • stDev

      public double stDev()
      Returns the sample standard deviation of the values, or NaN if less than two values are present.
      Returns:
      the standard deviation, or NaNt
    • range

      public Interval range()
      Returns the range as an Interval from min() to max(), or Interval.EMPTY if no values have been added
      Returns:
      an Interval representing the range of values
    • values

      public List<Double> values()
      Returns a list of all values currently stored, sorted in ascending order.
      Returns:
      a List<Double> of stored values
    • confidenceInterval95

      public Interval confidenceInterval95()
      Returns the 95% confidence interval for the sample mean using Student’s t-distribution.
      Returns:
      an Interval representing the 95% confidence interval, or Interval.UNIVERSE if fewer than two values
    • isEmpty

      public boolean isEmpty()
    • confidenceInterval

      public Interval confidenceInterval(double percent)
      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 Interval representing the confidence interval; returns Interval.UNIVERSE if fewer than 2 values
      Throws:
      IllegalArgumentException - if percent is 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 - if percentile is not between 0 and 1
    • toString

      public String toString()
      Overrides:
      toString in class Object