zhatvalues function

Generate the Hat Matrix or Leverage Scores of a Complex Linear Model

Generate the Hat Matrix or Leverage Scores of a Complex Linear Model

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.

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.

Returns

Either a (nxn)(n x n) complex matrix or a length nn numeric vector.

Details

For unweighted least-squares fits the hat matrix is calculated from the model matrix, X=X = model$x, as

For rlm or weighted least-squares fits the hat matrix is calculated as

Where t^t represents conjugate transpose, and WW 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.

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)

See Also

stats::hatvalues , stats::hat , cooks.distance