y = intercept + slope * x
Standard errors for intercept and slope are
available as well as ANOVA, r-square and Pearson's r statistics.
Observations (x,y pairs) can be added to the model one at a time or they can be provided in a 2-dimensional array. The observations are not stored in memory, so there is no limit to the number of observations that can be added to the model.
Usage Notes:
NaN. At least two observations with
different x coordinates are required to estimate a bivariate regression
model.
false to
the SimpleRegression(boolean) constructor. When the
hasIntercept property is false, the model is estimated without a
constant term and getIntercept() returns 0.| Modifier and Type | Field and Description |
|---|---|
| private final boolean | hasIntercept
include an intercept or not |
| private long | n
number of observations |
| private static final long | serialVersionUID
Serializable version identifier |
| private double | sumX
sum of x values |
| private double | sumXX
total variation in x (sum of squared deviations from xbar) |
| private double | sumXY
sum of products |
| private double | sumY
sum of y values |
| private double | sumYY
total variation in y (sum of squared deviations from ybar) |
| private double | xbar
mean of accumulated x values, used in updating formulas |
| private double | ybar
mean of accumulated y values, used in updating formulas |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SimpleRegression(boolean
whether or not to include an intercept term in
the regression model includeIntercept)Create a SimpleRegression instance, specifying whether or not to estimate an intercept. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addData(final double
independent variable value x, final double dependent variable value y)Adds the observation (x,y) to the regression data set. |
| public void | addData(final double[][]
array of observations to be added data)Adds the observations represented by the elements in
|
| public void | addObservation(final double[]
the independent variables which form the design matrix x, final double the dependent or response variable y)Implements org. Adds one observation to the regression model. |
| public void | addObservations(final double[][]
a series of observations on the independent variables x, final double[] a series of observations on the dependent variable
The length of x and y must be the same y)Implements org. Adds a series of observations to the regression model. |
| public void | append(SimpleRegression
model to append data from reg)Appends data from another regression calculation to this one. |
| public void | clear()
Implements org. Clears all data from the model. |
| public double | Returns: the intercept of the regression line if the model includes an intercept; 0 otherwiseReturns the intercept of the estimated regression line, if
|
| private double | Returns: the intercept of the regression linecurrent slope slope)Returns the intercept of the estimated regression line, given the slope. |
| public double | Returns: standard error associated with intercept estimateReturns the standard error of the intercept estimate, usually denoted s(b0). |
| public double | Returns: sum of squared deviations of y valuesReturns the sum of squared errors divided by the degrees of freedom, usually abbreviated MSE. |
| public long | Returns: n number of observations that have been added.Implements org. Returns the number of observations that have been added to the model. |
| public double | Returns: Pearson's rReturns Pearson's product moment correlation coefficient, usually denoted r. Preconditions:
|
| public double | Returns: sum of squared deviations of predicted y valuesReturns the sum of squared deviations of the predicted y values about their mean (which equals the mean of y). |
| private double | Returns: sum of squared deviations of predicted y valuesregression slope estimate slope)Computes SSR from b1. |
| public double | |
| public double | Returns: significance level for slope/correlationReturns the significance level of the slope (equiv) correlation. |
| public double | Returns: the slope of the regression lineReturns the slope of the estimated regression line. |
| public double | Returns: half-width of 95% confidence interval for the slope estimateReturns the half-width of a 95% confidence interval for the slope estimate. |
| public double | Returns: half-width of 95% confidence interval for the slope estimatethe desired significance level alpha)Returns the half-width of a (100-100*alpha)% confidence interval for the slope estimate. |
| public double | Returns: standard error associated with slope estimateReturns the standard error of the slope estimate, usually denoted s(b1). |
| public double | |
| public double | Returns: sum of squared errors associated with the regression modelReturns the sum of squared errors (SSE) associated with the regression model. |
| public double | Returns: sum of squared deviations of y valuesReturns the sum of squared deviations of the y values about their mean. |
| public double | Returns: sum of squared deviations of x valuesReturns the sum of squared deviations of the x values about their mean. |
| public boolean | Returns: true if the regression includes an intercept; false otherwiseImplements org. Returns true if the model includes an intercept term. |
| public double | Returns: predictedy valueinput x)x valueReturns the "predicted" |
| public RegressionResults | Returns: RegressionResults acts as a container of regression outputImplements org. Performs a regression on data present in buffers and outputs a RegressionResults object. |
| public RegressionResults | Returns: RegressionResults acts as a container of regression outputan array of indices of regressors to include variablesToInclude)Implements org. Performs a regression on data present in buffers including only regressors indexed in variablesToInclude and outputs a RegressionResults object |
| public void | removeData(final double
independent variable value x, final double dependent variable value y)Removes the observation (x,y) from the regression data set. |
| public void | removeData(double[][]
array of observations to be removed data)Removes observations represented by the elements in |
| hasIntercept | back to summary |
|---|---|
| private final boolean hasIntercept include an intercept or not | |
| n | back to summary |
|---|---|
| private long n number of observations | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serializable version identifier | |
| sumX | back to summary |
|---|---|
| private double sumX sum of x values | |
| sumXX | back to summary |
|---|---|
| private double sumXX total variation in x (sum of squared deviations from xbar) | |
| sumXY | back to summary |
|---|---|
| private double sumXY sum of products | |
| sumY | back to summary |
|---|---|
| private double sumY sum of y values | |
| sumYY | back to summary |
|---|---|
| private double sumYY total variation in y (sum of squared deviations from ybar) | |
| xbar | back to summary |
|---|---|
| private double xbar mean of accumulated x values, used in updating formulas | |
| ybar | back to summary |
|---|---|
| private double ybar mean of accumulated y values, used in updating formulas | |
| SimpleRegression | back to summary |
|---|---|
| public SimpleRegression() Create an empty SimpleRegression instance | |
| SimpleRegression | back to summary |
|---|---|
| public SimpleRegression(boolean includeIntercept) Create a SimpleRegression instance, specifying whether or not to estimate an intercept. Use
| |
| addData | back to summary |
|---|---|
| public void addData(final double x, final double y) Adds the observation (x,y) to the regression data set. Uses updating formulas for means and sums of squares defined in "Algorithms for Computing the Sample Variance: Analysis and Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J. 1983, American Statistician, vol. 37, pp. 242-247, referenced in Weisberg, S. "Applied Linear Regression". 2nd Ed. 1985.
| |
| addData | back to summary |
|---|---|
| public void addData(final double[][] data) throws ModelSpecificationException Adds the observations represented by the elements in
This method does not replace data that has already been added. The
observations represented by
To replace all data, use
| |
| addObservation | back to summary |
|---|---|
| public void addObservation(final double[] x, final double y) throws ModelSpecificationException Implements org. Adds one observation to the regression model.
| |
| addObservations | back to summary |
|---|---|
| public void addObservations(final double[][] x, final double[] y) throws ModelSpecificationException Implements org. Adds a series of observations to the regression model. The lengths of x and y must be the same and x must be rectangular.
| |
| append | back to summary |
|---|---|
| public void append(SimpleRegression reg) Appends data from another regression calculation to this one. The mean update formulae are based on a paper written by Philippe Pébay: Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments, 2008, Technical Report SAND2008-6212, Sandia National Laboratories.
| |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Clears all data from the model. | |
| getIntercept | back to summary |
|---|---|
| public double getIntercept() Returns the intercept of the estimated regression line, if
The least squares estimate of the intercept is computed using the normal equations. The intercept is sometimes denoted b0. Preconditions:
| |
| getIntercept | back to summary |
|---|---|
| private double getIntercept(final double slope) Returns the intercept of the estimated regression line, given the slope.
Will return
| |
| getInterceptStdErr | back to summary |
|---|---|
| public double getInterceptStdErr() Returns the standard error of the intercept estimate, usually denoted s(b0).
If there are fewer that three observations in the
model, or if there is no variation in x, this returns
Double.NaN is
returned when the intercept is constrained to be zero
| |
| getMeanSquareError | back to summary |
|---|---|
| public double getMeanSquareError() Returns the sum of squared errors divided by the degrees of freedom, usually abbreviated MSE.
If there are fewer than three data pairs in the model,
or if there is no variation in
| |
| getN | back to summary |
|---|---|
| public long getN() Implements org. Returns the number of observations that have been added to the model.
| |
| getR | back to summary |
|---|---|
| public double getR() Returns Pearson's product moment correlation coefficient, usually denoted r. Preconditions:
| |
| getRegressionSumSquares | back to summary |
|---|---|
| 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:
| |
| getRegressionSumSquares | back to summary |
|---|---|
| private double getRegressionSumSquares(final double slope) Computes SSR from b1.
| |
| getRSquare | back to summary |
|---|---|
| public double getRSquare() Returns the coefficient of determination, usually denoted r-square. Preconditions:
| |
| getSignificance | back to summary |
|---|---|
| public double getSignificance() Returns the significance level of the slope (equiv) correlation.
Specifically, the returned value is the smallest
Usage Note:
If there are fewer that three observations in the
model, or if there is no variation in x, this returns
| |
| getSlope | back to summary |
|---|---|
| public double getSlope() Returns the slope of the estimated regression line. The least squares estimate of the slope is computed using the normal equations. The slope is sometimes denoted b1. Preconditions:
| |
| getSlopeConfidenceInterval | back to summary |
|---|---|
| public double getSlopeConfidenceInterval() throws OutOfRangeException Returns the half-width of a 95% confidence interval for the slope estimate. The 95% confidence interval is
If there are fewer that three observations in the
model, or if there is no variation in x, this returns
Usage Note:
| |
| getSlopeConfidenceInterval | back to summary |
|---|---|
| public double getSlopeConfidenceInterval(final double alpha) throws OutOfRangeException Returns the half-width of a (100-100*alpha)% confidence interval for the slope estimate. The (100-100*alpha)% confidence interval is
To request, for example, a 99% confidence interval, use
Usage Note: Preconditions:
| |
| getSlopeStdErr | back to summary |
|---|---|
| public double getSlopeStdErr() Returns the standard error of the slope estimate, usually denoted s(b1).
If there are fewer that three data pairs in the model,
or if there is no variation in x, this returns
| |
| getSumOfCrossProducts | back to summary |
|---|---|
| public double getSumOfCrossProducts() Returns the sum of crossproducts, xi*yi.
| |
| getSumSquaredErrors | back to summary |
|---|---|
| public double getSumSquaredErrors() Returns the sum of squared errors (SSE) associated with the regression model. The sum is computed using the computational formula
where
The sums are accumulated using the updating algorithm referenced in
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:
| |
| getTotalSumSquares | back to summary |
|---|---|
| public double getTotalSumSquares() Returns the sum of squared deviations of the y values about their mean. This is defined as SSTO here.
If
| |
| getXSumSquares | back to summary |
|---|---|
| public double getXSumSquares() Returns the sum of squared deviations of the x values about their mean.
If
| |
| hasIntercept | back to summary |
|---|---|
| public boolean hasIntercept() Implements org. Returns true if the model includes an intercept term.
| |
| predict | back to summary |
|---|---|
| public double predict(final double x) Returns the "predicted"
Preconditions:
| |
| regress | back to summary |
|---|---|
| public RegressionResults regress() throws ModelSpecificationException, NoDataException Implements org. Performs a regression on data present in buffers and outputs a RegressionResults object. If there are fewer than 3 observations in the model and
| |
| regress | back to summary |
|---|---|
| public RegressionResults regress(int[] variablesToInclude) throws MathIllegalArgumentException Implements org. Performs a regression on data present in buffers including only regressors indexed in variablesToInclude and outputs a RegressionResults object
| |
| removeData | back to summary |
|---|---|
| public void removeData(final double x, final double y) Removes the observation (x,y) from the regression data set. Mirrors the addData method. This method permits the use of SimpleRegression instances in streaming mode where the regression is applied to a sliding "window" of observations, however the caller is responsible for maintaining the set of observations in the window. The method has no effect if there are no points of data (i.e. n=0)
| |
| removeData | back to summary |
|---|---|
| public void removeData(double[][] data) Removes observations represented by the elements in If the array is larger than the current n, only the first n elements are processed. This method permits the use of SimpleRegression instances in streaming mode where the regression is applied to a sliding "window" of observations, however the caller is responsible for maintaining the set of observations in the window.
To remove all data, use
| |