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)
X |
|
---|
Returns the projection matrix \(\left( \mathbf{P} \right)\).
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)\).
Ivan Jacob Agaloos Pesigan
# 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 ...