public abstract class AbstractMultipleLinearRegression extends Object implements MultipleLinearRegression
Constructor and Description |
---|
AbstractMultipleLinearRegression() |
Modifier and Type | Method and Description |
---|---|
protected abstract RealVector |
calculateBeta()
Calculates the beta of multiple linear regression in matrix notation.
|
protected abstract RealMatrix |
calculateBetaVariance()
Calculates the beta variance of multiple linear regression in matrix
notation.
|
protected double |
calculateErrorVariance()
Calculates the variance of the error term.
|
protected RealVector |
calculateResiduals()
Calculates the residuals of multiple linear regression in matrix
notation.
|
protected double |
calculateYVariance()
Calculates the variance of the y values.
|
double |
estimateErrorVariance()
Estimates the variance of the error.
|
double |
estimateRegressandVariance()
Returns the variance of the regressand, ie Var(y).
|
double[] |
estimateRegressionParameters()
Estimates the regression parameters b.
|
double[] |
estimateRegressionParametersStandardErrors()
Returns the standard errors of the regression parameters.
|
double[][] |
estimateRegressionParametersVariance()
Estimates the variance of the regression parameters, ie Var(b).
|
double |
estimateRegressionStandardError()
Estimates the standard error of the regression.
|
double[] |
estimateResiduals()
Estimates the residuals, ie u = y - X*b.
|
protected RealMatrix |
getX() |
protected RealVector |
getY() |
boolean |
isNoIntercept() |
void |
newSampleData(double[] data,
int nobs,
int nvars)
Loads model x and y sample data from a flat input array, overriding any previous sample.
|
protected void |
newXSampleData(double[][] x)
Loads new x sample data, overriding any previous data.
|
protected void |
newYSampleData(double[] y)
Loads new y sample data, overriding any previous data.
|
void |
setNoIntercept(boolean noInterceptIn) |
protected void |
validateCovarianceData(double[][] x,
double[][] covariance)
Validates that the x data and covariance matrix have the same
number of rows and that the covariance matrix is square.
|
protected void |
validateSampleData(double[][] x,
double[] y)
Validates sample data.
|
protected RealMatrix getX()
protected RealVector getY()
public boolean isNoIntercept()
public void setNoIntercept(boolean noInterceptIn)
noInterceptIn
- true means the model is to be estimated without an intercept termpublic void newSampleData(double[] data, int nobs, int nvars)
Loads model x and y sample data from a flat input array, overriding any previous sample.
Assumes that rows are concatenated with y values first in each row. For example, an input data
array
containing the sequence of values (1, 2, 3, 4, 5, 6, 7, 8, 9) with nobs = 3
and
nvars = 2
creates a regression dataset with two independent variables, as below:
y x[0] x[1] -------------- 1 2 3 4 5 6 7 8 9
Note that there is no need to add an initial unitary column (column of 1's) when specifying a model including an
intercept term. If isNoIntercept()
is true
, the X matrix will be created without an initial
column of "1"s; otherwise this column will be added.
Throws IllegalArgumentException if any of the following preconditions fail:
data
cannot be nulldata.length = nobs * (nvars + 1)
nobs > nvars
data
- input data arraynobs
- number of observations (rows)nvars
- number of independent variables (columns, not counting y)NullArgumentException
- if the data array is nullDimensionMismatchException
- if the length of the data array is not equal
to nobs * (nvars + 1)
NumberIsTooSmallException
- if nobs
is smaller than nvars
protected void newYSampleData(double[] y)
y
- the array representing the y sampleNullArgumentException
- if y is nullNoDataException
- if y is emptyprotected void newXSampleData(double[][] x)
Loads new x sample data, overriding any previous data.
The inputx
array should have one row for each sample
observation, with columns corresponding to independent variables.
For example, if
x = new double[][] {{1, 2}, {3, 4}, {5, 6}}
then setXSampleData(x)
results in a model with two independent
variables and 3 observations:
x[0] x[1] ---------- 1 2 3 4 5 6
Note that there is no need to add an initial unitary column (column of 1's) when specifying a model including an intercept term.
x
- the rectangular array representing the x sampleNullArgumentException
- if x is nullNoDataException
- if x is emptyDimensionMismatchException
- if x is not rectangularprotected void validateSampleData(double[][] x, double[] y)
x
- the [n,k] array representing the x datay
- the [n,1] array representing the y dataNullArgumentException
- if x
or y
is nullDimensionMismatchException
- if x
and y
do not
have the same lengthNoDataException
- if x
or y
are zero-lengthMathIllegalArgumentException
- if the number of rows of x
is not larger than the number of columns + 1protected void validateCovarianceData(double[][] x, double[][] covariance)
x
- the [n,k] array representing the x samplecovariance
- the [n,n] array representing the covariance matrixDimensionMismatchException
- if the number of rows in x is not equal
to the number of rows in covarianceNonSquareMatrixException
- if the covariance matrix is not squarepublic double[] estimateRegressionParameters()
estimateRegressionParameters
in interface MultipleLinearRegression
public double[] estimateResiduals()
estimateResiduals
in interface MultipleLinearRegression
public double[][] estimateRegressionParametersVariance()
estimateRegressionParametersVariance
in interface MultipleLinearRegression
public double[] estimateRegressionParametersStandardErrors()
estimateRegressionParametersStandardErrors
in interface MultipleLinearRegression
public double estimateRegressandVariance()
estimateRegressandVariance
in interface MultipleLinearRegression
public double estimateErrorVariance()
public double estimateRegressionStandardError()
protected abstract RealVector calculateBeta()
protected abstract RealMatrix calculateBetaVariance()
protected double calculateYVariance()
protected double calculateErrorVariance()
Calculates the variance of the error term.
Uses the formulavar(u) = u · u / (n - k)where n and k are the row and column dimensions of the design matrix X.
protected RealVector calculateResiduals()
u = y - X * b
Copyright © 2020 CNES. All rights reserved.