|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.stat.BivariateRegression
Estimates an ordinary least squares regression model with one independent variable.
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 requred to estimate a bivariate regression
model.
Constructor Summary | |
BivariateRegression()
|
Method Summary | |
void |
addData(double[][] data)
Adds the observations represented by the elements in data . |
void |
addData(double x,
double y)
Adds the observation (x,y) to the regression data set. |
void |
clear()
Clears all data from the model. |
double |
getIntercept()
Returns the intercept of the estimated regression line. |
double |
getInterceptStdErr()
Returns the standard error of the intercept estimate, usually denoted s(b0). |
double |
getMeanSquareError()
Returns the sum of squared errors divided by the degrees of freedom, usually abbreviated MSE. |
long |
getN()
Returns the number of observations that have been added to the model. |
double |
getR()
Returns Pearson's product moment correlation coefficient, usually denoted r. |
double |
getRegressionSumSquares()
Returns the sum of squared deviations of the predicted y values about their mean (which equals the mean of y). |
double |
getRSquare()
Returns the coefficient of determination, usually denoted r-square. |
double |
getSignificance()
Returns the significance level of the slope (equiv) correlation. |
double |
getSlope()
Returns the slope of the estimated regression line. |
double |
getSlopeConfidenceInterval()
Returns the half-width of a 95% confidence interval for the slope estimate. |
double |
getSlopeConfidenceInterval(double alpha)
Returns the half-width of a (100-100*alpha)% confidence interval for the slope estimate. |
double |
getSlopeStdErr()
Returns the standard error of the slope estimate, usually denoted s(b1). |
double |
getSumSquaredErrors()
Returns the sum of squared errors (SSE) associated with the regression model. |
double |
getTotalSumSquares()
Returns the sum of squared deviations of the y values about their mean. |
double |
predict(double x)
Returns the "predicted" y value associated with the
supplied x value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public BivariateRegression()
Method Detail |
public void addData(double x, double y)
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
x
- independent variable valuey
- dependent variable valuepublic void addData(double[][] data)
data
.
(data[0][0],data[0][1])
will be the first observation, then
(data[1][0],data[1][1])
, etc.
This method does not replace data that has already been added.
To replace all data, use clear()
before adding the new
data.
data
- array of observations to be addedpublic void clear()
public long getN()
public double predict(double x)
y
value associated with the
supplied x
value.
predict(x) = intercept + slope * x
Preconditions:
Double,NaN
is
returned.
x
- input x
value
y
valuepublic double getIntercept()
The least squares estimate of the intercept is computed using the normal equations. The intercept is sometimes denoted b0.
Preconditions:
Double,NaN
is
returned.
public double getSlope()
The least squares estimate of the slope is computed using the normal equations. The slope is sometimes denoted b1.
Preconditions:
Double.NaN
is
returned.
public double getSumSquaredErrors()
Preconditions:
Double,NaN
is
returned.
public double getTotalSumSquares()
This is defined as SSTO here.
If n < 2
, this returns Double.NaN
.
public double getRegressionSumSquares()
This is usually abbreviated SSR or SSM. It is defined as SSM here
Preconditions:
Double,NaN
is
returned.
public double getMeanSquareError()
If there are fewer than three data pairs in the model,
or if there is no variation in x
, this returns
Double.NaN
.
public double getR()
Preconditions:
Double,NaN
is
returned.
public double getRSquare()
Preconditions:
Double,NaN
is
returned.
public double getInterceptStdErr()
If there are fewer that three observations in the
model, or if there is no variation in x, this returns
Double.NaN
.
public double getSlopeStdErr()
If there are fewer that three data pairs in the model,
or if there is no variation in x, this returns Double.NaN
.
public double getSlopeConfidenceInterval() throws MathException
The 95% confidence interval is
(getSlope() - getSlopeConfidenceInterval(),
getSlope() + getSlopeConfidenceInterval())
If there are fewer that three observations in the
model, or if there is no variation in x, this returns
Double.NaN
.
Usage Note:
The validity of this statistic depends on the assumption that the
observations included in the model are drawn from a
Bivariate Normal Distribution.
MathException
public double getSlopeConfidenceInterval(double alpha) throws MathException
The (100-100*alpha)% confidence interval is
(getSlope() - getSlopeConfidenceInterval(),
getSlope() + getSlopeConfidenceInterval())
To request, for example, a 99% confidence interval, use
alpha = .01
Usage Note:
The validity of this statistic depends on the assumption that the
observations included in the model are drawn from a
Bivariate Normal Distribution.
Preconditions:
Double.NaN
.
(0 < alpha < 1)
; otherwise an
IllegalArgumentException
is thrown.
alpha
- the desired significance level
MathException
public double getSignificance() throws MathException
Specifically, the returned value is the smallest alpha
such that the slope confidence interval with significance level
equal to alpha
does not include 0
.
On regression output, this is often denoted Prob(|t| > 0)
Usage Note:
The validity of this statistic depends on the assumption that the
observations included in the model are drawn from a
Bivariate Normal Distribution.
If there are fewer that three observations in the
model, or if there is no variation in x, this returns
Double.NaN
.
MathException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |