Calculates the residual maker matrix \(\left( \mathbf{M} \right)\) using $$ \mathbf{M} = \mathbf{I} - \mathbf{P} $$ where $$ \mathbf{P} = \mathbf{X} \left( \mathbf{X}^{T} \mathbf{X} \right)^{-1} \mathbf{X}^{T} . $$ The residual maker matrix \(\left( \mathbf{M} \right)\) transforms the \(\mathbf{y}\) vector to the vector of residuals \(\left( \mathbf{e} = \mathbf{My} \right)\) .

M(X)

Arguments

X

n by k numeric matrix. The data matrix \(\mathbf{X}\) (also known as design matrix, model matrix or regressor matrix) is an \(n \times k\) matrix of \(n\) observations of \(k\) regressors, which includes a regressor whose value is 1 for each observation on the first column.

Value

Returns the residual maker matrix \(\left( \mathbf{M} \right)\) .

References

Wikipedia: Projection Matrix

See also

Other projection matrix functions: .M(), .h(), P(), h()

Author

Ivan Jacob Agaloos Pesigan

Examples

# Simple regression------------------------------------------------ X <- jeksterslabRdatarepo::wages.matrix[["X"]] X <- X[, c(1, ncol(X))] M <- M(X = X) str(M, list.len = 6)
#> num [1:1289, 1:1289] 0.999224 -0.00077 -0.000775 -0.000783 -0.000777 ...
# Multiple regression---------------------------------------------- X <- jeksterslabRdatarepo::wages.matrix[["X"]] # age is removed X <- X[, -ncol(X)] M <- M(X = X) str(M, list.len = 6)
#> num [1:1289, 1:1289] 9.98e-01 -6.81e-04 5.85e-05 1.41e-03 -4.75e-04 ...