public class LeastSquare_Regression
extends java.lang.Object
This class will perform Linear Least square regression with focus on providing all the common regression statistics like T-stats, Anova and so on.
In Linear OLS Regression as an optimization problem we are trying to minimize the sum of squared difference between the real value the prediction of a Y value when we know a number of other characteristics or predictors labeled as x. This deviation (real value-prediction) is also called residual . The equation we are trying to minimize is :
Min(f)=Ó(Yi-yi)2 Where Y is the real value of the variable we are trying to predict and y is the prediction
The coefficients (or beta) for t for the predictors x that minimize this equation are computed as:
Beta(b)=(XTX)-1XTY Where X is the matrix of predictors, XTthe matrix of predictors' transposed and Y the single array of the real valuesLai, T.L.; Robbins,H; Wei, C.Z. (1978).
| Constructor and Description |
|---|
LeastSquare_Regression() |
| Modifier and Type | Method and Description |
|---|---|
double[] |
get_Betas_only(double[][] X,
double[] Y,
boolean addconstant)
This method will compute the beta and it should be chosen when there is no interest for any other
of the stats provided in this class (e.g.
|
double |
getadjRSquared() |
double[] |
getBetas() |
double |
getDW() |
double |
getFStatistic() |
double |
getFStatisticPvalue() |
double |
getPC() |
double[] |
getPredictedValues() |
double |
getR() |
double |
getRegDegreesFreedom() |
double |
getRegMeanSquares() |
double |
getRegSumSquares() |
double |
getResiDegreesFreedom() |
double[] |
getResiduals() |
double |
getResiMeanSquares() |
double |
getResiSumSquares() |
double |
getRSquared() |
double |
getSBC() |
double |
getSE() |
double[] |
getStandardErrors() |
double |
getTotalDegreesFreedom() |
double |
getTotalSumSquares() |
double[] |
getTstatistics() |
double[] |
getTstatisticsPvalues() |
void |
regression(double[][] X,
double[] Y)
A default constructor for regression where the intercept (constant) is assumed to be included.
|
void |
regression(double[][] X,
double[] Y,
boolean addconstant)
This the main method of this class that will compute the most
important OLS regression statistics such as the :
Beta
Anova
R and R-Squared
T-statistics for the predictors
Beat standard errors
T Pvalues and more
|
double[] |
score(double[][] X,
double[] beta,
boolean Constant)
The purpose of this method is to score a new set of variables where all the data is provided
|
void |
setDefaultContant(boolean con)
Method to change the default when setting a constant
|
public void regression(double[][] X,
double[] Y)
A default constructor for regression where the intercept (constant) is assumed to be included. It computes the most important OLS regression statistics such as the :
X - : The set of predictors (independent variables) in [rows][columns] formatY - : The array of the dependent variable (the one we are trying to predict).public void regression(double[][] X,
double[] Y,
boolean addconstant)
This the main method of this class that will compute the most important OLS regression statistics such as the :
X - : The set of predictors (independent variables) in [rows][columns] formatY - : The array of the dependent variable (the one we are trying to predict).addconstant - : when addconstant is true, we add a constant which is also the defaultpublic double[] get_Betas_only(double[][] X,
double[] Y,
boolean addconstant)
This method will compute the beta and it should be chosen when there is no interest for any other of the stats provided in this class (e.g. R squared), but the betas.
X - : The set of predictors (independent variables) in [rows][columns] formatY - : The array of the dependent variable (the one we are trying to predict).addconstant - : when addconstant is true, we add a constant which is also the defaultpublic double[] score(double[][] X,
double[] beta,
boolean Constant)
The purpose of this method is to score a new set of variables where all the data is provided
X - : The set of predictors (independent variables) in [rows][columns] formatbeta - : the beta (double array) to be applied.Constant - : an indication on whether there is a constant (in location 0-beta[0]) or notpublic void setDefaultContant(boolean con)
Method to change the default when setting a constant
con - When true the contant is addedpublic double[] getBetas()
public double getFStatistic()
public double getFStatisticPvalue()
public double getRegSumSquares()
public double getResiSumSquares()
public double getTotalSumSquares()
public double getRegMeanSquares()
public double getResiMeanSquares()
public double getRegDegreesFreedom()
public double getResiDegreesFreedom()
public double getTotalDegreesFreedom()
public double getDW()
public double getR()
public double getRSquared()
public double getadjRSquared()
public double getSE()
public double getPC()
public double getSBC()
public double[] getTstatistics()
public double[] getTstatisticsPvalues()
public double[] getStandardErrors()
public double[] getResiduals()
public double[] getPredictedValues()