我正在尝试使用PCoA进行特质分析。根据Laliberté& Legendre(2010)这是一个合适的工具,因为它可以处理不同尺度类型的缺失值和特征。
首先我创建了一个物种x特征矩阵。然后我计算了一个关于特征的不同权重的距离矩阵,因为一个特征被分成三个。由于距离矩阵包含负特征值,我使用'lingoes'校正来计算PCoA。现在我想绘制PCoA。
到目前为止,我设法做到了两者中的任何一个。 (PCoA具有不同的功能,导致相同的结果)。
library(FD)
# species-traits data frame
df <- data.frame(row.names= c( "Sp1", "Sp2", "Sp3", "Sp4", "Sp5", "Sp6", "Sp7", "Sp8", "Sp9", "Sp10"),
"Height" = c( 10.5, NA, 36.8, 1504.7, 120.4, 85.9, 26.1, NA, 39.2, 142.8),
"Seed" = c( 456, 852, 302, 10, 400, 1190, 758, 56, 487, NA),
"Anemo" = c( 1, 0, 1, 0, 1, 1, 1, 0, 0, 1),
"Zoo" = c( 0, 0, 0, 1, 1, 0, 0, 1, 0, 1),
"Ballo" = c( 0, 1, 0, 0, 0, 0, 1, 0, 1, 0),
"Indicat"= c( 5, 4, 5, 6, 2, 3, 5, 6, 4, 5))
# species abundance
abun <- c(0.005, 0.005, 0.05, 0.43, 0.05, 0.095, 0.005, 0.05, 0.01, 0.3)
# weights
w <- c(1, 1, 1/3, 1/3, 1/3, 1)
# distance matrix
dist <- gowdis(df, w) # FD package
is.euclid(dist) # distance matrix is not euclidean - negative Eigenvalues!
# PCoA
pcoa1 <- wcmdscale(d = dist, eig = TRUE, add = "lingoes") # vegan package
plot(pcoa1)
plot(pcoa1, type = "points", cex = log10(abun*1000))
pcoa2 <- pcoa(dist, correction = "lingoes") # ape package
biplot.pcoa(pcoa2, df, dir.axis1 = -1)
我的问题是:
当我使用plot()
函数时,我无法添加特征向量,也无法更改任何简单的图形参数,例如pch
或col
。
当我使用biplot.pcoa
特征时,conatain NAs
不会显示为矢量,我也无法用点大小来说明相对丰度。
PCoA也适用于非数字特征。但是,在这种情况下,biplot.pcoa
,
e.g:
# species-traits data frame
df <- data.frame(row.names= c( "Sp1", "Sp2", "Sp3", "Sp4", "Sp5", "Sp6", "Sp7", "Sp8", "Sp9", "Sp10"),
"Height" = c( 10.5, NA, 36.8, 1504.7, 120.4, 85.9, 26.1, NA, 39.2, 142.8),
"Seed" = c( 456, 852, 302, 10, 400, 1190, 758, 56, 487, NA),
"Anemo" = c( 1, 0, 1, 0, 1, 1, 1, 0, 0, 1),
"Zoo" = c( 0, 0, 0, 1, 1, 0, 0, 1, 0, 1),
"Ballo" = c( 0, 1, 0, 0, 0, 0, 1, 0, 1, 0),
"Indicat"= c( 5, 4, 5, 6, 2, 3, 5, 6, 4, 5),
"Polli" = c("wind", "insect", NA, "wind", "insect","insect", "wind", "wind", "wind", "insect"))
# weights
w <- c(1, 1, 1/3, 1/3, 1/3, 1, 1)
dist <- gowdis(df, w)
pcoa2 <- pcoa(dist, correction = "lingoes")
biplot.pcoa(pcoa2, dir.axis1 = -1)
biplot.pcoa(pcoa2, df, dir.axis1 = -1)
Error: is.numeric(x) || is.logical(x) is not TRUE
Borcard,Gillet&amp; Legendre 2011 数值生态学与R
Laliberté&amp; Legendre 2010 基于距离的框架,用于衡量多种特征的功能多样性