## org.apache.commons.math3.stat.regression
Class RegressionResults

    java.lang.Object
      org.apache.commons.math3.stat.regression.RegressionResults

All Implemented Interfaces:
  java.io.Serializable

    public class RegressionResults

extends java.lang.Object
implements java.io.Serializable

Results of a Multiple Linear Regression model fit.

Since:
  3.0
Version:
  $Id: RegressionResults.java 1392342 2012-10-01 14:08:52Z psteitz $
See Also:
  Serialized Form

Field Summary
`private static int` `ADJRSQ_IDX` INDEX of Adjusted R Squared
`private boolean` `containsConstant` boolean flag indicator of whether a constant was included
`private double[]` `globalFitInfo` array storing global results, SSE, MSE, RSQ, adjRSQ
`private boolean` `isSymmetricVCD` boolean flag for variance covariance matrix in symm compressed storage
`private static int` `MSE_IDX` INDEX of Mean Squared Error
`private long` `nobs` number of observations on which results are based
`private double[]` `parameters` regression slope parameters
`private int` `rank` rank of the solution
`private static int` `RSQ_IDX` INDEX of R-Squared of regression
`private static long` `serialVersionUID` UID
`private static int` `SSE_IDX` INDEX of Sum of Squared Errors
`private static int` `SST_IDX` INDEX of Sum of Squares of Model
`private double[][]` `varCovData` variance covariance matrix of parameters

Constructor Summary
`private` `RegressionResults()` Set the default constructor to private access to prevent inadvertent instantiation
`` `RegressionResults(double[] parameters, double[][] varcov, boolean isSymmetricCompressed, long nobs, int rank, double sumy, double sumysq, double sse, boolean containsConstant, boolean copyData)` Constructor for Regression Results.

Method Summary
`double` `getAdjustedRSquared()` Returns the adjusted R-squared statistic, defined by the formula
`double` `getCovarianceOfParameters(int i, int j)` Returns the covariance between regression parameters i and j.
`double` `getErrorSumSquares()` Returns the sum of squared errors (SSE) associated with the regression model.
`double` `getMeanSquareError()` Returns the sum of squared errors divided by the degrees of freedom, usually abbreviated MSE.
`long` `getN()` Returns the number of observations added to the regression model.
`int` `getNumberOfParameters()` Returns the number of parameters estimated in the model.
`double` `getParameterEstimate(int index)` Returns the parameter estimate for the regressor at the given index.
`double[]` `getParameterEstimates()` Returns a copy of the regression parameters estimates.
`double` `getRegressionSumSquares()` Returns the sum of squared deviations of the predicted y values about their mean (which equals the mean of y).
`double` `getRSquared()` Returns the coefficient of multiple determination, usually denoted r-square.
`double` `getStdErrorOfEstimate(int index)` Returns the standard error of the parameter estimate at index, usually denoted s(bindex).
`double[]` `getStdErrorOfEstimates()` Returns the standard error of the parameter estimates, usually denoted s(bi).
`double` `getTotalSumSquares()` Returns the sum of squared deviations of the y values about their mean.
`private double` `getVcvElement(int i, int j)` Gets the i-jth element of the variance-covariance matrix.
`boolean` `hasIntercept()` Returns true if the regression model has been computed including an intercept.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SSE_IDX

    private static final int SSE_IDX

  INDEX of Sum of Squared Errors

  See Also:
    Constant Field Values

### SST_IDX

    private static final int SST_IDX

  INDEX of Sum of Squares of Model

  See Also:
    Constant Field Values

### RSQ_IDX

    private static final int RSQ_IDX

  INDEX of R-Squared of regression

  See Also:
    Constant Field Values

### MSE_IDX

    private static final int MSE_IDX

  INDEX of Mean Squared Error

  See Also:
    Constant Field Values

### ADJRSQ_IDX

    private static final int ADJRSQ_IDX

  INDEX of Adjusted R Squared

  See Also:
    Constant Field Values

### serialVersionUID

    private static final long serialVersionUID

  UID

  See Also:
    Constant Field Values

### parameters

    private final double[] parameters

  regression slope parameters

### varCovData

    private final double[][] varCovData

  variance covariance matrix of parameters

### isSymmetricVCD

    private final boolean isSymmetricVCD

  boolean flag for variance covariance matrix in symm compressed storage

### rank

    private final int rank

  rank of the solution

### nobs

    private final long nobs

  number of observations on which results are based

### containsConstant

    private final boolean containsConstant

  boolean flag indicator of whether a constant was included

### globalFitInfo

    private final double[] globalFitInfo

  array storing global results, SSE, MSE, RSQ, adjRSQ

Constructor Detail

### RegressionResults

    private RegressionResults()

  Set the default constructor to private access to prevent inadvertent instantiation

### RegressionResults

    public RegressionResults(double[] parameters,
                             double[][] varcov,
                             boolean isSymmetricCompressed,
                             long nobs,
                             int rank,
                             double sumy,
                             double sumysq,
                             double sse,
                             boolean containsConstant,
                             boolean copyData)

  Constructor for Regression Results.

  Parameters:
    `parameters` - a double array with the regression slope estimates
    `varcov` - the variance covariance matrix, stored either in a square matrix or as a compressed
    `isSymmetricCompressed` - a flag which denotes that the variance covariance matrix is in symmetric compressed format
    `nobs` - the number of observations of the regression estimation
    `rank` - the number of independent variables in the regression
    `sumy` - the sum of the independent variable
    `sumysq` - the sum of the squared independent variable
    `sse` - sum of squared errors
    `containsConstant` - true model has constant, false model does not have constant
    `copyData` - if true a deep copy of all input data is made, if false only references are copied and the RegressionResults become mutable

