/** * 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; }
/** * 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(); }
/** * {@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; }
/** * {@inheritDoc} */ @Override public SecondMoment copy() { SecondMoment result = new SecondMoment(); // no try-catch or advertised NAE because args are guaranteed non-null 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 * @throws NullPointerException if the sample has not been set * @see #isNoIntercept() * @since 2.2 */ public double calculateTotalSumOfSquares() { if (isNoIntercept()) { return StatUtils.sumSq(getY().toArray()); } else { return new SecondMoment().evaluate(getY().toArray()); } }
/** * {@inheritDoc} */ @Override public void clear() { if (incMoment) { moment.clear(); } }
/** * 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 NullArgumentException if either source or dest is null */ public static void copy(ThirdMoment source, ThirdMoment dest) throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); SecondMoment.copy(source, dest); dest.m3 = source.m3; dest.nDevSq = source.nDevSq; }
/** * {@inheritDoc} */ public long getN() { return moment.getN(); }
/** * {@inheritDoc} */ @Override public SecondMoment copy() { SecondMoment result = new SecondMoment(); // no try-catch or advertised NAE because args are guaranteed non-null 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 * @throws NullPointerException if the sample has not been set * @see #isNoIntercept() * @since 2.2 */ public double calculateTotalSumOfSquares() { if (isNoIntercept()) { return StatUtils.sumSq(getY().toArray()); } else { return new SecondMoment().evaluate(getY().toArray()); } }
/** * {@inheritDoc} */ @Override public void clear() { super.clear(); m3 = Double.NaN; nDevSq = Double.NaN; }
/** * 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 NullArgumentException if either source or dest is null */ public static void copy(Variance source, Variance dest) throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.moment = source.moment.copy(); dest.isBiasCorrected = source.isBiasCorrected; dest.incMoment = source.incMoment; } }
/** * {@inheritDoc} */ public long getN() { return moment.getN(); }
/** * Constructs a Variance with default (true) <code>isBiasCorrected</code> * property. */ public Variance() { moment = new SecondMoment(); }
/** * {@inheritDoc} */ @Override public SecondMoment copy() { SecondMoment result = new SecondMoment(); // no try-catch or advertised NAE because args are guaranteed non-null 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 * @throws NullPointerException if the sample has not been set * @see #isNoIntercept() * @since 2.2 */ public double calculateTotalSumOfSquares() { if (isNoIntercept()) { return StatUtils.sumSq(getY().toArray()); } else { return new SecondMoment().evaluate(getY().toArray()); } }
/** * {@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> * * <p>Note also that when {@link #Variance(SecondMoment)} is used to * create a Variance, this method does nothing. In that case, the * SecondMoment should be incremented directly.</p> */ @Override public void increment(final double d) { if (incMoment) { moment.increment(d); } }
/** * Resets all statistics and storage */ public void clear() { this.n = 0; minImpl.clear(); maxImpl.clear(); sumImpl.clear(); sumLogImpl.clear(); sumsqImpl.clear(); geoMeanImpl.clear(); secondMoment.clear(); if (meanImpl != mean) { meanImpl.clear(); } if (varianceImpl != variance) { varianceImpl.clear(); } }
dest.sumLogImpl = source.sumLogImpl.copy(); dest.sumsqImpl = source.sumsqImpl.copy(); dest.secondMoment = source.secondMoment.copy(); dest.n = source.n;
/** * 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(); }