Search code examples
rlinear-regressionphylogeny

Error message for one model when trying to run two almost identical pgls models


I'm trying to create a model using the pgls() function in the package caper to look at the impact of feeding style on shape. The model below works:

latdata <- comparative.data(lattree, lat, Species, vcv=TRUE, vcv.dim=3)
latpigot <- pgls(PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 ~ Feeding, latdata, lambda = 'ML')

Where lattree is my phylogenetic tree, lat is my dataset and Species, the PCs and Feeding are the names of columns in my dataset. The PCs are numerical variables with positive and negative values. Species and Feeding are categorical variables.

But when I try the same code with a new dataset and new tree it does not work and I get an error:

vendata <- comparative.data(ventree, ven, Species, vcv=TRUE, vcv.dim=3)
venpigot <- pgls(PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 ~ Feeding, vendata, lambda = 'ML')

Error in pgls(PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 ~ Feeding, vendata,  : 
  Problem with optim:52ERROR: ABNORMAL_TERMINATION_IN_LNSRCH

ven has 65 entries instead of the 66 in lat. The trees are the same except that one of the taxa in lattree is not in ventree.

From what I understand, the pgls() function has the optim() function somewhere in its code and that's what's causing the issues but I don't understand how the optim() function fits in and why it might be causing issues.

Does anyone have any ideas as to what might be going wrong?

Many thanks,

Carolina

EDIT: If I set lambda to 1, this seems to work. However, I don't know if this is right or how to decide on appropriate lambda value. Can anyone help with this?


Solution

  • I found this webpage:

    http://blog.phytools.org/2012/11/fitting-model-in-phylogenetic.html

    and used the ape and nlme packages to write a PGLS model using this code:

    venpigot <- gls(PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 ~ Pigot, ven, correlation = corPagel(1, ventree, fixed = FALSE), method = "ML")
    

    which seems to work.