Solves the ordinary least-squares problem \(Y \approx X \beta\) for a
single design matrix X and one or more response columns Y.
Usage
lm_fit(
X,
Y,
intercept = FALSE,
include_fitted = TRUE,
include_residuals = TRUE,
cache = TRUE,
method = c("normal", "qr")
)Arguments
- X
Numeric matrix or
adgeMatrixof predictors, shape[n, p].- Y
Numeric matrix, vector, or
adgeMatrixof responses, shape[n, q].- intercept
Logical. When
TRUE, a column of ones is prepended toXbefore fitting.- include_fitted
Logical. When
TRUE, fitted values are included in the returned object.- include_residuals
Logical. When
TRUE, residuals are included in the returned object.- cache
Logical. When
TRUE, the \(X^T X\) or QR factorization is cached for reuse across calls sharing the sameX.- method
Solver method:
"normal"(normal equations, default) or"qr"(QR decomposition).
Value
An object of class "lm_fit", a named list containing:
- coefficients
adgeMatrixof shape[p, q].- fitted.values
adgeMatrixof shape[n, q], orNULLwheninclude_fitted = FALSE.- residuals
adgeMatrixof shape[n, q], orNULLwheninclude_residuals = FALSE.- rank
Integer model rank.
- df.residual
Residual degrees of freedom.