Tips & Tricks 6: Exploring Data for Outliers

February 17, 2015

(This article was first published on geomorph, and kindly contributed to R-bloggers)

Geomorph users,

A new function in geomorph 2.1.3 allows the user to explore Procrustes superimposed data for outliers (plotOutliers). Here I shall provide a few example for loops to demonstrate how you can explore your data for outliers prior to analyses.

1) plotTangentSpace to visualise aberrant individuals

To label all the individuals in the biplot so strong outliers can be identified:
plotTangentSpace(coords, labels = dimnames(coords)[[3]])# 

If your data has group structure (e.g. species), make a factor for this grouping variable then you can plot each level at a time using:

for(i in levels(group)){
  plotTangentSpace(coords[,,which(group == i)], 
  label = dimnames(coords)[[3]][which(group == i)])}

2) plotOutliers to find outliers by ordering individuals by their distance from the mean

outliers <- plotOutliers(coords)

If you have a lot of specimens, make a PDF of all specimens plotted as vector shape change graphs:

outliers <- plotOutliers(coords)
for(i in 1:length(outliers)){ plotRefToTarget(mshape(coords), coords[,,outliers[i]],  
method=”vector”, label = T) title(names(outliers[i]))}

If your data has group structure, make a factor for this grouping variable then you can  examine outliers for each level at a time using:

for(i in levels(group)){
      outliers <- plotOutliers(coords[,, which(group == i)])
      title(i) }

Combining these two makes a PDF for each level in the group with the summary graph and the shape change graphs:

for(i in levels(group)){
  outliers <- plotOutliers(coords[,, which(group == i)])
  pdfname <- paste(i, “.pdf”, sep=””)
  plotOutliers(coords[,, which(group == i)])
  for(j in 1:length(outliers)){
    plotRefToTarget(mshape(coords), coords[,,outliers[j]], method=”vector”, label = T)


To leave a comment for the author, please follow the link and comment on their blog: geomorph. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)