trouble with extended pgls dataframe input

20 views
Skip to first unread message

Omar Mejía

unread,
May 23, 2025, 3:37:38 PMMay 23
to geomorph R package
Dear all,

I have a problem that surely has a simple solution, however, I struggle with the problem for a couple of days.

I have landmarks from 150 individuals belonging to 10 different species and I want to perform an extended phylogenetic anova. I notice that this analysis can be performed with the extended.pgls function, I run the pupfish.ws data without trouble, but, once I tried to reproduce the analysis with my data I received an error message.

Briefly, this is what I am doing:

1) Read my landmarks using the readland function (150 individuals)
1b) Make the Procrustes fit with gpagen
2) Create a factor called Species containing species names (match with the names in the tree)
3) Create a geomorph data frame merging landmarks and species
4) When I try to merge phylo class tree with my aforementioned geomorph data frame (gdf)  there is a warn that indicate me that the number of dimmensions are different, so I tried to build a rrpp dataframe turning my geomorph dataframe in a rrpp dataframe
5) I try to run the first lane of the code and get an error

I kindly appreciate your suggestions, I am not able to put the complete code or error message screenshot due that a colleague is trying to find a solution (without results after 2 hours :(

"fit <- extended.pgls(f1 = coords~Species * Sex + Population, data = pupfish.ws, species = "Species", phy = pupfish.ws$phy"

I try this code due that my phylogenetic tree is not part of the dataframe as in pupfish.ws

fit=extended.pgls(f1=coords~Species,data=gdf, species="Species", phy=phy)
I received an error message indicating me that my object is not a geomorph data frame or a list




Adams, Dean [EEOB]

unread,
May 24, 2025, 1:55:27 AMMay 24
to geomorph-...@googlegroups.com
When putting species into the data frame, try doing it like this:

species = as.matrix(species)

See if that resolves things

Dean


From: geomorph-...@googlegroups.com <geomorph-...@googlegroups.com> on behalf of Omar Mejía <posgradobio...@gmail.com>
Sent: Friday, May 23, 2025 9:37:37 PM
To: geomorph R package <geomorph-...@googlegroups.com>
Subject: [geomorph-r-package] trouble with extended pgls dataframe input
 
--
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, visit https://groups.google.com/d/msgid/geomorph-r-package/76daba91-38ee-4431-9362-97ec3ad9e948n%40googlegroups.com.

Omar Mejía

unread,
May 24, 2025, 8:08:44 PMMay 24
to geomorph-...@googlegroups.com
Dear Dean,

I kindly appreciate your soon answer, try your solution and others, but I am still stuck :(

This is what I tried:

#########################################################################
landmarks=readland.tps("landmarks.tps",readcurves = TRUE,specID="ID")
Procrustes=gpagen(landmarks)
#######################################################
species=read.csv("species.csv", header=T, row.names=1)
species=as.factor(species$species)
is.factor(species)
species2=as.matrix(species)
###############################################
phy=read.tree("phylo.tre")
######################################################################
If read species as factor:
df<-geomorph.data.frame(Procrustes,species=species)
df2=rrpp.data.frame(Procrustes,species=species)
Warning: "Error in rrpp.data.frame(Procrustes, species = species) :
  Some input is either dimensionless or inappropriate for data frames"
#########################################################
If read species as matrix
#############################################################
dfa<-geomorph.data.frame(Procrustes,species=species2)
df2a=rrpp.data.frame(Procrustes,species=species2)
Warning: "Error in rrpp.data.frame(Procrustes, species = species) :
  Some input is either dimensionless or inappropriate for data frames"
#####################################################
So, I cannot obtain a rrppdataframe directly, reading species
as factor or as a matrix
#################################################
So, lets try  to convert the geomorphdataframe into a rrpp.data.frame
#######################################################
rrdf=rrpp.data.frame(df)
rrdm=rrpp.data.frame(dfa)
####################################
class(rrdf)
[1] "rrpp.data.frame"
class(rrdm)
[1] "rrpp.data.frame"

Either as a factor or as a matrix both frames are a rrpp.data.frame
#####################################################
Try to include the tree in the data.frame
class(phy)
[1] "phylo"
####################################################
df3=rrpp.data.frame(rrdf,phy=phy)
Warning "Error in rrpp.data.frame(rrdf, phy = phy) :
  Some input is either dimensionless or inappropriate for data frames"

df4=rrpp.data.frame(rrdm,phy=phy)
Warning "Error in rrpp.data.frame(rrdf, phy = phy) :
  Some input is either dimensionless or inappropriate for data frames"

#### Then I guess that the problem arise when I try
to include the phylo object, so I convert into a df###
#######################################
tree_df <- fortify(phy)
##################################
df3=rrpp.data.frame(rrdf,phy=tree_df)
Warning"Error in rrpp.data.frame(rrdf, phy = tree_df) :
  Inputs have different numbers of observations"

df4=rrpp.data.frame(rrdm,phy=tree_df)
"Error in rrpp.data.frame(rrdm, phy = tree_df) :
  Inputs have different numbers of observations"

#########When I tried to merge phylo dataframe into the
original geomorph dataframe the same result###
df<-geomorph.data.frame(Procrustes,species=species,phy=tree_df)
##############################################
Finally, try to convert phylo in a matrix
capm=clade.matrix(phy)
> class(capm)
[1] "clade.matrix"

################Merge phylo matrix into rrpp.dataframe

df3=rrpp.data.frame(rrdf,phy=capm)
Warning"Error in rrpp.data.frame(rrdf, phy = capm) :
  Some input is either dimensionless or inappropriate for data frames"

Thanks in advance

Best regards

Omar





--
Omar Mejía G
Laboratorio de Variación Biológica y Evolución
Departamento de Zoología
Escuela Nacional de Ciencias Biológicas-IPN

Adams, Dean [EEOB]

unread,
May 25, 2025, 2:17:58 AMMay 25
to geomorph-...@googlegroups.com
Omar,

The phylogeny does not need to be in the data frame, and that would likely cause some challenges. Also, some of your calls to components were not correct (you need to specify the 'coords' and not just the gpagen object for instance). Please see the help file. 

Below is a simple worked example of assembling up the data frame correctly. As you can see, it runs.  Hope this helps!

Dean

###
library(geomorph)
data("pupfish.ws")

pupfish.ws$coords
pupfish.ws$Species
dim(pupfish.ws$Sex)

#Create a data frame from the components
gdf <- geomorph.data.frame(shape = pupfish.ws$coords, Sex = pupfish.ws$Sex,
                           Species = pupfish.ws$Species)

#run analysis
fit <- extended.pgls(shape ~ Species * Sex, data = gdf, 
                     species = "Species", phy = pupfish.ws$phy)
--
Dr. Dean C. Adams
Distinguished Professor
Department of Ecology, Evolution, and Organismal Biology
Iowa State University

Sent: Saturday, May 24, 2025 7:08 PM
To: geomorph-...@googlegroups.com <geomorph-...@googlegroups.com>
Subject: Re: [geomorph-r-package] trouble with extended pgls dataframe input
 

Mike Collyer

unread,
May 25, 2025, 9:45:11 AMMay 25
to geomorph R package
To expand on Dean’s comment, the reason both rrpp.data.frame and geomorph.data.frame exist is because the standard.data.frame objects need to be coercible to matrices and sometimes that is not ideal for RRPP and geomorph functions.  A data.frame object is actually just a list of vectors but whereas a list does not have to assure that vectors have the same length, a data.frame object does.  Something like an array of coordinates cannot be coerced into a vector for a data.frame object, so the geomorph.data.frame uses a different method of assessing the length of the object.  The data frames in RRPP and geomorph check the length of objects that compose the data frame.  If you have a phylogeny with N species and data for n observations, but N and n are not equal, trying to put the phylo object into the data frame will cause issues.

Mike

Omar Mejía

unread,
May 26, 2025, 10:06:23 AMMay 26
to geomorph-...@googlegroups.com
Dear Dean and Mike,

Kindly appreciate the time invested in answering my comment and for the full explanation. I read once again the data and follow Dean's suggestion of reading the classifier as matrix, also check once again that the names in classifier and tree were the same and notice a mistake. Once I correct the labels the analysis runs perfect

I am apologize for the inconvenience

Best regards

Omar

Adams, Dean [EEOB]

unread,
May 27, 2025, 12:21:35 PMMay 27
to geomorph-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages