public class LinearRegression
extends java.lang.Object
implements java.lang.Runnable
Table
).Table
,
PlotWindow.PlotType
,
PlotWindow
Modifier and Type | Field and Description |
---|---|
static int |
INTERCEPT_INDEX
Index of intercept in result of
toArray() . |
static int |
MSE_INDEX
Index of mean squared error (mse) in result of
toArray() . |
static int |
R_INDEX
Index of Pearson's r in result of
toArray() . |
static int |
SLOPE_INDEX
Index of slope in result of
toArray() . |
Constructor and Description |
---|
LinearRegression(double[] theXColumn,
double[] theYColumn,
boolean calculateMSE)
Creates a
LinearRegression . |
Modifier and Type | Method and Description |
---|---|
boolean |
getCalculateMSE()
Returns whether the mean squared error (mse) will be
calculated.
|
double |
getIntercept()
Return the intercept for the
LinearRegression . |
double |
getMSE()
Return the mean squared error (mse) for the
LinearRegression . |
double |
getR()
Return the correlation as calculated by Pearson's r for the
LinearRegression . |
double |
getSlope()
Return the slope for the
LinearRegression . |
boolean |
isCalculated()
Return whether the result for this
LinearRegression has
been calculated. |
void |
run() |
LinearRegression |
setCalculateMSE(boolean theSetting)
Sets whether the mean squared error will be calculated.
|
double[] |
toArray()
Returns an array containing the slope, intercept,
Pearson's r and mean squared error that are
calculated for the
LinearRegression . |
java.lang.String |
toString()
Returns the
String representation of the
LinearRegression . |
public static final int SLOPE_INDEX
toArray()
.public static final int INTERCEPT_INDEX
toArray()
.public static final int R_INDEX
toArray()
.public static final int MSE_INDEX
toArray()
.public LinearRegression(double[] theXColumn, double[] theYColumn, boolean calculateMSE)
LinearRegression
.
theXColumn
- The x-column.theYColumn
- The y-column.calculateMSE
- boolean
that controls whether the
mean squared error will be calculated.public LinearRegression setCalculateMSE(boolean theSetting)
Note the default is to calculate the mean squared error.
theSetting
- The setting.LinearRegression
the method was called on.public boolean getCalculateMSE()
true
iff the mse will be
calculated, false
otherwise.public boolean isCalculated()
LinearRegression
has
been calculated.
This means the run()
method has been called on this
LinearRegression
, and the calculation has finished.
true
iff the calculation has finished,
false
otherwise.run()
public double getSlope()
LinearRegression
.
Note returns NaN
if the slope is not calculated
yet, and when an error occurred during the calculation.
double
that represents the slope.isCalculated()
public double getIntercept()
LinearRegression
.
Note returns NaN
if the intercept is not
calculated yet, and when an error occurred during the calculation.
double
that represents the intercept
.isCalculated()
public double getR()
LinearRegression
.
Note returns -1.0
if the r is not
calculated yet, and NaN
when an error occurred during
the calculation.
double
that represents the r.isCalculated()
public double getMSE()
LinearRegression
.
Note returns -1.0
if the mse is not
calculated yet, and NaN
when an error occurred during
the calculation.
double
that represents the mse.isCalculated()
public double[] toArray()
LinearRegression
.
Note that the index of each of the different values is given by the
corresponding public static final int *_INDEX
member
variable of this class.
double[]
containing all calculated values.isCalculated()
public java.lang.String toString()
String
representation of the
LinearRegression
.
This is a formula of the form: y = a*x + b (r = ?, mse = ?).
toString
in class java.lang.Object
public void run()
run
in interface java.lang.Runnable