r语言 - Permanova 错误与 metaMDS 的 adonis 和 ggplot2 错误



我正在尝试对宿主植物物种的昆虫群落组成进行持续分析。不管我们怎么努力,都行不通,我不明白为什么不行。我知道珀曼诺瓦可以处理零,但我们确实有很多,这是问题吗?

我们收到这个错误:if (any(lhs <)-TOL)) stop(" dissimilarity必须是非负的"):需要TRUE/FALSE的缺失值

下面是我们的尝试:

library(vegan)
#insect community composition on 3 different species of milkweed
lilly.data<-read.csv("https://raw.githubusercontent.com/lmgermeroth/Garden-sampling-SU21/main/backyard2021_main_forR.4.22.22.csv")
lilly.data$SPECIES<-as.factor(lilly.data$SPECIES)
# creating a species data matrix so I can tell the model how to calculate the community composition, but first, make them numeric.
lilly.data[6:151] <- lapply(lilly.data[6:152], as.numeric)
#Create the matrix of insect species
lilly.species<-as.matrix(lilly.data[,8:152])
lilly.dist<-vegdist(lilly.species,"bray")
#get a warning.....but it runs
lilly.permanova<-adonis2(lilly.dist ~ SPECIES,permutations=999,method='bray',data=lilly.data)
# why doesn't this work?

第二,我们正在尝试创建一个排序图,但这也行不通,我们不确定为什么。可能与上述问题有关?

library(ggplot2)
ord<-metaMDS(lilly.species)
#this is where we throw the error....
scores<-scores(ord,display='sites')
scores<-cbind(as.data.frame(scores), Treatment=lilly.data$SPECIES)
center<-aggregate(cbind(NMDS1,NMDS2)~Treatment,data=scores,FUN=mean)
seg<-merge(scores,setNames(center,c('Species','oNMDS1','oNMDS2')),by='Treatment',sort=FALSE)
ggplot(scores,aes(x=NMDS1,y=NMDS2,colour=Treatment))+
geom_segment(data=seg,
mapping=aes(xend=oNMDS1,yend=oNMDS2))+
geom_point(data=cent,size=8)+
geom_point()+
coord_fixed()

这里的错误是:平方根变换威斯康辛双重标准cmd (dist, k = k)中的错误:'d'中不允许有NA值警告信息:在distfun(comm, method = distance,…)中:您有空行:它们的不同之处在方法"bray"中可能毫无意义。2:在distfun(comm, method = distance,…)中:结果中缺少值

任何建议将不胜感激!

不可能有零物种被检测到的站点。在您创建了您的社区数据矩阵之后,您应该删除任何没有物种的行:

lilly.species <- lilly.species[rowSums(!lilly.species) < ncol(lilly.species), ]

那么所有剩下的代码应该都能正常工作。

最新更新