Class UserBasisRegression
Description
UserBasisRegression generalizes the concept of linear regression to user
defined basis functions. The linear regression model is
\(y = c_0 + c_1 x_1 + \cdots + c_k x_k + \varepsilon \),
where are the k independent variables. UserBasisRegression generalizes this
concept by setting \(x_i = f_i (x)\), where \(f_i (x)\)
is any user defined function of \(x\).
This makes it easier for users to fit complex univariate models. For
example, the LinearRegression class can be used to fit polynomials such as
\(y = c_0 + c_1 x + c_2 x^2 \cdots + c_k x^k + \varepsilon\),
but this requires an input matrix where the ith column of that array contains
the values of \(x^i\).
With UserBasisRegression, these columns can be automatically generated.
For this polynomial model, the user would define a user basis function
\(f_i (x) = x^{i + 1}\). The UserBasisRegression class
automatically inserts the necessary values into the regression equation and
then calculates the coefficients and analysis of variance statistics.
Since the user provides a method for calculating the basis function, other more
complex user basis functions are possible such as \(y = c_1 Sin(x) + c_2 Cos(x) + \varepsilon\).
In this example, nBasis=2, \(f_0 (x) = Sin(x)\), and
\(f_1 (x) = Cos(x)\).
-
Constructor Summary
ConstructorsConstructorDescriptionUserBasisRegression(RegressionBasis basis, int nBasis, boolean hasIntercept) Constructs aUserBasisRegressionobject -
Method Summary
-
Constructor Details
-
UserBasisRegression
Constructs aUserBasisRegressionobject- Parameters:
basis- aRegressionBasisbasis function supplied by the usernBasis- anintwhich specifies the number of basis functionshasIntercept- abooleanwhich specifies whether or not the model has an intercept
-
-
Method Details
-
update
public void update(double x, double y, double w) Adds a new observation and associated weight to theRegressionBasisobject.- Parameters:
x- adoublecontaining the independent (explanatory) variable.y- adoublecontaining the dependent (response) variable.w- adoublerepresenting the weight
-
getCoefficients
public double[] getCoefficients()Returns the regression coefficients.- Returns:
- A
doublearray containing the regression coefficients. If hasIntercept is false its length is equal to the number of variables. If hasIntercept is true then its length is the number of variables plus one and the 0-th entry is the value of the intercept. - Throws:
SingularMatrixException- is thrown when the regression matrix is singular.
-
getANOVA
Get an analysis of variance table and related statistics.- Returns:
- an
ANOVAtable and related statistics
-