# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.regression.linear

## Class LMProblem

• java.lang.Object
• com.numericalmethod.suanshu.stats.regression.linear.LMProblem
• Direct Known Subclasses:
ConstrainedLASSOProblem, GLMProblem, LARSProblem, LogisticProblem, UnconstrainedLASSOProblem

public class LMProblem
extends Object
This is a linear regression or a linear model (LM) problem. Linear regression models the relationship between a scalar variable y and one or more variables denoted as X. In linear regression, models of the unknown parameters are estimated from the data using linear functions. Most commonly, linear regression refers to a model in which the conditional mean of y given the value of y is an affine function of y.
Wikipedia: Linear regression
• ### Constructor Summary

Constructors
Constructor and Description
LMProblem(LMProblem that)
Copy constructor.
LMProblem(Vector y, Matrix X)
Constructs a linear regression problem, assuming a constant term (the intercept) equal weights assigned to all observations
LMProblem(Vector y, Matrix X, boolean intercept)
Constructs a linear regression problem, assuming equal weights to all observations.
LMProblem(Vector y, Matrix X, boolean intercept, Vector weights)
Constructs a linear regression problem.
LMProblem(Vector y, Matrix X, Vector weights)
Constructs a linear regression problem, assuming a constant term (the intercept).
• ### Method Summary

All Methods
Modifier and Type Method and Description
ImmutableMatrix A()
Gets the regressor matrix.
protected void checkInputs()
Checks whether this LMProblem instance is valid.
boolean intercept()
Checks if an intercept term is added to the linear regression.
ImmutableMatrix invOfwAtwA()
(wA' * wA)-1
int nExogenousFactors()
Gets the number of factors, excluding the intercept.
int nFactors()
Gets the number of factors, including the intercept if any.
int nObs()
Gets the number of observations.
ImmutableMatrix wA()
Gets the weighted regressor matrix.
ImmutableVector weights()
Gets the weights assigned to each observation.
ImmutableVector wy()
Gets the weighted response vector.
ImmutableMatrix X()
Gets the factor matrix.
ImmutableVector y()
Gets the response vector, the regressands, the dependent variables.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### LMProblem

public LMProblem(Vector y,
Matrix X,
boolean intercept,
Vector weights)
Constructs a linear regression problem.
Parameters:
y - the dependent variables
X - the factors
intercept - true if to additionally add an intercept term to the linear regression
weights - the weights assigned to each observation
• #### LMProblem

public LMProblem(Vector y,
Matrix X,
Vector weights)
Constructs a linear regression problem, assuming a constant term (the intercept).
Parameters:
y - the dependent variables
X - the factors
weights - the weights assigned to each observation
• #### LMProblem

public LMProblem(Vector y,
Matrix X,
boolean intercept)
Constructs a linear regression problem, assuming equal weights to all observations.
Parameters:
y - the dependent variables
X - the factors
intercept - true if to additionally add an intercept term to the linear regression
• #### LMProblem

public LMProblem(Vector y,
Matrix X)
Constructs a linear regression problem, assuming
• a constant term (the intercept)
• equal weights assigned to all observations
Parameters:
y - the dependent variables
X - the factors
• #### LMProblem

public LMProblem(LMProblem that)
Copy constructor.
Parameters:
that - another LMProblem
• ### Method Detail

• #### nObs

public int nObs()
Gets the number of observations.
Returns:
the number of observations
• #### nFactors

public int nFactors()
Gets the number of factors, including the intercept if any.
Returns:
the number of factors, including the intercept if any
• #### y

public ImmutableVector y()
Gets the response vector, the regressands, the dependent variables.
Returns:
the response vector
• #### wy

public ImmutableVector wy()
Gets the weighted response vector.
Returns:
the weighted response vector
• #### A

public ImmutableMatrix A()
Gets the regressor matrix.
Returns:
the regressor matrix
• #### wA

public ImmutableMatrix wA()
Gets the weighted regressor matrix.
Returns:
the weighted regressor matrix
• #### intercept

public boolean intercept()
Checks if an intercept term is added to the linear regression.
Returns:
true if an intercept term is added
• #### weights

public ImmutableVector weights()
Gets the weights assigned to each observation.
Returns:
the weights assigned to each observation
• #### nExogenousFactors

public int nExogenousFactors()
Gets the number of factors, excluding the intercept.
Returns:
the number of factors, excluding the intercept
• #### X

public ImmutableMatrix X()
Gets the factor matrix.

Note: the automatically appended intercept is not included.

Returns:
the factor matrix.
• #### invOfwAtwA

public ImmutableMatrix invOfwAtwA()
(wA' * wA)-1
Returns:
(wA' * wA)-1
• #### checkInputs

protected void checkInputs()
Checks whether this LMProblem instance is valid.
Throws:
IllegalArgumentException - if this problem is invalid