Package dev.nm.stat.regression.linear
Class LMProblem
- java.lang.Object
-
- dev.nm.stat.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.- See Also:
- Wikipedia: Linear regression
-
-
Constructor Summary
Constructors Constructor Description LMProblem(Vector y, Matrix X)
Constructs a linear regression problem, assuming a constant term (the intercept) equal weights assigned to all observationsLMProblem(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).LMProblem(LMProblem that)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableMatrix
A()
Gets the regressor matrix.protected void
checkInputs()
Checks whether thisLMProblem
instance is valid.boolean
intercept()
Checks if an intercept term is added to the linear regression.ImmutableMatrix
invOfwAtwA()
(wA' * wA)-1int
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.
-
-
-
Constructor Detail
-
LMProblem
public LMProblem(Vector y, Matrix X, boolean intercept, Vector weights)
Constructs a linear regression problem.- Parameters:
y
- the dependent variablesX
- the factorsintercept
-true
if to additionally add an intercept term to the linear regressionweights
- 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 variablesX
- the factorsweights
- 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 variablesX
- the factorsintercept
-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 variablesX
- the factors
-
LMProblem
public LMProblem(LMProblem that)
Copy constructor.- Parameters:
that
- anotherLMProblem
-
-
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 thisLMProblem
instance is valid.- Throws:
IllegalArgumentException
- if this problem is invalid
-
-