Date: | 2016-02-24 |
Type: | Package |
Title: | Evolutionary Morphometric Simulation |
Version: | 0.9 |
Author: | Juan Manuel Cabrera, Federico Giri |
Maintainer: | Juan Manuel Cabrera <juanmanuelcabrera1@gmail.com> |
Depends: | R (≥ 3.2.0) |
Imports: | ggplot2, reshape2, geomorph, stringr |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Description: | Evolutionary process simulation using geometric morphometric data. Manipulation of landmark data files (TPS), shape plotting and distances plotting functions. |
LazyData: | yes |
NeedsCompilation: | no |
Packaged: | 2016-02-25 19:05:40 UTC; Juanma |
Repository: | CRAN |
Date/Publication: | 2016-02-25 21:12:57 |
Plot the Procrustes distances between a set of shapes and a reference
Description
DistancesPlot
creates a distances plot using ggplot2 (Wickman 2009).
Usage
DistancesPlot(dist)
Arguments
dist |
Distances matrix |
Details
Use ggplot2
to create a plot where each point represent distance between a particular shape and a reference shape.
Value
Return an ggplot2 object
Author(s)
Juan Manuel Cabrera
References
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2009.
Examples
data("simulated_shape_distances")
#Plot distances between a set of simulated shapes a reference.
DistancesPlot(simulated_shape_distances)
Generalized Procrustes residuals calculation
Description
Calculates Procrustes residuals of landmark configurations
Usage
GpaResiduals(lands,gpa_coords)
Arguments
lands |
Landmark configuration |
gpa_coords |
GPA coordinates matrix |
Details
Partial least squares analysis is a common tool to examine complex patterns of covariations between multiple sets of variables (Rohlf and Corti 2000; Bookstein et al. 2003). When one set of these variables consists of shape coordinates it is called singular warps analysis. Singular warp analysis is based on a singular decomposition of the cross-covariance matrix of two sets of variables measured from the same sample objects. Bookstein et al. (2013) gave this equation (1):
\sum = \left ( 1/N \right )X^{t}Y\
Where N is the sample size and X and Y are matrices for two sets of variables with N rows, corresponding to the same sample specimens, and columns according to the number of variables of each set. If each variable in both matrices is first mean-centered (by variable), then Equation (1) yields the cross-covariance matrix between variables in X and those in Y.
Most of the landmark-based morphometric studies use aligned shape coordinates (GPA) as variable for analyzing complex patterns of covariations between sets of landmarks coordinates data. However, whereas GPA mean-centers all specimen configurations – it superimposes the centroids of each specimen - GPA does not mean center each coordinate within the specimens, and therefore does not in itself provide suitable variables for use in Equation (1).
To avoid this problem GpaResiduals
mean center the aligned coordinates to get Procrustes residuals which are more appropriate for calculating covariance (McNulty 2009).
If generalized procrustes coordinates are not provided, the function will calculate them using geomorph package (Adams & Otárola Castillo 2013)
Value
It returns a list containing:
consens |
Consensus shape |
cvectorized |
Consensus shape (1 dim vector) |
resid |
GPA residuals matrix |
Author(s)
Cabrera Juan Manuel
References
Adams, D. C., & Otárola-Castillo, E. (2013). geomorph: an R package for the collection and analysis of geometric morphometric shape data. Methods in Ecology and Evolution, 4(4), 393-399.
Bookstein, F. L., Gunz, P., Mitterœcker, P., Prossinger, H., Schæfer, K., & Seidler, H. (2003). Cranial integration in Homo: singular warps analysis of the midsagittal plane in ontogeny and evolution. Journal of Human Evolution, 44(2), 167-187.
McNulty, K. P. (2009). Computing singular warps from Procrustes aligned coordinates. Journal of human evolution, 57(2), 191-194.
Rohlf, F. J., & Corti, M. (2000). Use of two-block partial least-squares to study covariation in shape. Systematic Biology, 49(4), 740-753.
Examples
data("aegla_landmarks")
result<-GpaResiduals(lands = aegla_landmarks)
#GPA consensus (matrix)
result$consens
#GPA consensus (vector)
result$cvectorized
#GPA residual matrix
result$resid
Plot shapes
Description
Plot the differences between a set of morphometric shapes and a reference
Usage
PlotVariations(shapes, reference, path, save = F, w = 6, h = 6, d = 100, c_ref = "red",
c_target = "black", s_ref = 3, s_target = 2)
Arguments
shapes |
Landmark data of shapes (list of matrices) |
reference |
Landmark data of reference shape (matrix type) |
path |
Path where results will be saved (Default: working directory) |
c_ref |
Color of the points representing the reference shape (Default |
c_target |
Color of the points representing the target shape (Default |
s_ref |
Size of the points representing the reference shape (Default |
s_target |
Size of the points representing the target shape (Default |
save |
A logical value. If TRUE, the function will save the plot as jpeg images in the indicated in |
This parameters are used to modify stored graph (save = TRUE
):
w |
Units of width of the graph in inches (Default |
h |
Units of height of the graph in inches(Default |
d |
Number of dpi (resolution) of the graph. (Default |
Details
The function uses package ggplot2 (Wickman 2009) to create multiple plots representing the variations between a list of target shapes and a reference (consensus shape or another specimen data). If save=TRUE
it creates a folder (named day_hh_mm) and stores the plots as images (.jpeg) at the provided path (if not provided it will store them in the working directory).
There are several parameters for modify the graph for a suitable representation. This function could be used for example to analyze morphological variations of species over generations.
Author(s)
Cabrera Juan Manuel
References
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2009.
See Also
Examples
data("aegla_consensus")
data("simulated_shapes")
#Sample one individual from simulated_shapes dataset
simu<-simulated_shapes[100]
#Create a shape variation graphic
graph<-PlotVariations(simu,aegla_consensus)
#Red dots represent the landmark coordinates of the reference shape and black
# dots represent the target shape. The length of the segments represent
# distances between pairs of homologous landmarks
graph[[1]]
Extract landmark data
Description
Read landmark coordinates and scales from a TPS file
Usage
ReadLandmarkData(datafile, m_byscale = T)
Arguments
datafile |
TPS file containing two dimensional landmark data |
m_byscale |
Logical value (Default m_byscale=TRUE). If TRUE, landmark coordinates are multiply by scale |
Details
The function returns landmark coordinates (array and data.frame format) and the scale of each specimen. If m_byscale
= T the coordinates are multiple by the corresponding scale.
ReadLandmarkData
only works with TPS files that has only landmark coordinates (presence of CURVES and OUTLINES may cause malfunction).
Value
It returns a 3 element list:
df |
Landmark coordinates as a data.frame. Sp factor correspond to species number. |
array |
Landmark coordinates as a three dimensional array. |
scale |
Vector of scales value for each specimen. |
Author(s)
Cabrera Juan Manuel
Calculate Procrustes distance between shapes
Description
Use the Procrustes method to calculate distances between a set of shapes and a reference.
Usage
ShapeDist(shapes, reference)
Arguments
shapes |
Landmark data of shapes (list of matrices) |
reference |
Lanmark data of reference shape (matrix type) |
Details
Procrustes distance provides a measure of coincidence of two point sets xi and yi, i=1..N. For this purpose the variance of point deviations is calculated at the optimal superposition of the sets. It allows to characterize the shape proximity of a given simplex to shape of a reference one.
Value
A matrix containing procrustes distance between shapes. Procrustes distance is the square root of the sum of squared differences in the posititions of the landmarks in two shapes (Dryden and Mardia 1998). This can be used to describe the difference between many landmark configurations (Rohlf and Slive 1990).
Author(s)
Cabrera Juan Manuel
References
Dryden, I. L., & Mardia, K. V. (1998). Statistical shape analysis (Vol. 4). Chichester: Wiley.
Rohlf, F. J., & Slice, D. (1990). Extensions of the Procrustes method for the optimal superimposition of landmarks. Systematic Biology, 39(1), 40-59.
Examples
data("aegla_landmarks")
data("aegla_consensus")
#Calculate distances between set of shapes and a reference
ShapeDist(shapes = aegla_landmarks, reference = aegla_consensus)
Simulation of Shape Variation
Description
SimEvo
performs a simulation of shape variation using a modification of Lande's evolutionary model Polly 2004
Usage
SimEvo(vari, consensusvec, resids, ngen, fsamp)
Arguments
vari |
Variation coefficient |
consensusvec |
Consensus shape (vectorized form) |
resids |
GPA residuals matrix |
ngen |
Number of generations of simulations (Default: 1000000 steps). |
fsamp |
Frequency of samples (Default: 1000000 steps). |
Details
Lande's evolutionary model defines mean morphological variation over generations \Delta Z
as:
\Delta Z = \beta G
where G
is the additive genetic covariance matrix, and \beta
are selection coefficients applied to the morphological structure.
Polly 2004 proposes a modification of this equation in order to use it with morphological data instead of genetic data:
\Delta Z = \beta P H
where P
is the phenotypic covariance matrix, and H
is an heritability matrix (See Polly 2004 for more information).
resids
will be used as the phenotypic covariance matrix, and vari
will be used to simulate \beta H
term. After ngen
simulations steps the new shape will be
reconstructed from the starting shape consensusvec
.
The number of plots representing the new shapes can be modify using fsamp
.
Value
It returns a list of ngen/fsamp shapes (landmarks coordinates)
Author(s)
Cabrera Juan Manuel
References
Polly, P. D. (2004). On the simulation of the evolution of morphological shape: multivariate shape under selection and drift. Palaeontologia Electronica, 7(2), 1-28.
Examples
data("aegla_landmarks")
#Use GpaResiduals function to obtain GPA residual matrix and consensus
# coordinates from landmark configuration
a_data=GpaResiduals(aegla_landmarks)
#Simulate morphological evolution with a variation rate "vari"
# trough "ngen" generations and retrieve the last generation shape coordinates
simshape = SimEvo(vari = 2, consensusvec = a_data$cvectorized,
resids = a_data$resid, ngen = 10000, fsamp = 10000)
#Plot consensus shape and the simulated shape
par(mfrow=c(1, 2))
plot(a_data$consens,type = "p",main = "Reference", xlab = "", ylab = "")
plot(simshape[[1]],type = "p",col = "red",main = "Target", xlab = "", ylab = "")
#Or you can use PlotVariations to see the difference more clearly
PlotVariations(simshape,a_data$consens)
Landmark coordinates data from consensus configuration of freshwater crabs
Description
Aegla uruguayana consensus shape coordinates.
Usage
data("aegla_consensus")
References
Diawol, V. P., Giri, F., & Collins, P. A. (2015). Shape and size variations of Aegla uruguayana (Anomura-Aeglidae) under laboratory conditions. A geometric morphometric approach to the growth. Iheringia Série Zoologia, 105(1), 76-83.
Landmark coordinates data from freshwater crabs
Description
Geometric morphometric data of Aegla uruguayana cephalothorax (21 landmarks).
Usage
data("aegla_landmarks")
References
Diawol, V. P., Giri, F., & Collins, P. A. (2015). Shape and size variations of Aegla uruguayana (Anomura-Aeglidae) under laboratory conditions. A geometric morphometric approach to the growth. Iheringia Série Zoologia, 105(1), 76-83.
Procrustes distances data
Description
Procrustes distance between a set of simulated shapes and their ancestry over generations.
Usage
data("simulated_shape_distances")
Simulated shapes
Description
Simulated landmark data using evomorph SimEvo
function on Aegla uruguayana data.
Usage
data("simulated_shapes")
References
Diawol, V. P., Giri, F., & Collins, P. A. (2015). Shape and size variations of Aegla uruguayana (Anomura-Aeglidae) under laboratory conditions. A geometric morphometric approach to the growth. Iheringia Série Zoologia, 105(1), 76-83.