0

我正在尝试重建连续​​字符的祖先状态。当我使用 ape 包的 Ace 功能时,出现一条错误消息,内容如下:

nlm(function(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")

当用于离散字符时,相同的数据集工作得很好。这是数据集数据 这是树文件treefile

4

1 回答 1

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
于 2015-05-01T19:37:43.890 回答