首页 > 解决方案 > 从两个数据框创建 R 中的比较对象以进行比较系统发育

问题描述

我正在尝试将两个数据帧读入一个比较对象,以便我可以使用 pgls 绘制它们。

我不确定返回的错误是什么意思,以及如何摆脱它。

我的代码:

library(ape)
library(geiger)
library(caper)

taxatree <- read.nexus("taxonomyforzeldospecies.nex")
LWEVIYRcombodata <- read.csv("LWEVIYR.csv")


LWEVIYRcombodataPGLS <-data.frame(LWEVIYRcombodata$Sum.of.percentage,OGT=LWEVIYRcombodata$OGT, Species=LWEVIYRcombodata$Species)

comp.dat <- comparative.data(taxatree, LWEVIYRcombodataPGLS, "Species")

返回错误:

> comp.dat <- comparative.data(taxatree, LWEVIYRcombodataPGLS, 'Species')
Error in if (tabulate(phy$edge[, 1])[ntips + 1] > 2) FALSE else TRUE : 
  missing value where TRUE/FALSE needed

标签: rdataframephylogeny

解决方案


这可能来自您的数据集和您的系统发育有一些comparative.data难以处理的差异(通过错误消息的外观)。

您可以尝试使用以下方法清理数据集和树dispRity::clean.data

library(dispRity)

## Reading the data
taxatree <- read.nexus("taxonomyforzeldospecies.nex")
LWEVIYRcombodata <- read.csv("LWEVIYR.csv")
LWEVIYRcombodataPGLS <- data.frame(LWEVIYRcombodata$Sum.of.percentage,OGT=LWEVIYRcombodata$OGT, Species=LWEVIYRcombodata$Species)

## Cleaning the data
cleaned_data <- clean.data(LWEVIYRcombodataPGLS, taxatree)

## Preparing the comparative data object
comp.dat <- comparative.data(cleaned_data$tree, cleaned_data$data, "Species")

但是,正如@MrFlick 所建议的那样,如果没有可重复的示例,很难知道这是否能解决问题。


推荐阅读