Phenotypic Trajectory Analysis

525 views
Skip to first unread message

lowiea...@gmail.com

unread,
Mar 3, 2022, 5:06:38 AM3/3/22
to geomorph R package

Hi!

I would like to perform a Phenotypic Trajectory Analysis but it’s not going well so far!

Goal is to visualize the trajectory between vertebrae (5 vertebrae) across the body of caecilians (24 sp). Would like to get 1 trajectory per species, and this trajectory going through the 5 vertebrae.

My initial model is:

gdfmean<-geomorph.data.frame(lm=coords, vert=group2, Cs=CStot, sp=sp)

fit <- lm.rrpp (lm ~ Cs * vert , data= gdfmean, iter = 199)

I want to include the size in the model, is it the first mistake? Should I include ‘sp’ in my model prior to perform the PTA?

Because then I would like to do the PTA:

TA <- trajectory.analysis(fit, groups = gdfmean$vert, traj.pts = gdfmean$sp)

--> “Error: Not every trajectory point has replication (more than one observation).”

Here’s what I have in vert and sp.
Capture.PNG
I have replication in both groups… It represents the vertebra 20 for all species, and then vertebra 2 for all species, …
Maybe it has to be organized such as V20 V2 V3 V60 and V90 for one species, and then same for the other species and so on?

Thanks a lot for your help! 

Aurélien

Mike Collyer

unread,
Mar 3, 2022, 7:40:35 AM3/3/22
to geomorph R package
Aurélien,

You are attempting to have sp as trajectory points for a model fit that did not include sp as a term.  Try changing the right had side of your equation to 

~ Cs * vert * sp

and it might work.  However, PTA works on factorial means and ~ Cs * vert * sp is a model where factor means might not be valid.  Rather,

~ Cs + vert * sp

would be ideal, provided you feel confident that interactions between Cs and main factors do not suggest significantly varied slopes.

Cheers!
Mike

On Mar 3, 2022, at 5:06 AM, lowiea...@gmail.com <lowiea...@gmail.com> wrote:

Hi!

I would like to perform a Phenotypic Trajectory Analysis but it’s not going well so far!

Goal is to visualize the trajectory between vertebrae (5 vertebrae) across the body of caecilians (24 sp). Would like to get 1 trajectory per species, and this trajectory going through the 5 vertebrae.

My initial model is:

gdfmean<-geomorph.data.frame(lm=coords, vert=group2, Cs=CStot, sp=sp)

fit <- lm.rrpp (lm ~ Cs * vert , data= gdfmean, iter = 199)

I want to include the size in the model, is it the first mistake? Should I include ‘sp’ in my model prior to perform the PTA?

Because then I would like to do the PTA:

TA <- trajectory.analysis(fit, groups = gdfmean$vert, traj.pts = gdfmean$sp)

--> “Error: Not every trajectory point has replication (more than one observation).”

Here’s what I have in vert and sp.

<Capture.PNG>
I have replication in both groups… It represents the vertebra 20 for all species, and then vertebra 2 for all species, …
Maybe it has to be organized such as V20 V2 V3 V60 and V90 for one species, and then same for the other species and so on?

Thanks a lot for your help! 

Aurélien


--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/a494f3e2-512c-41e0-97a1-d19c35d46686n%40googlegroups.com.
<Capture.PNG>

lowiea...@gmail.com

unread,
Mar 3, 2022, 8:52:49 AM3/3/22
to geomorph R package
Thanks Mike! 

But I still have the error  “Error: Not every trajectory point has replication (more than one observation).”  if I am using TA <- trajectory.analysis (fit, groups = gdfmean$vert, traj.pts = gdfmean$sp)

Should I use 'as.numeric', 'as.factor', 'levels',... somewhere? 

Thanks! 

Aurélien

Mike Collyer

unread,
Mar 3, 2022, 9:18:55 AM3/3/22
to geomorph-...@googlegroups.com
Yes, vert and sp have to be factors, and they have to have all possible interactions.  If one or both are inherently numeric, you will have to coerce them into factors.

Mike

lowiea...@gmail.com

unread,
Mar 3, 2022, 10:13:55 AM3/3/22
to geomorph R package
Like this then: 

