check.outlier: Outlier and Influential Observations Diagnostics for Linear...

View source: R/check.outlier.R

check.outlierR Documentation

Outlier and Influential Observations Diagnostics for Linear Models

Description

This function performs outlier and influential observations diagnostics by plotting for statistical measures for leverage, distance, and influence for linear models estimated by using the lm() function. Mahalanobis distance and hat values are computed for quantifying leverage, standardized leverage-corrected residuals and studentized leverage-corrected residuals are computed for quantifying distance, and Cook's distance and standardized DFBETAS are computed for quantifying influence. By default, the function provides plots showing observations with the 10% highest absolute values or a minimum of 10 observations with the highest absolute values in the hat values, studentized leverage-corrected residuals, and Cook's distances.

Usage

check.outlier(model, type = c("mahal", "hat", "rstand", "rstud", "cook", "dfb"),
              cutoff = NULL, sample = 0.10, sort = TRUE, append = TRUE,
              plot = TRUE, geom = c("none", "text"), filename = NULL,
              width = NA, height = NA, dpi = 600, check = TRUE, ...)

Arguments

model

a fitted model of class "lm".

type

a character vector indicating which statistical measures to include in the plot, i.e., "mahal" for the Mahalanobis distance, "hat" for the hat value, "rstand" for the standardized leverage-corrected residual, "rstud" for the studentized leverage-corrected residual, "cook" for the Cook's distance, and "dfb" for the DFBETAS.

cutoff

a named numeric vector indicating the cutoff values for the statistical measures shown in the plot as horizontal lines. Note that the elements of the vectors need to be need with "mahal", "hat", "rstand", "rstud", "cook", and "dfb". For example, cutoff = c(hat = 0.2, cook = 0.3) to draw a horizontal line at 0.2 for the hat value plot and a horizontal line at 0.3 for the Cook's distance plot.

sample

numeric value for selecting the sample with the highest absolute values in the statistical measures for leverage, distance, and influence. The value is either a proportion between 0 and 1, e.g., sample = 0.2 for the 20% highest absolute values, or an integer value for selecting the number of observations with the highest absolute values. Note that the logical argument FALSE can be used to plot all observations. By default, the function plots observations with the 10% highest absolute values, but a minimum of 10 observations.

sort

logical: if TRUE (default), observations are sorted in decreasing order by the statistical measure.

append

logical: logical: if TRUE (default), statistical measures for leverage, distance, and influence are appended to the data frame in model$model.

plot

logical: if TRUE (default), a plot is drawn.

geom

a character vector indicating which plot elements to draw, i.e., "none" for not drawing any labels, "text" (default) for drawing labels above or below each observation.

filename

a character string indicating the filename argument including the file extension in the ggsave function. Note that one of ".eps", ".ps", ".tex", ".pdf" (default), ".jpeg", ".tiff", ".png", ".bmp", ".svg" or ".wmf" needs to be specified as file extension in the file argument. Note that plots can only be saved when plot = TRUE.

width

a numeric value indicating the width argument (default is the size of the current graphics device) for the ggsave function.

height

a numeric value indicating the height argument (default is the size of the current graphics device) for the ggsave function.

dpi

a numeric value indicating the dpi argument (default is 600) for the ggsave function.

check

logical: if TRUE (default), argument specification is checked.

...

further arguments to be passed to or from methods.

Details

In regression analysis, an observation can be extreme in three major ways (see Darlington & Hayes, 2017, p. 484): (1) An observation has high leverage if it has a atypical pattern of values on the predictors, (2) an observation has high distance if its observed outcome value Y_i has a large deviation from the predicted value \hat{Y}_i, and (3) an observation has high influence if its inclusion substantially changes the estimates for the intercept and/or slopes.

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

model

model specified in model

args

specification of function arguments

plot

ggplot2 object for plotting the residuals

data

list with data frame, i.e., data for a data frame in model$model with statistical measures for leverage, distance, and influence are appended to the data frame when append = TRUE, mahal for the sample of data with the highest Mahalanobis distance, hat for the sample of data with the highest hat values, rstand for the sample of data with the highest absolute standardized leverage-corrected residuals, rstud for the sample of data with the highest absolute studentized leverage-corrected residuals, cook for the sample of data with the highest Cook's distance, and *.dfb for the sample of data with the highest absolute DFBETAS

Author(s)

Takuya Yanagida

References

Darlington, R. B., &, Hayes, A. F. (2017). Regression analysis and linear models: Concepts, applications, and implementation. The Guilford Press.

See Also

check.resid, check.collin

Examples

## Not run: 
#————————————————————————————————————————————————————————————————————————————
# Outlier and Influential Observations Diagnostics for Linear Models

# Estimate linear model
mod <- lm(mpg ~ cyl + disp + hp, data = mtcars)

#——————————————————————————————————————
## Default Setting

# Example 1a: Hat values, studentized leverage-corrected residuals, and Cook's distance
check.outlier(mod)

# Example 1b: Additional plot arguments
# see Details in the help page of the function plot.misty.object
check.outlier(mod, point.shape = 1, point.size = 4, line.col = "red")

#——————————————————————————————————————
## Argument 'cutoff' and 'type'

# Example 2a: Horizontal cutoff lines
check.outlier(mod, cutoff = c(hat = 0.3, rstud = 2, cook = 0.1))

# Example 2b: Mahalanobis distance and standardized leverage-corrected residuals
check.outlier(mod, type = c("mahal", "rstand"), cutoff = c(mahal = 8, rstand = 2))

# Example 2c: DFBETAS
check.outlier(mod, type = "dfb", cutoff = c(dfb = 0.35))

#——————————————————————————————————————
## Arguments 'sample' and 'sort'

# Example 3a: Plot entire data set and do not sort
check.outlier(mod, sample = FALSE, sort = FALSE)

# Example 3b: Plot 50% highest absolute values
check.outlier(mod, sample = 0.5)

# Example 3c: Plot n = 15 highest absolute values
check.outlier(mod, sample = 15)

#——————————————————————————————————————
## Data

object <- check.outlier(mod)

# Example 4a: Data frame with with statistical measures
object$data$data

# Example 4b: Sample of data with the highest hat values
object$data$hat

#————————————————————————————————————————————————————————————————————————————
# Save Plot

# Example 7: Save plot as PNG file
check.outlier(mod, filename = "Outlier.png", width = 12, height = 15)

## End(Not run)

misty documentation built on Nov. 24, 2026, 5:06 p.m.

Related to check.outlier in misty...