Day 2B - Geometric Morphometrics in R PDF
Day 2B - Geometric Morphometrics in R PDF
Day 2B - Geometric Morphometrics in R PDF
R packages to install
geomorph shapes svd scatterplot3d rgl MASS ape vegan Geometric morphometrics package by Adams and Otrola-Castillo Geometric morphometrics package by Ian Dryden Singular value decomposition package Functions for 3D plotting (installed as dependency to above) More 3D functions (installed as dependency to above) Modern Applied Statistics with S (installed as dependency to above) Analyses of Phylogenetics and Evolution (installed as dependency to above) Community ecology package (installed as dependency to above)
General Procedure
Study design Data collection Data standardization Analysis Results interpretation
Department of Geological Sciences | Indiana University
(c) 2012, P. David Polly
Choosing landmarks
1. landmarks should sample the aspects of the shape that are of interest 2. enough landmarks should be used to adequately sample the shape 3. dont oversample (NB: each landmark adds weight to the
analysis. Multiple landmarks on one area will increase weight of that area.)
4. landmarks should be repeatable (same point on every specimen, placed with as little error as possible)
1. type 1 = location of the point defined by obvious biologically homologous structures (eg. intersection of three bones) 2. type 2 = location of the point defined by obvious geometry (eg., point of greatest curvature) 3. type 3 = location of point defined with reference to another point (eg., point ventral to last tooth)
Department of Geological Sciences | Indiana University
(c) 2012, P. David Polly
From an image digitize2d(filename, landmarks, scale) [opens jpg file and collects lands]
Note: digitize2d may need debugging. Saves coordinates to file in working directory in NTS format.
readmulti.nts(filenames)
digitize2d()
Erik Otarola-Castillo has sent a fix. Do the following and the function will work: 1. Set the working directory to where your images are stored. 2. Define the function picscale() as follows
picscale <- function(scale){ digscale<-NULL digscale<-locator(2,type="o",lwd=2,col="red",lty="11") sqrt(sum(diff(digscale$x)^2 + diff(digscale$y)^2))*scale }
1.1. enter the length of the scale bar as argument (e.g., 10 if the scale bar is 10 mm) 1.2. when digitize2d starts, click on both ends of the scale bar, then click on your landmarks in the proper order 1.3. coordinates and centroid sizes will be scaled in the units of your scale bar (e.g., mm)
function(path, lands, scale) { setwd(path) myFiles <- dir(pattern="[jJ][pP][gG]") for( i in 1:length( myFiles ) ) { dig2d(myFiles[i],lands, scale) } myFiles <- dir(pattern="[nN][tT][sS]") return(readmulti.nts(myFiles)) }
Cryptic error?
Error in .External2(C_edit, name, file, title, editor) : unexpected input occurred on line 3 use a command like x <- edit() to recover
May be caused by smart quotes if you copied and pasted script from Word or other text editor
Before
After
> plotAllSpecimens(lands)
Department of Geological Sciences | Indiana University
> gpagen(lands)
Details of gpagen()
This function does a generalized Procrustes analysis, superimposition of multiple specimens about their mean (Gower, 1975; Rohlf and Slice, 1990) Returns a plot of superimposed coordinates Returns the superimposed coordinates and their centroid sizes in dataframe format:
$coords = the x,y(,z) Procrustes coordinates after superimposition $Csize = the centroid size of the specimens
PC 2
Create 3D scatterplot
> library(scatterplot3d) > scatterplot3d(pca.lands$pc.scores[,1:3])
Terminology: shape
Shape = a set of landmarks Sometimes shape specifically refers to the landmark configurations without respect to size and form refers to the configurations including size
To calculate
> consensus <- apply(proc$coords, c(1,2), mean)
> plot(consensus,asp=1, type="n") > for(i in 1:length(proc$coords[,,3])) points(proc$coords[,,i]) > points(consensus, col=Red, cex=2, pch=20)
Terminology: centroid
The mean (center) of a shape (or of a landmark). Average x,y of all coordinates across all landmarks. (for individual landmark, the centroid is the consensus point for that landmark). To calculate:
> centroid <- apply(proc$coords,2,mean)
PC2
50
-50
[40.2,-22.2]
-150
-100
-50
0 PC1
50
100
150
PCA of faces
0.05
-0.10
-0.05 Axis 1
0.00
0.05
0.10
PC2
Andrew2 Thomasz2 Aidan1 Silvia2 DavidP2 Nadia1 DavidW2 Julietta1 Nadia2 DavidW1 Mark1 Julietta2 Neil2 Emily2Neil1 Emily1 Daniel1 Mark2 Derek2 Thomasz1 Stephanie1 Aidan2 Stephanie2
0.00
-0.10
-0.05 PC1
0.00
0.05
0.10
0.10
PC2
Andrew2 Thomasz2 Aidan1 Silvia2 DavidP2 Nadia1 DavidW2 Julietta1 Nadia2 DavidW1 Mark1 Julietta2 Neil2 Emily2Neil1 Emily1 Daniel1 Mark2 Derek2 Thomasz1 Stephanie1 Aidan2 Stephanie2
0.00
-0.10
-0.05 PC1
0.00
0.05
0.10