[R] Difficulty in caper: Error in phy$node.label[which(newNb > 0) - Ntip]

David Winsemius dwinsemius at comcast.net
Fri Mar 8 08:24:57 CET 2013


On Mar 7, 2013, at 5:12 PM, Nicole Thompson wrote:

> Thank you, Peter, for your response.
> 
> I can see then that comparative.data() is performing some operation
> that calls an invalid subset of either my phylo or data file
> (mammaldata or mammaltree).
> 
> It would be helpful to understand what "newNb" is, as
> comparative.data() creates it while constructing the comparative
> dataset. I'm guessing Ntip is the taxa I've included in my mammaldata.
> Perhaps newNb is the number of nodes inside the mammaltree and the
> error occurs because the taxa and tree nodes don't match well?
> 
> If anyone has similar experience with comparative.data(), I would
> greatly appreciate your insight.

Questions about the code that are not explained by the commented source code (which may not be available unless you make specific efforts to retain comments)  are best posed to the package maintainer. If you are asking for advice from the mailing list, you should make the effort to construct a minimal example. I suspect that the examples in the help files do not throw the same error. 

-- 

David.

> 
> Thank you.
> Nicole
> 
> On Thu, Mar 7, 2013 at 12:35 PM, Peter Ehlers <ehlers at ucalgary.ca> wrote:
>> On 2013-03-06 07:49, Nicole Thompson wrote:
>>> 
>>> Hello,
>>> 
>>> I'm doing a comparative analysis of mammal brain and body size data.
>>> I'm following Charlie Nunn and Natalie Cooper's instructions for
>>> "Running PGLS in R using caper".
>>> 
>>> I run into the following error when I create my comparative dataset,
>>> combining my phylogenetic tree (mammaltree) and taxon measures
>>> (mammaldata):
>>> 
>>> "Error in phy$node.label[which(newNb > 0) - Ntip] : only 0's may be
>>> mixed with negative subscripts"
>>> 
>>> My full script is provided at the bottom.
>>> 
>>> I have looked at the caper manual by David Orme to understand how
>>> comparative.data() constructs the dataset, but still cannot interpret
>>> the error. Many thanks to anyone who could provide me with insight.
>>> 
>>> Nicole Thompson
>>> E3B Columbia University
>>> 
>>> 
>>> 
>>>> library(caper)
>>> 
>>> 
>>> Loading required package: ape
>>> 
>>> Loading required package: MASS
>>> 
>>> Loading required package: mvtnorm
>>> 
>>>> 
>>> 
>>>> mammaldata <-read.csv("R.Mammal_data.csv", header = TRUE)
>>> 
>>> 
>>>> mammaltree <-read.nexus("BEphylotree.nex")
>>> 
>>> 
>>>> mammal <- comparative.data(phy = mammaltree, data = mammaldata, names.col
>>>> = Taxon, vcv = TRUE, na.omit = FALSE, warn.dropped = TRUE) #names.col?
>>> 
>>> 
>>> Error in phy$node.label[which(newNb > 0) - Ntip] : only 0's may be
>>> mixed with negative subscripts
>> 
>> 
>> Looks to me like 'which(newNb > 0) - Ntip' evaluates to a
>> vector that has both positive and negative elements.
>> Like this:
>> 
>>  x <- 1:5
>>  x[c(-2,-4)] ## ok
>>  x[c(-2, 0)] ## ok
>>  x[c(-2, 4)] ## generates your error
>> 
>> Peter Ehlers
>> 
>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> --
>>> Nicole A Thompson
>>> E3B Columbia University, NYCEP
>>> nat2103 at columbia.edu
>>> 480.522.4212
>>> 
>> 
> 
> 
> 
> --
> Nicole A Thompson
> E3B Columbia University, NYCEP
> nat2103 at columbia.edu
> 480.522.4212
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list