leverages {india}R Documentation

Leverages

Description

Computes leverage measures from a fitted model object.

Usage

  leverages(model, ...)
  ## S3 method for class 'lm'
leverages(model, infl = lm.influence(model, do.coef = FALSE), ...)
  ## S3 method for class 'ols'
leverages(model, ...)
  ## S3 method for class 'ridge'
leverages(model, ...)

  ## S3 method for class 'ols'
hatvalues(model, ...)
  ## S3 method for class 'ridge'
hatvalues(model, ...)

Arguments

model

an R object, returned by lm, ols or ridge.

infl

influence structure as returned by lm.influence.

...

further arguments passed to or from other methods.

Value

A vector containing the diagonal of the prediction (or ‘hat’) matrix.

For linear regression (i.e., for "lm" or "ols" objects) the prediction matrix assumes the form

\bold{H} = \bold{X}(\bold{X}^T\bold{X})^{-1}\bold{X}^T,

in which case, h_{ii} = \bold{x}_i^T(\bold{X}^T\bold{X})^{-1}\bold{x}_i for i=1,\dots,n. Whereas for ridge regression, the prediction matrix is given by

\bold{H}(\lambda) = \bold{X}(\bold{X}^T\bold{X} + \lambda\bold{I})^{-1}\bold{X}^T,

where \lambda represents the ridge parameter. Thus, the diagonal elements of \bold{H}(\lambda), are h_{ii}(\lambda) = \bold{x}_i^T(\bold{X}^T\bold{X} + \lambda\bm{I})^{-1}\bold{x}_i, i=1,\dots,n.

Note

This function never creates the prediction matrix and only obtains its diagonal elements from the singular value decomposition of \bold{X}.

Function hatvalues only is a wrapper for function leverages.

References

Chatterjee, S., Hadi, A.S. (1988). Sensivity Analysis in Linear Regression. Wiley, New York.

Cook, R.D., Weisberg, S. (1982). Residuals and Influence in Regression. Chapman and Hall, London.

Walker, E., Birch, J.B. (1988). Influence measures in ridge regression. Technometrics 30, 221-227. doi:10.1080/00401706.1988.10488370.

Examples

# Leverages for linear regression
fm <- ols(stack.loss ~ ., data = stackloss)
lev <- leverages(fm)
cutoff <- 2 * mean(lev)
plot(lev, ylab = "Leverages", ylim = c(0,0.45))
abline(h = cutoff, lty = 2, lwd = 2, col = "red")
text(17, lev[17], label = as.character(17), pos = 3)

# Leverages for ridge regression
data(portland)
fm <- ridge(y ~ ., data = portland)
lev <- leverages(fm)
cutoff <- 2 * mean(lev)
plot(lev, ylab = "Leverages", ylim = c(0,0.7))
abline(h = cutoff, lty = 2, lwd = 2, col = "red")
text(10, lev[10], label = as.character(10), pos = 3)

[Package india version 0.1 Index]