sl_plot.lm {api2lm}R Documentation

Spread-level plot for lm object

Description

sl_plot.lm plots a spread-level plot of a fitted lm object. In general, it is intended to provide similar functionality to plot.lm when which = 3, but can be used for different types of residuals and can also plot first-order predictor variables along the x-axis instead of only the fitted values.

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

Usage

## S3 method for class 'lm'
sl_plot(
  model,
  rtype = c("standardized", "studentized", "internally studentized",
    "externally studentized"),
  xaxis = "fitted",
  id_n = 3,
  predictors = ~.,
  smooth = stats::loess,
  add_smooth = TRUE,
  ...,
  text_arglist = list(),
  smooth_arglist = list(),
  lines_arglist = list()
)

Arguments

model

A fitted model object from the lm function.

rtype

The residual type to plot. The default is "ordinary". The other options are "standardized", "studentized", "loo", "jackknife", "deleted", "internally studentized", "externally studentized".

xaxis

The variable to use on the x-axis of the plot(s). The default is "fitted" to use fitted values. The other option is "predictors".

id_n

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

predictors

A formula describing the first-order predictors to plot the residuals against. The default is all available first-order predictors.

smooth

A function with a formula argument to smooth the desired plot. The default function is loess.

add_smooth

A logical value indicating whether a smooth should be added to each plot produced. The default is TRUE.

...

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.

smooth_arglist

A named list specifying additional arguments passed to the function provided in the smooth argument.

lines_arglist

A named list specifying additional arguments passed to the lines function for plotting the result of applying the smooth function.

Author(s)

Joshua French

See Also

plot, text, lines loess.

Examples

lmod <- lm(Petal.Length ~ Sepal.Length + Species,
           data = iris)
# similarity with built-in plot.lm functionality
sl_plot(lmod)
plot(lmod, which = 3)
# spread-level plot for other residual types
sl_plot(lmod, rtype = "studentized", id_n = 0)
# spread-level plot for predictors
sl_plot(lmod, xaxis = "pred", id_n = 2)
# spread-level plot for individual predictors
sl_plot(lmod, xaxis = "pred",
        predictors = ~ Sepal.Length,
        id_n = 2)

[Package api2lm version 0.2 Index]