使用ape包的ace功能时出错

时间:2015-05-01 18:47:35

标签: r phylogeny

我正在尝试重建连续​​字符的祖先状态。当我使用ape包的Ace函数时,会出现一条错误消息:

  

nlm中的错误(函数(p)dev.BM(p),p = c(1,rep(mean(x),nb.node)),hessian = TRUE):     参数中缺少值   另外:警告信息:   在mean.default(x)中:参数不是数字或逻辑:返回NA

以下是我使用的代码:

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")

用于离散字符的相同数据集完美运行。 这是数据集data 这是树文件treefile

1 个答案:

答案 0 :(得分:1)

您缺少导致错误的数据。您需要做的是读取指示缺少数据字符串的数据,然后从数据框和树中删除缺少的数据:

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")

请记住:您并未分析所有数据。这些是您删除的提示:

> 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