Wednesday, March 7, 2012

Testing whether Pagel's lambda is different from 1.0

A phytools user asks:

Is there an easy way to use phylosig to test whether the fitted value of λ is significantly different from 1?

Indeed, this is possible to do using fitContinuous in the geiger package, as many readers probably realize. It is also possible to do this with functions entirely in the phytools package. This is how:

# assuming phylogeny in 'tree' and data in 'x'
mtree<-tree
mtree$mapped.edge<-matrix(mtree$edge.length,nrow(tree$edge),1)
colnames(mtree$mapped.edge)<-"1"
resBM<-brownie.lite(mtree,x)
resLambda<-phylosig(tree,x,method="lambda")
LR<-2*(resLambda$logL-resBM$logL1)
P<-pchisq(LR,df=1,lower.tail=F)


That's it!

5 comments:

  1. Hi Dr. Revell,

    I'm trying to follow your above example for a tree of eight bird species and data for their respective growth rates. The brownie.lite() function seems to run fine but phylosig() returns "Error in invCl %*% y : requires numeric/complex matrix/vector arguments." I have used the same tree and data with function pgls (in caper) without a problem. I realize this is not reproducible but I thought you might have an idea as to what I'm doing wrong?

    Many thanks,
    Maria

    ReplyDelete
    Replies
    1. Hi Maria, I came across the same problem. It can be circumvented with reducing the number of traits in your dataset. If you prune all but 2 traits, it runs fine. Might be a bug?!

      cheers,
      max

      Delete
  2. Hello. Is there also an easy way to test whether the fitted value of λ is significantly different from 0?

    Thank you for answering,
    René

    ReplyDelete
    Replies
    1. That's the default. Just set method="lambda" & test=TRUE.

      - Liam

      Delete
    2. Many thanks for the quick reply!

      Delete

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.