pca.outlier: Outlier detection by PCA

View source: R/mt_util.R

pca.outlierR Documentation

Outlier detection by PCA

Description

Outlier detection by the Mahalanobis distances of PC1 and PC2. Also plot PC1 and PC2 with its confidence ellipse.

Usage

  pca.outlier(x, center = TRUE, scale=TRUE,conf.level = 0.975,...) 

  pca.outlier.1(x, center = TRUE, scale=TRUE, conf.level = 0.975, 
              group=NULL, main = "PCA", cex=0.7,...)

Arguments

x

A data frame or matrix.

center

A logical value indicating whether the variables should be shifted to be zero centred before PCA analysis takes place.

scale

A logical value indicating whether the variables should be scaled to have unit variance before PCA analysis takes place.

conf.level

The confidence level for controlling the cutoff of the Mahalanobis distances.

group

A string character or factor indicating group information of row of x. It is used only for plotting.

main

An overall title for PCA plot.

cex

A numerical value giving the amount by which plotting text and symbols should be magnified relative to the default.

...

Further arguments for plotting

Value

A list with components:

plot

plot object of class "trellis" by pca.outlier only.

outlier

Outliers detected.

conf.level

Confidence level used.

mah.dist

Mahalanobis distances of each data sample.

cutoff

Cutoff of Mahalanobis distances used for outlier detection.

Note

Examples of panel.elli and panel.outl give more general information about ellipses and outliers. If you ONLY want to plot outliers based on PCA in a general way, for example, outliers in different groups or in conditional panel, you can write an wrapper function combining with pca.comp, panel.elli and panel.outl. It is quite similiar to the implementation of pca_plot_wrap.

Author(s)

Wanchang Lin

See Also

pcaplot, grpplot, panel.outl,panel.elli, pca_plot_wrap

Examples

  data(iris)

  ## call lattice version
  pca.outlier(iris[,1:4], adj=-0.5)
  ## plot group
  pca.outlier(iris[,1:4], adj=-0.5,groups=iris[,5])
  ## more information about groups
  pca.outlier(iris[,1:4],groups=iris[,5],adj = -0.5, xlim=c(-5, 5),
                auto.key = list(x = .05, y = .9, corner = c(0, 0)),
                par.settings = list(superpose.symbol=list(pch=rep(1:25))))

  ## call basic graphic version
  pca.outlier.1(iris[,1:4])
  ## plot group
  pca.outlier.1(iris[,1:4], group=iris[,5])


mt documentation built on June 22, 2024, 12:24 p.m.