leverage_plot {api2lm}R Documentation

Index plot of leverage values for lm object

Description

leverage_plot plots the leverage (hat) values from the hatvalues function of a fitted lm object.

Usage

leverage_plot(
  model,
  id_n = 3,
  add_reference = TRUE,
  ttype = "half",
  threshold = NULL,
  ...,
  text_arglist = list(),
  abline_arglist = list(),
  extendrange_f = 0.08
)

Arguments

model

A fitted model object from the lm function.

id_n

The number of points to identify with labels. The default is 3.

add_reference

A logical value indicating whether a reference line should be added. The default is TRUE.

ttype

Threshold type. The default is "half". The other options are "2mean" and "custom". See Details.

threshold

A number between 0 and 1. Any observation with a leverage value above this number is declared a leverage point. This is automatically determined unless ttype = "custom".

...

Additional arguments passed to the plot function.

text_arglist

Additional arguments passed to the text function, which is used to display the points that are identified.

abline_arglist

A named list specifying additional arguments passed to the abline function for the horizontal reference line added to the plot.

extendrange_f

Positive number(s) specifying the fraction by which the range of the residuals should be extended using the extendrange function. If longer than one, f[1] is used on the left and f[2] on the right.

Details

If ttype = "half", the threshold is 0.5.

If ttype = "2mean", the threshold is 2p/n, where p = length(stats::coef(model)) and n = stats::nobs(model), which is double the mean leverage value.

If ttype = "custom" then the user must manually specify threshold.

Author(s)

Joshua French

See Also

plot, text, abline, rstudent

Examples

lmod <- lm(price ~ sqft_living, data = home_sales)
# reference line not visible on plot because all
# leverage values are less than 0.5
leverage_plot(lmod, id_n = 2)
# different reference line
leverage_plot(lmod, id_n = 6, ttype = "2mean")
# custom reference line
leverage_plot(lmod, id_n = 2, ttype = "custom",
              threshold = 0.15)

[Package api2lm version 0.2 Index]