/** * Calculates the regression coefficients using OLS. * * <p>Data for the model must have been successfully loaded using one of * the {@code newSampleData} methods before invoking this method; otherwise * a {@code NullPointerException} will be thrown.</p> * * @return beta * @throws org.apache.commons.math3.linear.SingularMatrixException if the design matrix is singular * @throws NullPointerException if the data for the model have not been loaded */ @Override protected RealVector calculateBeta() { return qr.getSolver().solve(getY()); }
/** * <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()); } }
/** * Calculates the regression coefficients using OLS. * * <p>Data for the model must have been successfully loaded using one of * the {@code newSampleData} methods before invoking this method; otherwise * a {@code NullPointerException} will be thrown.</p> * * @return beta * @throws org.apache.commons.math3.linear.SingularMatrixException if the design matrix is singular * @throws NullPointerException if the data for the model have not been loaded */ @Override protected RealVector calculateBeta() { return qr.getSolver().solve(getY()); }
/** * Calculates the regression coefficients using OLS. * * <p>Data for the model must have been successfully loaded using one of * the {@code newSampleData} methods before invoking this method; otherwise * a {@code NullPointerException} will be thrown.</p> * * @return beta * @throws org.apache.commons.math3.linear.SingularMatrixException if the design matrix is singular * @throws NullPointerException if the data for the model have not been loaded */ @Override protected RealVector calculateBeta() { return qr.getSolver().solve(getY()); }
/** * <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()); } }
/** * <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()); } }