/** * Constructs a Variance with default (true) <code>isBiasCorrected</code> * property. */ public Variance() { moment = new SecondMoment(); }
/** * {@inheritDoc} */ @Override public void clear() { if (incMoment) { moment.clear(); } }
/** * {@inheritDoc} */ public long getN() { return moment.getN(); }
/** * {@inheritDoc} */ @Override public SecondMoment copy() { SecondMoment result = new SecondMoment(); copy(this, result); return result; }
/** * <p>Returns the sum of squared deviations of Y from its mean.</p> * * <p>If the model has no intercept term, <code>0</code> is used for the * mean of Y - i.e., what is returned is the sum of the squared Y values.</p> * * <p>The value returned by this method is the SSTO value used in * the {@link #calculateRSquared() R-squared} computation.</p> * * @return SSTO - the total sum of squares * @see #isNoIntercept() * @since 2.2 */ public double calculateTotalSumOfSquares() { if (isNoIntercept()) { return StatUtils.sumSq(Y.getData()); } else { return new SecondMoment().evaluate(Y.getData()); } }
/** * {@inheritDoc} */ @Override public void increment(final double d) { if (n < 1) { m3 = m2 = m1 = 0.0; } double prevM2 = m2; super.increment(d); nDevSq = nDev * nDev; double n0 = n; m3 = m3 - 3.0 * nDev * prevM2 + (n0 - 1) * (n0 - 2) * nDevSq * dev; }
/** * Copies source to dest. * <p>Neither source nor dest can be null.</p> * * @param source Variance to copy * @param dest Variance to copy to * @throws NullPointerException if either source or dest is null */ public static void copy(Variance source, Variance dest) { dest.moment = source.moment.copy(); dest.isBiasCorrected = source.isBiasCorrected; dest.incMoment = source.incMoment; }
/** * Returns a statistic related to the Second Central Moment. Specifically, * what is returned is the sum of squared deviations from the sample mean * among the values that have been added. * <p> * Returns <code>Double.NaN</code> if no data values have been added and * returns <code>0</code> if there is just one value in the data set.</p> * <p> * @return second central moment statistic * @since 2.0 */ public double getSecondMoment() { return secondMoment.getResult(); }
geometricMean = descriptiveStats.getGeometricMean(); sumOfSquares = descriptiveStats.getSumsq(); secondMoment = new SecondMoment().evaluate(descriptiveStats.getValues()); } else { final SummaryStatistics summaryStats = (SummaryStatistics) s;
/** * {@inheritDoc} */ @Override public SecondMoment copy() { SecondMoment result = new SecondMoment(); copy(this, result); return result; }
/** * {@inheritDoc} * <p>If all values are available, it is more accurate to use * {@link #evaluate(double[])} rather than adding values one at a time * using this method and then executing {@link #getResult}, since * <code>evaluate</code> leverages the fact that is has the full * list of values together to execute a two-pass algorithm. * See {@link Variance}.</p> */ @Override public void increment(final double d) { if (incMoment) { moment.increment(d); } }
/** * Copies source to dest. * <p>Neither source nor dest can be null.</p> * * @param source ThirdMoment to copy * @param dest ThirdMoment to copy to * @throws NullPointerException if either source or dest is null */ public static void copy(ThirdMoment source, ThirdMoment dest) { SecondMoment.copy(source, dest); dest.m3 = source.m3; dest.nDevSq = source.nDevSq; }
/** * Returns a statistic related to the Second Central Moment. Specifically, * what is returned is the sum of squared deviations from the sample mean * among the values that have been added. * <p> * Returns <code>Double.NaN</code> if no data values have been added and * returns <code>0</code> if there is just one value in the data set.</p> * <p> * @return second central moment statistic * @since 2.0 */ public double getSecondMoment() { return secondMoment.getResult(); }
geometricMean = descriptiveStats.getGeometricMean(); sumOfSquares = descriptiveStats.getSumsq(); secondMoment = new SecondMoment().evaluate(descriptiveStats.getValues()); } else { final SummaryStatistics summaryStats = (SummaryStatistics) s;
/** * Constructs a Variance with default (true) <code>isBiasCorrected</code> * property. */ public Variance() { moment = new SecondMoment(); }
/** * {@inheritDoc} */ @Override public void clear() { super.clear(); m3 = Double.NaN; nDevSq = Double.NaN; }
/** * @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#increment(double) */ public void increment(final double d) { if (n < 1) { m3 = m2 = m1 = 0.0; } double prevM2 = m2; super.increment(d); nDevSq = nDev * nDev; double n0 = (double) n; m3 = m3 - 3.0 * nDev * prevM2 + (n0 - 1) * (n0 - 2) * nDevSq * dev; }
/** * @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#getN() */ public long getN() { return moment.getN(); }
/** * Copies source to dest. * <p>Neither source nor dest can be null.</p> * * @param source ThirdMoment to copy * @param dest ThirdMoment to copy to * @throws NullPointerException if either source or dest is null */ public static void copy(ThirdMoment source, ThirdMoment dest) { SecondMoment.copy(source, dest); dest.m3 = source.m3; dest.nDevSq = source.nDevSq; }
/** * Constructs a Variance with the specified <code>isBiasCorrected</code> * property * * @param isBiasCorrected setting for bias correction - true means * bias will be corrected and is equivalent to using the argumentless * constructor */ public Variance(boolean isBiasCorrected) { moment = new SecondMoment(); this.isBiasCorrected = isBiasCorrected; }