TA <- trajectory.analysis(fit, groups = as.factor(gdfmean$vert), traj.pts = as.factor(gdfmean$sp))

It still gives the same error... 

Capture.PNG

Thanks!

Mike Collyer

unread,
Mar 3, 2022, 10:26:23 AM3/3/22
to geomorph R package
No, they must be a factors in your initial model fit.

Mike

On Mar 3, 2022, at 10:13 AM, lowiea...@gmail.com <lowiea...@gmail.com> wrote:

Like this then: 

TA <- trajectory.analysis(fit, groups = as.factor(gdfmean$vert), traj.pts = as.factor(gdfmean$sp))

It still gives the same error... 

Mike Collyer

unread,
Mar 3, 2022, 10:36:45 AM3/3/22
to geomorph R package
Additionally, this is only one problem.  As the error statement indicates, you have no replication.  You have 120 observations, 24 species, and 5 different trajectory points.  But 5 * 24 = 120.  You have 0 residuals degrees of freedom, so you have, therefore, no statistical test to perform.

Mike
Message has been deleted

lowiea...@gmail.com

unread,
Mar 3, 2022, 11:38:17 AM3/3/22
to geomorph R package
Ok. I actually though that I HAD to have 120 observations. And replication would mean SP1-V2, SP1-V3, SP1-V20,... And thus the first species (SP1) replicated k times if I have k vertebrae. 

So a PTA would work only if I have a group factor such as 3 different ecologies, and check the trajectory of vertebral shape variation depending of ecology ( 5*3 < 120). Or I really miss the point? 

The thing is, I would love to do a plot such as this one, from Scholtes et al. (2021). Where T1 to T13 represent vertebrae, and each trajectory represent a species. That's what I would like to do... And to do so, I though I had to get the 120 observations in the plot... Grouped in 24 trajectories comprising 5 points each... 

Capture.PNG

Adams, Dean [EEOB]

unread,
Mar 3, 2022, 11:47:05 AM3/3/22
to geomorph-...@googlegroups.com

Aurélien,

 

The plot you wish to generate does not require the trajectory analysis per se. These trajectories are quite similar to the ‘motion path’ example in the help file for trajectory.analysis in geomorph.

 

However, from reading the exchange you’ve been having, you still could not perform the analysis, because even for that specialized data set-up, you still require ‘groups’ of species to compare. So whether the design is of this type, or of the type you were discussing with Mike, either way you have no replication, so zero residual df. Like Mike said, there is no test to perform.

 

Dean

 

Dr. Dean C. Adams (he/him)

Distinguished Professor of Evolutionary Biology

Director of Graduate Education, EEB Program

Department of Ecology, Evolution, and Organismal Biology

Iowa State University

https://faculty.sites.iastate.edu/dcadams/

phone: 515-294-3834

talijan...@gmail.com

unread,
Jul 14, 2022, 5:06:48 AM7/14/22
to geomorph R package

Dear geomorph community,

I am conducting a phenotypic trajectory analysis to investigate possible intraspecific sexual shape dimorphism in fish species inhabiting two different areas in the Adriatic Sea that differ mainly in terms of resource availability and structure. However, I am also interested in examining sexual size dimorphism between the sampled populations and whether they follow Rensch's rule or the pattern whereby size is more female biased (i.e., the female size to male size ratio is higher) the smaller the body size of the species, whereas it becomes increasingly more male biased the larger-bodied the species.

I came across the angler package (https://github.com/TWilliamBell/angler), which seems to be compatible with geomorph as it provides the ability to calculate sexual size and shape dimorphism using landmark-based sexual dimorphism data. However, I have not been able to run the code or structure it properly. So, I was wondering if anyone has experience with this package and can provide some guidelines on how to implement the code with geomorph.

 

Also, if someone has some advice how to produce the RMA analysis and the plot as found in Kelly et al. (2013) – Figure 4 would be helpful, as I have difficulties  creating it properly due to insufficient coding skills.

 

 Thank you for your consideration.


Sincerely,

Igor

 

Reference:

Kelly, C.D., Folinsbee, K.E., Adams, D.C., Jennions, M.,D. (2013) Intraspecific sexual size and shape dimorphism in an Australian freshwater fish differs with respect to a biogeographic barrier and latitude. Evolutionary Biology, 40: 408-419.

Ian Dworkin

unread,
Jul 14, 2022, 7:03:20 AM7/14/22
to geomorph-...@googlegroups.com
Hi Igor


The angler package is from my lab and we are still finishing it up for publication, including a tutorial.  The version you are looking at is probably the 0.1 or 0.2 version so was not ready for public use and is incomplete).  I am not sure if the current version of the repository is public (probably as we usually do keep them open).  But we hope to submit by the end of the summer.  Please contact me and we are more than happy to ask you to run through the tutorial and when we finish it so we can revise it to make it clearer.  

