outlierplot: Univariate Representation of Multivariate Outliers

View source: R/outlierplot.R

outlierplotR Documentation

Univariate Representation of Multivariate Outliers

Description

This function creates a visual representation of multivariate outliers using a univariate plot.It uses robust covariance estimation methods to identify outliers and provides options for displaying the results through various plotting styles.

Usage

outlierplot(
  x,
  quan = 1/2,
  alpha = 0.025,
  show.outlier = TRUE,
  show.mahal = FALSE
)

Arguments

x

A matrix or data frame.

quan

A numeric value, between 0.5 and 1, that specifies the amount of observations which are used for MCD estimations. Default is 0.5.

alpha

A numeric value specifying the amount of observations used for calculating the adjusted quantile. Default is 0.025.

show.outlier

A logical value, if TRUE (default), outliers are highlighted in the plot.

show.mahal

A logical value, if FALSE (default), robust Mahalanobis distances are not color-coded in the plot.

Details

The function uses the Minimum Covariance Determinant (MCD) method to compute robust estimates of location and scatter. It then applies an adaptive reweighting step to further improve the outlier detection. The results are visualized using ggplot2, with options to highlight outliers and/or color-code points based on their Mahalanobis distances.

Value

Depending on the combination of show.outlier and show.mahal:

  • A ggplot object with outliers highlighted (if show.outlier = TRUE)

  • A ggplot object with Mahalanobis distances color-coded (if show.mahal = TRUE)

  • A ggplot object combining both outlier highlighting and Mahalanobis distance color-coding (if both show.outlier and show.mahal are TRUE)

  • A tibble containing standardized scores, outlier flags, and robust multivariate Mahalanobis distances (if both show.outlier and show.mahal are FALSE)

Author(s)

Christian L. Goueguel

Examples

# Load the glass dataset from the chemometrics package
data(glass, package = "chemometrics")

# Basic usage with default parameters
outlierplot(glass)

# Adjust the proportion of observations used for MCD estimation
outlierplot(glass, quan = 0.75)

# Show Mahalanobis distances instead of outlier highlighting
outlierplot(glass, show.outlier = FALSE, show.mahal = TRUE)

# Combine outlier highlighting and Mahalanobis distance color-coding
outlierplot(glass, show.outlier = TRUE, show.mahal = TRUE)

# Return data frame instead of plot
result_df <- outlierplot(glass, show.outlier = FALSE, show.mahal = FALSE)
head(result_df)


ChristianGoueguel/specProc documentation built on Nov. 9, 2024, 3:23 p.m.