Calculates leverage, that is, how far away the regressor values of an observation are from those of the other observations using $$ h_{ii} = x_{i}^{T} \left( \mathbf{X}^{T} \mathbf{X} \right)^{-1} x_{i} $$ where \(x_{i}^{T}\) is the \(i\)th row of the \(\mathbf{X}\) matrix. Note that \( \mathbf{X} \left( \mathbf{X}^{T} \mathbf{X} \right)^{-1} \mathbf{X}^{T} \) is the projection matrix (or hat matrix) \(\mathbf{P}\) and \(h_{ii}\) is the diagonal of \(\mathbf{P}\).

h(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 leverage.

References

Wikipedia: Leverage

See also

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

Author

Ivan Jacob Agaloos Pesigan

Examples

# Simple regression------------------------------------------------ X <- jeksterslabRdatarepo::wages.matrix[["X"]] X <- X[, c(1, ncol(X))] h <- h(X = X) hist(h)
# Multiple regression---------------------------------------------- X <- jeksterslabRdatarepo::wages.matrix[["X"]] # age is removed X <- X[, -ncol(X)] h <- h(X = X) hist(h)