使用 ape 包的 ace 函数时出错
Error while using ace function of ape package
我正在尝试重建连续字符的祖先状态。当我使用 ape 包的 Ace 功能时,有一条错误消息显示为:
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
这是我使用的代码:
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")
您缺少导致错误的数据。您需要做的是读取指示缺失数据字符串的数据,然后从数据框和树中删除缺失数据:
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
我正在尝试重建连续字符的祖先状态。当我使用 ape 包的 Ace 功能时,有一条错误消息显示为:
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
这是我使用的代码:
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")
您缺少导致错误的数据。您需要做的是读取指示缺失数据字符串的数据,然后从数据框和树中删除缺失数据:
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