zhatvalues | R Documentation |
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. \loadmathjax
zhatvalues(model, full = FALSE, ...)
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. |
For unweighted least-squares fits the hat matrix is calculated from the model matrix, X =
model$x
, as
\mjdeqnH = X (X^t X)^-1 X^tH = X (X^t X)^-1 X^t
For rlm or weighted least-squares fits the hat matrix is calculated as
\mjdeqnH = X (X^t W X)^-1 X^t WH = 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
.
Either a (n x n)
complex matrix or a length n
numeric vector.
stats::hatvalues, stats::hat, cooks.distance
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.