df <- data.frame(CMS_1 = sample(2, replace = T, size = 10)-1,
CMS_2 = sample(2, replace = T, size = 10)-1,
CMS_3 = sample(2, replace = T, size = 10)-1,
CMS_4 = sample(2, replace = T, size = 10)-1,
CMS_5 = sample(2, replace = T, size = 10)-1,
CMS_6 = sample(2, replace = T, size = 10)-1,
CMS_7 = sample(2, replace = T, size = 10)-1,
CMS_8 = sample(2, replace = T, size = 10)-1,
CMS_9 = sample(2, replace = T, size = 10)-1,
CMS_10 = sample(2, replace = T, size = 10)-1,
CMS_11 = sample(2, replace = T, size = 10)-1,
CMS_12 = sample(2, replace = T, size = 10)-1,
CMS_13 = sample(2, replace = T, size = 10)-1,
CMS_14 = sample(2, replace = T, size = 10)-1,
disease_status = sample(2, replace = T, size = 10)-1)
“ CMS_1:CMS_14”是我感兴趣的用于提取主成分的二分变量。 “疾病状态”表示组成员身份,即受试者是否患有疾病。这是从四色相关矩阵产生主成分的代码。
library(psych)
library(factoextra)
library(FactoMineR)
df <- df %>% mutate_if(is.numeric, as.factor)
df_matrix<-data.matrix(df[,-15])
df_tetra<-tetrachoric(df_matrix)
res.pca <- PCA(df_tetra$rho, graph = FALSE)
如果我不喜欢“ res.pca”,它会说:
主成分分析(PCA)结果 对14个人进行了分析,由14个变量描述
我有兴趣为个人提取结果,以查看这些个人所属的群体是否对主要组成部分做出不同的贡献。如果我将原始数据集(df)传递给函数PCA(),则来自factoextra的函数get_pca_ind()和fviz_pca_ind()会起作用。但是,由于我使用了四色相关矩阵,因此将同一组变量(CMS_1:CSM_14)视为个体。实际上,正如我在上面写的,检查PCA()在四色矫正矩阵上的结果会带来:对14个人进行了分析,由14个变量描述。谢谢!