0

I get an error while using the ARD model of the ace function in R. The error is

Error in floating.pie.asp(XX[i], YY[i], pie[i, ], radius = xrad[i], col = piecol) : floating.pie: x values must be non-negative

library(ape)
library(phylobase)
tree <- read.nexus("data1.nexus")
plot(tree)
data <- read.csv("phagy_species.csv")
clade.full <- extract.clade(tree, node=91)
plot(clade.full)
clade.1 <- drop.tip(clade.full, "Bar_bre")
clade.2<- drop.tip(clade.1, "Par_pho")
clade.3<- drop.tip(clade.2, "Par_iph")
clade.4<- drop.tip(clade.3, "Eur_ser")
clade.5<- drop.tip(clade.4, "Opo_sym")
clade.6<- drop.tip(clade.5, "Mor_pel")
clade.7<- drop.tip(clade.6, "Aph_hyp")
clade.8<- drop.tip(clade.7, "Ere_oem")
clade.9<- drop.tip(clade.8, "Cal_bud")
clade.10<- drop.tip(clade.9, "Lim_red")
clade.11<- drop.tip(clade.10, "Act_str")
clade.12<- drop.tip(clade.11, "Hel_hec")
clade.13<- drop.tip(clade.12,"Col_dir")
clade.14<- drop.tip(clade.13, "Hyp_pau")
clade.15<- drop.tip(clade.14, "Nym_pol")
clade.16<- drop.tip(clade.15, "Mel_cin")
clade.17<- drop.tip(clade.16,"Apa_iri")
clade.18<- drop.tip(clade.17, "Bib_hyp")
clade.19<- drop.tip(clade.18, "Mar_ors")
clade.20<- drop.tip(clade.19, "Apo_cra")
clade.21<- drop.tip(clade.20, "Pse_par")
clade.22 <- drop.tip(clade.21, "Lep_sin")
clade.23<- drop.tip(clade.22, "Dis_spi")
plot(clade.23)
data2 <- as.numeric(data[,2])
model2 <- ace(data2, clade.23, type="discrete", method="ML", model="ARD")
summary(model2)
d <-logLik(model2)
deviance(model2)
AIC(model2)
plot(clade.23, type="phylogram", cex=0.8, font=3, label.offset = 0.004)
co <- c("red", "blue", "green", "black")
nodelabels(pie = model2$lik.anc, piecol = co, cex = 0.5)

And that is when I get the error. There is no error if I use the original tree without trimming. But, when i trim them to my requirements, it goes in the negative.

Here is the data tree file

data file

C_Z_
  • 7,427
  • 5
  • 44
  • 81
user6385
  • 17
  • 1
  • 8
  • I also just want to point out that you don't need to drop tips one at a time and create a bunch of temporary trees. You can do everything in one step, like `clade <- drop.tip(clade, c("Bar_bre", "Par_pho", "Par_iph", "Eur_ser", "Opo_sym", "Mor_pel", "Aph_hyp", "Ere_oem", "Cal_bud", "Lim_red", "Act_str", "Hel_hec","Col_dir", "Hyp_pau", "Nym_pol", "Mel_cin","Apa_iri", "Bib_hyp", "Mar_ors", "Apo_cra", "Pse_par", "Lep_sin", "Dis_spi"))` – SlowLoris May 11 '16 at 05:53

3 Answers3

0

The matrix you are using for the proportions of the pie has complex numbers in it. To see this, try:

class(model2$lik.anc[1,1])

The rows of that matrix define the proportions of the pies, and they need to sum to 1. Your code produces a plot with pies if I replace the pie matrix in the nodelabels function like this:

nodelabels(pie = matrix(0.25, 64, 4), piecol = co, cex = 0.5)

because now there is a legitimate matrix for the pie argument with rows that sum to 1.

As for why you have complex numbers in that matrix, I am not sure. It is probably related to all the warnings produced by the ace in your example. But that is a completely different issue.

SlowLoris
  • 995
  • 6
  • 28
0

I had the same problem with my data. I put my data into the matrix (like Slow Ioris suggested) and then unlisted the matrix.

x <- matrix(data=c(model2$lik.anc[,1],model2$lik.anc[,2],model2$lik.anc[,3],model2$lik.anc[,4]))
plotTree(tree,ftype="i",label.offset = 0.02)
nodelabels(pie = unlist(x))
Nataliia
  • 1
  • 2
-1

For other people having the same problem also after purging imaginable parts of their data: The nodelabels function gives the same error when you provide a data.frame instead of a matrix to pie.

Peter Lyko
  • 61
  • 1
  • 6