Cheers,
Ian Dworkin
 (on behalf of Nirupama and Will who have done much of the coding and refactoring of the functions for angler)

On Jul 14, 2022, at 5:06 AM, talijan...@gmail.com <talijan...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

Ian Dworkin

unread,
Jul 14, 2022, 7:13:49 AM7/14/22
to geomorph-...@googlegroups.com, Nirupama Tamvada
For people who can’t wait and why to give us suggestions,criticism and feedback the public copy to follow is (but it really is not yet ready for prime time, so we really advise waiting).  

https://github.com/DworkinLab/angler 


Ian (and Nirupama who is now leading the development of the library)


On Jul 14, 2022, at 7:03 AM, Ian Dworkin <ian.d...@gmail.com> wrote:



Bryan H. Juarez

unread,
Jul 14, 2022, 10:57:35 AM7/14/22
to geomorph-...@googlegroups.com, Nirupama Tamvada
Hi all, 

Igor, I just wanted to share the following code since it is published, which would help in the review process (not to discourage angler - I am excited to see what it can do). This is the paper https://doi.org/10.1111/evo.14049 and the associated code is in Dryad here https://datadryad.org/stash/downloads/file_stream/531722. The code is easy to follow and I am using it in one of my projects as well. 

Regarding use of RMA in testing for patterns of allometry in sexual dimorphism, the latter paper describes why it might not be a good approach. Further explanation is given here (https://link.springer.com/article/10.1007/s10682-021-10132-x), please message me individually if you need a copy. We justify the use of OLS for our dataset, and verify those results using phylogenetic regression while incorporating sampling error (http://www.phytools.org/static.help/pgls.Ives.html). It might be worth thinking about whether this is a useful approach for you.

Best,
Bryan



--
Dr. Bryan H. Juarez
He/They
NSF Postdoctoral Scholar
O'Connell and Hadly Labs
Biology Dept.
Stanford University



talijan...@gmail.com

unread,
Jul 15, 2022, 7:19:24 AM7/15/22
to geomorph R package
Dear all,

thank you for your suggestions and advice on the matter regarding analyzing sexual size dimorphism. I would look up the provision material that you provided and I will check up back again when I get something.

Sincerely,
Igor

Bassel Arnaout

unread,
Jun 27, 2023, 11:39:55 AM6/27/23
to geomorph R package

Hi everyone,

I am trying to perform a phenotypic trajectory analysis and i am having trouble.

I am comparing shape change during ontogeny of different species and I only have one shape for each trajectory point for each species.

Picture2.png

 

From Esquerre et al., 2017          

 

I read the conversations on PTA and I suspected that the issue is not having multiple replicates per trajectory point for each taxon. I tried using a similar method to the motion.path example and I keep getting this error:

gdf <- geomorph.data.frame(coords = gpa$coords, CS= gpa$Csize, age=age, taxons = taxons, families = families )

fit <- procD.lm(coords ~ log10(CS)+taxons, data = gdf, iter = 999, turbo = TRUE, RRPP = TRUE, print.progress = T)

##taxons and age are both factors.

TA <- trajectory.analysis(fit, groups = gdf$taxons, traj.pts = 2, pca = T)

Error in trajectory.analysis(fit, groups = gdf$taxons, traj.pts = 2, pca = T) :

  The number of variables divided by the number of trajectory points is not an integer

 

I would really appreciate any help!

Adams, Dean [EEOB]

unread,
Jun 27, 2023, 12:12:55 PM6/27/23
to geomorph-...@googlegroups.com

Unfortunately, you do not have the required replication to perform the test (or any test really).

 

For trajectory analysis, you either need multiple individuals per level to define each trajectory (as described in the original Collyer and Adams 2007 procedure), or you require multiple, replicate full trajectories in each group (as described in the Adams and Cerney 2007 motion trajectory procedure). Either way, one requires replication of trajectory units or individuals used to describe those units.

 

From your email, it seems you have a single juvenile and a single adult per species ‘trajectory’.  With this, all one can do is draw lines between Juv—Adult in morphospace to visualize ontogeny. But statistical tests like those in trajectory analysis are not possible, as there is no replication in the study design. As with all statistical analyses, trajectory analysis requires replication to estimate variation against which observed patterns may be compared.

 

Sorry.

 

Dean

 

Dr. Dean C. Adams (he/him)

Distinguished Professor of Evolutionary Biology

Department of Ecology, Evolution, and Organismal Biology

From: geomorph-...@googlegroups.com <geomorph-...@googlegroups.com> On Behalf Of Bassel Arnaout
Sent: Tuesday, June 27, 2023 5:40 PM
To: geomorph R package <geomorph-...@googlegroups.com>
Subject: Re: [geomorph-r-package] Phenotypic Trajectory Analysis

 

Hi everyone,

Bassel Arnaout

unread,
Jul 5, 2023, 12:26:26 PM7/5/23
to geomorph R package
Thank you Dean!

Since I can't use any statistical test. Is there a way to calculate the length and angles of these lines? I tried using procD.lm with adult and juvenile categories - but It didn't give me the vectors. Is there a way to extract these ontogenetic vectors without using CSize?

Many Thanks,

Bassel

Adams, Dean [EEOB]

unread,
Jul 6, 2023, 4:19:17 AM7/6/23
to geomorph-...@googlegroups.com

Yes, using a combination of various functions and some home-grown (read ugly!) code.  Here is a simple example for 2 vectors.

 

Dean

 

library(geomorph)

 

## Simulate some triangles: 1 per group

Y <- arrayspecs(matrix(rnorm(24), nrow = 4), p=3, k=2)

shape <- gpagen(Y)$coords

X <- gl(2,2)

sex <- factor(c(1,2,1,2))

gp <- interaction(X,sex)

 

# # Fit model

fit <- procD.lm(shape~X*sex)

PW <- pairwise(fit, groups = gp)

 

#vector lengths (elements 1,3 & 2,4)

PW$means.dist[[1]] 

 

# vector angles

acos(RRPP:::vec.cor.matrix(rbind(PW$LS.means[[1]][1,]-PW$LS.means[[1]][3,],

    PW$LS.means[[1]][2,]-PW$LS.means[[1]][4,])))*180/pi

Bassel Arnaout

unread,
Jul 11, 2023, 1:43:06 PM7/11/23
to geomorph R package
Thank you so much dan!

just to make sure I understand the code correctly:
PW$means.dist[[1]] 

produces the distance between every member of the gp interaction. So I have to connect the right X variable with the proper sex. In terms of my question, this function measures the distance between every adult and hatchling of all the species and I have to find the distance between the adult and hatchling belonging to the same species?

acos(RRPP:::vec.cor.matrix(rbind(PW$LS.means[[1]][1,]-PW$LS.means[[1]][3,],

    PW$LS.means[[1]][2,]-PW$LS.means[[1]][4,])))*180/pi


I couldn't understand this function and so I couldn't adapt it. It seems to be subtracting between different values of the first iteration. I couldn't understand where would (x1-x2) and (y1-y2) be?

Many Thanks again,

Bassel

Adams, Dean [EEOB]

unread,
Jul 12, 2023, 1:51:24 AM7/12/23
to geomorph-...@googlegroups.com

…$means.dist is a distance matrix among group means for all groups in the interaction.

 

My code used the least-squares means for these. Subtracting one of those (e.g., males gp 1 – females gp 1) generates a sexual dimorphism vector. These are bound together in rowwise. Then, the correlation between those vectors is found, which is converted to an angle (mathematically, correlations are cosines of angles).

Reply all
Reply to author
Forward
0 new messages