Method Detail

### getParameterEstimate

    public double getParameterEstimate(int index)
                                throws OutOfRangeException

  Returns the parameter estimate for the regressor at the given index.

  A redundant regressor will have its redundancy flag set, as well as a parameters estimated equal to `Double.NaN`

  Parameters:
    `index` - Index.
  Returns:
    the parameters estimated for regressor at index.
  Throws:
    `OutOfRangeException` - if `index` is not in the interval `[0, number of parameters)`.

### getParameterEstimates

    public double[] getParameterEstimates()

  Returns a copy of the regression parameters estimates.

  The parameter estimates are returned in the natural order of the data.

  A redundant regressor will have its redundancy flag set, as will a parameter estimate equal to `Double.NaN`.

  Returns:
    array of parameter estimates, null if no estimation occurred

### getStdErrorOfEstimate

    public double getStdErrorOfEstimate(int index)
                                 throws OutOfRangeException

  Returns the standard error of the parameter estimate at index, usually denoted s(bindex).

  Parameters:
    `index` - Index.
  Returns:
    the standard errors associated with parameters estimated at index.
  Throws:
    `OutOfRangeException` - if `index` is not in the interval `[0, number of parameters)`.

### getStdErrorOfEstimates

    public double[] getStdErrorOfEstimates()

  Returns the standard error of the parameter estimates, usually denoted s(bi).

  If there are problems with an ill conditioned design matrix then the regressor which is redundant will be assigned `Double.NaN`.

  Returns:
    an array standard errors associated with parameters estimates, null if no estimation occurred

### getCovarianceOfParameters

    public double getCovarianceOfParameters(int i,
                                            int j)
                                     throws OutOfRangeException

  Returns the covariance between regression parameters i and j.

  If there are problems with an ill conditioned design matrix then the covariance which involves redundant columns will be assigned `Double.NaN`.

  Parameters:
    `i` - `i`th regression parameter.
    `j` - `j`th regression parameter.
  Returns:
    the covariance of the parameter estimates.
  Throws:
    `OutOfRangeException` - if `i` or `j` is not in the interval `[0, number of parameters)`.

### getNumberOfParameters

    public int getNumberOfParameters()

  Returns the number of parameters estimated in the model.

  This is the maximum number of regressors, some techniques may drop redundant parameters

  Returns:
    number of regressors, -1 if not estimated

### getN

    public long getN()

  Returns the number of observations added to the regression model.

  Returns:
    Number of observations, -1 if an error condition prevents estimation

### getTotalSumSquares

    public double getTotalSumSquares()

  Returns the sum of squared deviations of the y values about their mean.

  This is defined as SSTO here.

  If `n < 2`, this returns `Double.NaN`.

  Returns:
    sum of squared deviations of y values

### getRegressionSumSquares

    public double getRegressionSumSquares()

  Returns the sum of squared deviations of the predicted y values about their mean (which equals the mean of y).

  This is usually abbreviated SSR or SSM. It is defined as SSM here

  Preconditions:

  - At least two observations (with at least two different x values) must have been added before invoking this method. If this method is invoked before a model can be estimated, `Double.NaN` is returned.

  Returns:
    sum of squared deviations of predicted y values

### getErrorSumSquares

    public double getErrorSumSquares()

  Returns the sum of squared errors (SSE) associated with the regression model.

  The return value is constrained to be non-negative - i.e., if due to rounding errors the computational formula returns a negative result, 0 is returned.

  Preconditions:

  - numberOfParameters data pairs must have been added before invoking this method. If this method is invoked before a model can be estimated, `Double,NaN` is returned.

  Returns:
    sum of squared errors associated with the regression model

### getMeanSquareError

    public double getMeanSquareError()

  Returns the sum of squared errors divided by the degrees of freedom, usually abbreviated MSE.

  If there are fewer than numberOfParameters + 1 data pairs in the model, or if there is no variation in `x`, this returns `Double.NaN`.

  Returns:
    sum of squared deviations of y values

### getRSquared

    public double getRSquared()

  Returns the coefficient of multiple determination, usually denoted r-square.

  Preconditions:

  - At least numberOfParameters observations (with at least numberOfParameters different x values) must have been added before invoking this method. If this method is invoked before a model can be estimated, `Double,NaN` is returned.

  Returns:
    r-square, a double in the interval [0, 1]

### getAdjustedRSquared

    public double getAdjustedRSquared()

  Returns the adjusted R-squared statistic, defined by the formula

       R2adj = 1 - [SSR (n - 1)] / [SSTO (n - p)]

  where SSR is the sum of squared residuals}, SSTO is the total sum of squares}, n is the number of observations and p is the number of parameters estimated (including the intercept).

  If the regression is estimated without an intercept term, what is returned is

        1 - (1 - getRSquared() ) * (n / (n - p))

  Returns:
    adjusted R-Squared statistic

### hasIntercept

    public boolean hasIntercept()

  Returns true if the regression model has been computed including an intercept. In this case, the coefficient of the intercept is the first element of the `parameter estimates`.

  Returns:
    true if the model has an intercept term

### getVcvElement

    private double getVcvElement(int i,
                                 int j)

  Gets the i-jth element of the variance-covariance matrix.

  Parameters:
    `i` - first variable index
    `j` - second variable index
  Returns:
    the requested variance-covariance matrix entry

Copyright (c) 2003-2013 Apache Software Foundation