0

I'm trying to read in two dataframes into a comparitive object so I can plot them using pgls.

I'm not sure what the error being returned means, and how to go about getting rid of it.

My code:

library(ape)
library(geiger)
library(caper)

taxatree <- read.nexus("taxonomyforzeldospecies.nex")
LWEVIYRcombodata <- read.csv("LWEVIYR.csv")


LWEVIYRcombodataPGLS <-data.frame(LWEVIYRcombodata$Sum.of.percentage,OGT=LWEVIYRcombodata$OGT, Species=LWEVIYRcombodata$Species)

comp.dat <- comparative.data(taxatree, LWEVIYRcombodataPGLS, "Species")

Returns error:

> comp.dat <- comparative.data(taxatree, LWEVIYRcombodataPGLS, 'Species')
Error in if (tabulate(phy$edge[, 1])[ntips + 1] > 2) FALSE else TRUE : 
  missing value where TRUE/FALSE needed
Biomage
  • 344
  • 2
  • 18
  • Check the `?comparative.data` help page. The first parameter must be a phylogeny (an object of class "phylo"), not a data.frame. Those errors are because you are passing in the wrong type of object. – MrFlick Jun 12 '18 at 15:26
  • Nexus files are phylogenies, maybe it just doesn't accept that filetype though? – Biomage Jun 12 '18 at 15:34
  • You are right. I misread that. Sorry. It would be easier to say what's going in for sure with a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can run the code to see what's going on. Right not since we don't have the input files we just have to guess. – MrFlick Jun 12 '18 at 15:36

2 Answers2

0

This might come from your data set and your phylogeny having some discrepancies that comparative.data struggles to handle (by the look of the error message).

You can try cleaning both the data set and the tree using dispRity::clean.data:

library(dispRity)

## Reading the data
taxatree <- read.nexus("taxonomyforzeldospecies.nex")
LWEVIYRcombodata <- read.csv("LWEVIYR.csv")
LWEVIYRcombodataPGLS <- data.frame(LWEVIYRcombodata$Sum.of.percentage,OGT=LWEVIYRcombodata$OGT, Species=LWEVIYRcombodata$Species)

## Cleaning the data
cleaned_data <- clean.data(LWEVIYRcombodataPGLS, taxatree)

## Preparing the comparative data object
comp.dat <- comparative.data(cleaned_data$tree, cleaned_data$data, "Species")

However, as @MrFlick suggests, it's hard to know if that solves the problem without a reproducible example.

Thomas Guillerme
  • 1,747
  • 4
  • 16
  • 23
  • When trying to run this, I get : `Error in comparative.data(cleaned_data$tree, cleaned_data$data, "Species")` `:` `'cleaned_data$tree' not of class 'phylo'` Although that happens even if I use a newick tree, which does work with my original code, not sure what's going on here! – Biomage Jun 13 '18 at 08:31
  • You might have multiple trees in your newick file. Did you try `class(taxatree)` and `class(cleaned_data$tree)`? If they are `multiPhylo` you might want to select only the one tree (`one_tree <- cleaned_data$tree[[1]]`) or use a multiple tree approach (e.g. [mulTree](https://github.com/TGuillerme/mulTree)). – Thomas Guillerme Jun 13 '18 at 23:58
0

The error here is that I was using a nexus file, although ?comparitive.data does not specify which phylo objects it should use, newick trees seem to work fine, whereas nexus files do not.

Biomage
  • 344
  • 2
  • 18