# Tips & Tricks 6: Exploring Data for Outliers

**geomorph**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)

pdf(“AllSpecimens.pdf”)

for(i in 1:length(outliers)){ plotRefToTarget(mshape(coords), coords[,,outliers[i]],

method=”vector”, label = T) title(names(outliers[i]))}

dev.off()

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)])

title(i)

pdfname <- paste(i, “.pdf”, sep=””)

pdf(pdfname)

plotOutliers(coords[,, which(group == i)])

for(j in 1:length(outliers)){

plotRefToTarget(mshape(coords), coords[,,outliers[j]], method=”vector”, label = T)

title(names(outliers[j]))

}

dev.off()

}

Emma

**leave a comment**for the author, please follow the link and comment on their blog:

**geomorph**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.