influence_plot {api2lm}R Documentation

Influence plots

Description

influence_plot creates an influence plot for a fitted lm object. The y-axis is either the studentized (the default) or standardized residuals versus the leverage values for each observation. The size of the point associated with each observation is proportional to the value of the Cook's distance (the default) or the DFFITS statistic for the observation.

Details about the different types of residuals are discussed in the get_residuals function.

Usage

influence_plot(
  model,
  rtype = c("studentized", "standardized"),
  criterion = c("cooks", "dffits"),
  id_n = 3,
  add_reference = TRUE,
  alpha = 0.05,
  size = c(1, 4.8),
  ...,
  text_arglist = list(),
  abline_arglist = list(),
  extendrange_f = 0.08
)

Arguments

model

A fitted model object from the lm function.

rtype

The residual type to plot on the y-axis. The default is "studentized". The other option is "standardized".

criterion

The criterion that decides the size of the points. The default is "cooks". The other option is "dffits".

id_n

The number of points to identify with labels with respect to largest absolute criterion. The default is 3 labels.

add_reference

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

alpha

The default quantile used for the horizontal reference lines. The default is 0.05. See Details.

size

A numeric vector of length 2 that provides guidelines for the size of the points.

...

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

The range of the criterion statistic is mapped to cex_pt = size[2]^2 - size[1]^2 and then the size of the points is sqrt(cex_pt).

If add_reference is TRUE, then horizontal reference lines are added at the \alpha/2 and 1-\alpha/2 quantiles of a t distribution with degrees of freedom given by stats::df.residual(model).

If add_reference is TRUE, then vertical reference lines are added at 2p/n and 0.5 where p=length(stats::coef(model)) and n=stats::nobs(model).

The vertical position of the reference lines can be customized by setting the h argument of abline_arglist. The horizontal position of the reference lines can be customized by setting the v argument of abline_arglist.

Author(s)

Joshua French

See Also

plot, text, abline, rstandard, rstudent, hatvalues cooks.distance, dffits

Examples

lmod <- lm(murder ~ hs_grad + urban + poverty + single,
           data = crime2009)
# studentized residuals vs leverage
influence_plot(lmod, id_n = 3)
# standardized residuals vs leverage
influence_plot(lmod, rtype = "stan")
# similar plot from plot.lm
plot(lmod, which = 5)

[Package api2lm version 0.2 Index]