我正在嘗試對宿主植物物種的昆蟲群落組成進行 permanova。無論我們嘗試了什么,它都不起作用,我不知道為什么不這樣做。我知道 permanova 可以處理零,但我們確實有很多,這可能是問題嗎?
我們收到此錯誤: if (any(lhs < -TOL)) stop("dissimilarities must be non-negative") 中的錯誤:需要 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()
這里的錯誤是:平方根變換威斯康星雙標準化cmdscale(dist,k = k)中的錯誤:'d'中不允許NA值另外:警告訊息:1:在distfun(comm,方法=距離,...) :您有空行:它們的差異在方法“bray”中可能毫無意義 2:在 distfun(comm, method = distance, ...) 中:結果中的缺失值
任何建議將不勝感激!
uj5u.com熱心網友回復:
您不能有檢測到零種的站點。制作社區資料矩陣后,您應該洗掉所有物種為零的行:
lilly.species <- lilly.species[rowSums(!lilly.species) < ncol(lilly.species), ]
然后所有剩余的代碼應該可以正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/468218.html
