【问题标题】:Can I overlay the coordinates of variables of one PCA over the coordinates of individuals from a second PCA and still interprete the results?我可以将一个 PCA 的变量坐标覆盖在来自第二个 PCA 的个体坐标上并仍然解释结果吗?
【发布时间】:2019-01-02 06:47:09
【问题描述】:

我确实有两组数据:丰度数据和环境数据,需要在 PCA 中“链接”或“叠加”它们:

我想在 R 中进行 PCA,它给我个人 纤毛虫 物种作为个体,环境参数作为变量。 我所拥有的是两个不同的数据框。 “abundance”,其中给出了采样地点不同物种的丰度,并且 “环境”,其中给出了采样站点的环境参数。所以我在每个数据框中有一个共同的参数:网站! 如果我进行 PCA,我要么得到一个以站点为个体、以环境参数为变量的地块,要么得到一个以物种为个体、以站点为变量的地块。我需要的是通过参数站点链接数据集,以便我可以将纤毛虫物种作为个体和环境参数作为变量进行 PCA。所以我会以某种方式需要通过公共参数站点链接两个 PCA/数据帧。 到目前为止我所做的 - 我做了两个不同的 PCA 并记住了 PCA1 的个体(纤毛虫物种)的坐标和 PCA2 变量的坐标(环境参数)并将它们绘制成双标图 -> 该图正是我需要的,但它仍然可以解释为 PCA,所以数据框真的由站点参数链接吗? 还是只是简单地欺骗数据并失去可解释性?

我尝试的另一个选择是通过加权平均值(由现场纤毛虫的丰度加权)计算每个纤毛虫物种的环境参数,并在具有纤毛虫物种的数据框和环境参数的加权平均值上进行 PCA ...这行得通,但我认为我在这种方式上丢失了很多信息...你怎么看?

#Create random dataframe of abundance data, I am sure this can be done simpler and more elegant than this ;)
    species<-c("spec1", "spec2", "spec3", "spec 4", "spec 5", "spec 6", "spec7")
    site1<-c(2,4,19,34,3,6,9)
    site2<-c(5,8,9,12,0,1,1)
    site3<-c(23,56,7,1,1,1,2)
    site4<-c(4,6,2,8,5,1,7)
    abundance<-data.frame(species,site1,site2,site3,site4)
    rownames(abundance)<-abundance$species
    abundance<-abundance[,-1]
    #Create random dataframe of abundance data
    #environmental parameters of the sites
    X<-c("site1","site2","site3","site4")
    Temp<-c(24,24.5,23.5,25)
    Chla<-c(2.2,1.5,2.0,3.4)
    Plo<-c(1000,2000,1500,200)
    Plo2<-c(200,400,600,200)
    environment<-data.frame(X,Temp,Chla,Plo,Plo2)
    rownames(environment)<-environment$X
    environment<-environment[,-1]
    ###PCA on abundance data
    #hellinger pre-transformation of abundance data
    library(vegan)
    abu.h<-decostand(abundance,"hellinger")
    abu.h.pca<-prcomp(abu.h)
    envir.pca<-prcomp(environment,scale=TRUE)
    biplot(abu.h.pca)
    ##and now I would need to discard the sites vectors and overlay it with 
    #the environmental sites factors, due to my prof?
    #Graph of individuals 
    fviz_pca_ind(abu.h.pca) 
    ##get coordinates 
    library(factoextra)
    ind<-get_pca_ind(abu.h.pca) 
    head(ind$coord) 
    #x in biplot 
    ind<-ind$coord 
    ind<-ind[,1:2]
    ind 
    #y variables 
    # Extract the results for variables only

    vari<-get_pca_var(abu.h.pca) 
    var<-vari$coord 
    var<-var[,1:2] 
    var 
    biplot(ind, var, var.axes = TRUE) 

【问题讨论】:

  • 似乎更适合 CrossValidated.com,因为统计有效性问题比 SO 上的情况更受关注。
  • 非常感谢,这是个好建议!

标签: r pca


【解决方案1】:

我从未做过您所描述的事情,但我知道您可以在 nMDS 上通过矢量叠加来关联环境(非生物)数据。如果你能用 PCA 做到这一点,我不确定,但至少我的 PRIMER 手册提到使用欧几里德距离的非生物数据的 PCA 非常适合生物数据的 nMDS,这就是 PRIMER 的 BEST 函数的工作原理.但这不是 PRIMER。

请参阅vegan::envfit 函数。 intro vignette 简要介绍了它。 Vegan tutor covers it a bit more.

我转置了物种数据并使用了物种数据的 nMDS。

library(vegan)

species <-c ("spec1", "spec2", "spec3", "spec 4", "spec 5", "spec 6", "spec7")
site1 <- c(2,4,19,34,3,6,9)
site2 <- c(5,8,9,12,0,1,1)
site3 <- c(23,56,7,1,1,1,2)
site4 <- c(4,6,2,8,5,1,7)
abundance <- data.frame(species,site1,site2,site3,site4)
rownames(abundance) <- abundance$species
abundance <- abundance[,-1]
abundance <- t(abundance)

X <- c ("site1","site2","site3","site4")
Temp <- c(24,24.5,23.5,25)
Chla <- c(2.2,1.5,2.0,3.4)
Plo <- c(1000,2000,1500,200)
Plo2 <- c(200,400,600,200)
environment <- data.frame(X,Temp,Chla,Plo,Plo2)
rownames(environment) <- environment$X
environment <- environment[,-1]

AbEnvMDS <- metaMDS(abundance, k = 2)
AbEnvFit <- envfit(AbEnvMDS, environment)

plt <- plot(AbEnvMDS) # displays both sites (empty circles) and species (red +)
plt <- plot(AbEnvMDS, display = "species") # displays only species (red +)
plt
identify(plt, what = "species") # choose your points
plot(AbEnvFit) # overlays your environment

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 2017-01-21
    • 2016-08-16
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多