简体   繁体   中英

Error while using ace function of ape package

I am trying to reconstruct ancestral state of continuous characters. When I use the Ace function of ape package, there is an error message which reads :

Error in nlm(function(p) dev.BM(p), p = c(1, rep(mean(x), nb.node)), hessian = TRUE) : missing value in parameter In addition: Warning message: In mean.default(x) : argument is not numeric or logical: returning NA

Here is the code I used :

library(ape)
library(phylobase)
library(phytools)
tree <-read.nexus("data1.nexus")
plot(tree)
nodelabels()
a <- extract.clade(tree, node=91)
plot(a)
data<- read.csv("Character_data.csv")
col2=2
char=data[,c(col2)]
model1 <- ace(char,a,type="continuous", method = "ML")

The same data set when used for discrete characters, worked perfectly. Here is the dataset data Here is the tree file treefile

You have missing data which is causing your error. What you have to do is read the data indicating the missing data string, and then remove the missing data from both your dataframe and from your tree:

library(ape)
library(phylobase)
library(phytools)
tree <- read.nexus("data1.nexus")
plot(tree)
nodelabels()
data <- read.csv("Character_data.csv", na.strings="?", header=T)

missing <- which(is.na(data[,2]))

clade.full <- extract.clade(tree, node=91)
clade.notNA <- drop.tip(clade, rmv) #Remove the tip of the species(?) you don't have the data

plot(clade.full)
plot(clade.notNA) #Note this tree is not the same as the one above, it has less species(?)

char <- data[-missing,2] #Take the column 2 without the missing rows

model <- ace(char, b, type="continuous", method = "ML")

Remember: You're not analyzing all your data. These are the tips you removed:

> data[missing,1]
 [1] 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
[19] Mar_ors Apo_cra Pse_par Lep_sin Dis_spi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM