簡體   English   中英

在R中為純素NMDS准備數據

[英]preparing data for vegan NMDS in R

我想在R中使用純素對數據子集運行NMDS和PERMANOVA。我的數據包含很多零,看起來像這樣:

> str(invert)
'data.frame':   96 obs. of  67 variables:
 $ SampleID                       : Factor w/ 96 levels "11-1-E-1","11-1-E-2",..: 61 62 63 49 50 51 85 86 87 73 ...
 $ SampleDate                     : Factor w/ 8 levels "17-Aug-12","17-Oct-12",..: 1 1 1 6 6 6 2 2 2 4 ...
 $ Year                           : int  2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ...
 $ Month                          : Factor w/ 4 levels "August","July",..: 1 1 1 2 2 2 3 3 3 4 ...
 $ Habitat                        : Factor w/ 4 levels "epiphyte","pool",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ N                              : num  1429 143 1705 1147 212 ...
 $ S                              : int  6 2 8 9 4 5 6 8 5 5 ...
 $ Aeshnidae                      : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Aeshnidae..Anax                : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Aeshnidae..Gynacantha          : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Aeshnidae..Oplonaeschna        : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Anisoptera                     : int  0 0 0 0 0 0 0 0 0 0 ...
 $ ant                            : num  0 0 0 0 0 0 0 0 0 0 ...

如您所見,“人居”分為四個級別。 我想分別分析每個棲息地。 我嘗試了子集化,但這意味着我必須做四次(每個棲息地一個)。 有更有效的方法嗎?

這就是我為泳池棲息地分配的方式:

invert[6:67] <- lapply(invert[6:67], as.numeric)
pool <- subset(invert, Habitat=="pool")

ord <- metaMDS(pool[,7:67], 
               k=2, 
               trymax = 1000, 
               autotransform = TRUE, 
               expand = FALSE, 
               plot = FALSE)

plot(ord$points[,2],ord$points[,1], type="n",
     main="Communities by month", 
     xlab="NMDS 1",
     ylab="NMDS 2", 
     xlim=c(-1.5,1.5), 
     ylim=c(-1.5,1.5))
ordisymbol(ord, pool, factor="Month", cex=1.25, rainbow=T, legend=T)

#run PERMANOVA;
adonis(pool[,8:67] ~ pool$Month)

您應該以矩陣形式為nmds運行所有物種x站點,然后創建一個組對象,指定哪些行來自哪個棲息地。 例如,如果矩陣的前6行來自城市化地區,然后接下來的6行來自雨林,我將創建一個分組對象,如下所示:

habitattypes<-c(rep("Urbanized",16), rep("RainForest",16))
Permanova<-adonis(yourdata^0.25~habitattypes, permutations = 999, method = "bray")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM