[R] geomorph: adding confidence ellipses

David L Carlson dcarlson at tamu.edu
Tue Dec 22 16:35:28 CET 2015


Look at scatter3d() in the car package. It has an option to add a confidence ellipsoid to an interactive 3d plot.

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352


-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of taze4 at web.de
Sent: Tuesday, December 22, 2015 1:58 AM
To: R Help
Subject: [R] geomorph: adding confidence ellipses

Hello everyone,
I’m currently working with package geomorph in R to generate a PCA plot. Now I want to add confidence ellipses to my plot. I couldn’t find any command integrated in package geomorph for doing this.
So I tried package vegan for adding confidence ellipses but the command does not work with geomorph as my data is a 3D-array (for the PCA) and vegan needs a 2D-array for creating confidence ellipses. Changing the data from 3D to 2D doesn’t work either as in this case I can’t plot the PCA at all.

Does anyone know a command in geomorph for confidence ellipses or a package compatible with geomorph for adding confidence ellipses?

Technical details: I am currently working with RStudio Version 0.99.484

My code so far:
library(rgl)
library(ape)
library(geomorph)

morpho<-readland.tps(file,specID="ID") #adding my data#
classifiers<-read.table(file,header=T) #adding the classifiers#
attach(classifiers)

morpho.gpa<-gpagen(morpho, pointscale=1,ShowPlot=T) #doing the Procrustes Fit#
plotTangentSpace(morpho,axis1=2,axis2=3,label=T,group=classifiers$Stretch) #plotting the PCA with Stretch as group, there are 4 different levels in group#

Now I want to add confidence ellipses. As I know no command in geomorph, I used vegan:
library(lattice)
library(permute)
library(vegan)
ordiellipse(morpho,classifiers$Stretch,kind="sd",conf=0.95)

This gives me the following error message:
Error in ordiellipse(morpho, classifiers$Stretch, kind = "sd", conf = 0.95) : 
  ordiellipse needs two dimensions

My data for the PCA is a 3D-array:
dim(morpho) #asking if data is 3D or 2D, as my command returns 3 values, the data  is in the form of a 3D-array#
[1] 16  2 88

Changing my data into a 2D-array does not solve the problem, because then I am unable to plot the PCA at all:
morpho2D<-two.d.array(morpho.gpa$coords)
plotTangentSpace(morpho2D,axis1=2,axis2=3,label=T,group=classifiers$Stretch)
Error in plotTangentSpace(morpho2D, axis1 = 2, axis2 = 3, label = T, group = classifiers$Stretch) : 
  Data matrix not a 3D array (see 'arrayspecs').

I am grateful for any help on this topic!
Kind regards,
Tatze


This is what my data looks like:
morpho[,,1] #I have 16 landmarks per fish, in total 87 fish; each of the 16 landmarks is given as coordinates#
          [,1]     [,2]
 [1,] 3.632444 4.795980
 [2,] 4.767132 4.726264
 [3,] 5.428232 4.735880
 [4,] 8.721712 3.935348
 [5,] 9.810724 3.899288
 [6,] 9.844380 2.704500
 [7,] 8.361112 2.716520
 [8,] 5.750368 2.646804
 [9,] 3.240592 2.488140
[10,] 3.440124 3.074716
[11,] 3.663696 4.344028
[12,] 2.995384 4.358452
[13,] 1.382300 4.211808
[14,] 0.613020 3.673312
[15,] 1.447208 3.137220
[16,] 2.055420 2.853548

head(classifiers)
  ID   Nr TotalLength Weight Sex Stretch riverbank  centroid
1  0 L010        11.5   15.0   1     Kel     Kel_l 12.180512
2  1 L094         8.0    7.4   1     Reg     Reg_r  8.459462
3  2 L033         9.6   12.6   1    Vils    Vils_r 10.262179

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list