zhatvalues {complexlm} | R Documentation |
Generate the Hat Matrix or Leverage Scores of a Complex Linear Model
Description
This function returns either the full hat matrix (AKA the projection matrix) of a complex "lm" or "rlm" object, or the diagonal elements of same. The later are also known as the influence scores. It performs the same basic role as stats::hat and stats::hatvalues do for numeric fits, but is quite a bit simpler and rather less versatile.
Usage
zhatvalues(model, full = FALSE, ...)
Arguments
model |
A complex linear fit object, of class "zlm" or "rzlm". An object with numeric residuals will produce a warning and NULL output. |
full |
Logical. If TRUE, return the entire hat matrix. If FALSE, return a vector of the diagonal elements of the hat matrix. These are the influence scores. Default is FALSE. |
... |
Additional arguments. Not used. |
Details
For unweighted least-squares fits the hat matrix is calculated from the model matrix, X = model$x
, as
\[H = X (X^t X)^{-1} X^t\]
For rlm or weighted least-squares fits the hat matrix is calculated as
\[H = X (X^t W X)^{-1} X^t W\]
Where ^t represents conjugate transpose, and W is the identity matrix times the user provided weights and the final IWLS weights if present.
Note that this function requires that the model matrix be returned when calling lm or rlm.
The diagonals will be purely real, and are converted to numeric if full == FALSE
.
Value
Either a (n x n) complex matrix or a length n numeric vector.
See Also
stats::hatvalues, stats::hat, cooks.distance
Examples
set.seed(4242)
n <- 8
slop <- complex(real = 4.23, imaginary = 2.323)
interc <- complex(real = 1.4, imaginary = 1.804)
e <- complex(real=rnorm(n)/6, imaginary=rnorm(n)/6)
xx <- complex(real= rnorm(n), imaginary= rnorm(n))
tframe <- data.frame(x = xx, y= slop*xx + interc + e)
fit <- lm(y ~ x, data = tframe, weights = rep(1,n))
zhatvalues(fit)