View source: R/check.outlier.R
| check.outlier | R Documentation |
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.
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, ...)
model |
a fitted model of class |
type |
a character vector indicating which statistical measures to
include in the plot, i.e., |
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
|
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., |
sort |
logical: if |
append |
logical: logical: if |
plot |
logical: if |
geom |
a character vector indicating which plot elements to draw, i.e.,
|
filename |
a character string indicating the |
width |
a numeric value indicating the |
height |
a numeric value indicating the |
dpi |
a numeric value indicating the |
check |
logical: if |
... |
further arguments to be passed to or from methods. |
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.
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 |
args |
specification of function arguments |
plot |
ggplot2 object for plotting the residuals |
data |
list with data frame, i.e., |
Takuya Yanagida
Darlington, R. B., &, Hayes, A. F. (2017). Regression analysis and linear models: Concepts, applications, and implementation. The Guilford Press.
check.resid, check.collin
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.