public class LinearRegression
extends java.lang.Object
LinearRegression
class performs a simple linear regression
on an set of n data points (yi, xi).
That is, it fits a straight line y = α + β x,
(where y is the response variable, x is the predictor variable,
α is the y-intercept, and β is the slope)
that minimizes the sum of squared residuals of the linear regression model.
It also computes associated statistics, including the coefficient of
determination R2 and the standard deviation of the
estimates for the slope and y-intercept.Modifier and Type | Field and Description |
---|---|
private double |
intercept |
private double |
r2 |
private double |
slope |
private double |
svar0 |
private double |
svar1 |
Constructor and Description |
---|
LinearRegression(double[] x,
double[] y)
Performs a linear regression on the data points
(y[i], x[i]) . |
Modifier and Type | Method and Description |
---|---|
double |
intercept()
Returns the y-intercept α of the best of the best-fit line y = α + β x.
|
double |
interceptStdErr()
Returns the standard error of the estimate for the intercept.
|
double |
predict(double x)
Returns the expected response
y given the value of the predictor
variable x . |
double |
R2()
Returns the coefficient of determination R2.
|
double |
slope()
Returns the slope β of the best of the best-fit line y = α + β x.
|
double |
slopeStdErr()
Returns the standard error of the estimate for the slope.
|
java.lang.String |
toString()
Returns a string representation of the simple linear regression model.
|
private final double intercept
private final double slope
private final double r2
private final double svar0
private final double svar1
public LinearRegression(double[] x, double[] y)
(y[i], x[i])
.x
- the values of the predictor variabley
- the corresponding values of the response variablejava.lang.IllegalArgumentException
- if the lengths of the two arrays are not equalpublic double intercept()
public double slope()
public double R2()
public double interceptStdErr()
public double slopeStdErr()
public double predict(double x)
y
given the value of the predictor
variable x
.x
- the value of the predictor variabley
given the value of the predictor
variable x
public java.lang.String toString()
toString
in class java.lang.Object