【问题标题】:Error while using ace function of ape package使用ape包的ace函数时出错
【发布时间】:2015-05-01 18:47:35
【问题描述】:

我正在尝试重建连续​​字符的祖先状态。当我使用 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")

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

【问题讨论】:

    标签: r phylogeny


    【解决方案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
    

    【讨论】:

    • 难道没有一种方法可以让我保留丢失的分类群并仍然重建祖先的字符吗?如果我删除缺少数据的那些,树上的支持将受到其他分析的影响
    • 我不做系统发育学研究——我只知道它是什么,因为我上过一门课——但我不这么认为。您收到的消息来自nlm 的内部调用,这是一个将数据调整为线性模型的函​​数,您不能使用您没有的数据。即使可以,ace() 函数似乎也不支持这一点,所以我认为最好的情况是你必须找到一个替代方案。
    猜你喜欢
    • 1970-01-01
    • 2019-11-30
    • 1970-01-01
    • 2021-09-05
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多