public class Mean extends Object implements Statistic
mean.
addData(double...) appends observations to the accumulated sample;
it does not replace earlier observations. N() counts all observations.
value() returns Double.NaN before the first observation.
Create a new calculator to start a new sample. Empty update batches are
ignored, including before the first observation.
import dev.nm.stat.descriptive.moment.Mean;
import dev.nm.stat.descriptive.moment.Variance;
Mean mean = new Mean(new double[]{1, 2});
mean.addData(3, 4);
assert mean.N() == 4;
assert mean.value() == 2.5;
Variance sample = new Variance(new double[]{1, 2, 3, 4});
Variance population = new Variance(new double[]{1, 2, 3, 4}, false);
assert Math.abs(sample.value() - 5.0 / 3.0) < 1e-12;
assert Math.abs(population.value() - 1.25) < 1e-12;
Empty batches are safe before, between, and after observations. They do not reset the sample.
import dev.nm.stat.descriptive.moment.Mean;
Mean mean = new Mean();
mean.addData();
assert Double.isNaN(mean.value());
mean.addData(3, 5);
mean.addData(new double[0]);
assert mean.N() == 2;
assert mean.value() == 4.0;
| Constructor and Description |
|---|
Mean()
Construct an empty
Mean calculator. |
Mean(double[] data)
Construct a
Mean calculator,
initialized with a sample. |
Mean(Mean that)
Copy constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addData(double... data)
Appends observations to the current sample.
|
long |
N()
Get the size of the sample.
|
String |
toString() |
double |
value()
Returns the arithmetic mean of all observations added so far.
|
public Mean()
Mean calculator.public Mean(double[] data)
Mean calculator,
initialized with a sample.data - a samplepublic Mean(Mean that)
that - a Mean calculatorpublic void addData(double... data)
public double value()
public long N()
StatisticCopyright © 2010-2026 NM Group. All Rights Reserved.