Calculates the projection matrix \(\left( \mathbf{P} \right)\) using $$ \mathbf{P} = \mathbf{X} \left( \mathbf{X}^{T} \mathbf{X} \right)^{-1} \mathbf{X}^{T} . $$

P(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 projection matrix \(\left( \mathbf{P} \right)\).

Details

The projection matrix \(\left( \mathbf{P} \right)\), also known as the hat matrix, transforms the \(\mathbf{y}\) vector to the vector of predicted values \(\left( \mathbf{\hat{y}} = \mathbf{Py} \right)\).

References

Wikipedia: Projection Matrix

See also

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

Author

Ivan Jacob Agaloos Pesigan

Examples

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