PCA - 从 R 中的 Communalities table 中提取低于某个阈值的变量
PCA - Extract variables falling below a certain threshold from the Communalities table in R
我是新来的,仍在学习如何正确使用 R,但我发现自己需要一些专家的帮助。我目前正在使用包 EFA.dimensions
来做我的 PCA。为此,我的脚本如下所示:
PCA(data, corkind='pearson', Nfactors=11, Ncases=NULL)
从出现在结果中的“公性”table(如下图所示),我想提取那些提取公性低于 0.80[的变量列表。在所示示例中,只有一个变量“ZLocomotionSocial”,但我有另一个数据集,它最终可能包含许多变量,所以最好不要一个一个地寻找它们。如果有帮助,最后的 objective 是从“数据”中删除这些变量,然后重新 运行 PCA。
Communalities table example
关于我可以使用哪些代码来解决这个问题有什么建议吗?
您可以转换数据框中的 communalities
对象,然后使用 dplyr
包进行一些基本过滤:
library(tidyverse)
library(EFA.dimensions)
communalities <-
data_Harman %>%
PCA(Nfactors=3, corkind = "pearson") %>%
pluck("communalities") %>%
as_tibble(rownames = "variable")
#>
#> Ncases must be provided when data is a correlation matrix.
#>
#>
#> Principal Components Analysis
#>
#> Specified kind of correlations for this analysis: from user
#>
#> The specified number of factors to extract = 3
#>
#> Model Fit Coefficients:
#>
#> RMSR = 0.046
#>
#> GFI = 0.993
#>
#> CAF = 0.5
#>
#>
#> Eigenvalues and factor proportions of variance:
#> Eigenvalues Proportion of Variance Cumulative Prop. Variance
#> Factor 1 4.67 0.58 0.58
#> Factor 2 1.77 0.22 0.81
#> Factor 3 0.48 0.06 0.87
#> Factor 4 0.42 0.05 0.92
#> Factor 5 0.23 0.03 0.95
#> Factor 6 0.19 0.02 0.97
#> Factor 7 0.14 0.02 0.99
#> Factor 8 0.10 0.01 1.00
#>
#> Unrotated PCA Loadings:
#> Factor 1 Factor 2 Factor 3
#> Height -0.86 -0.37 -0.07
#> Arm.span -0.84 -0.44 0.08
#> Forearm -0.81 -0.46 0.01
#> Leg.length -0.84 -0.40 -0.10
#> Weight -0.76 0.52 -0.15
#> Hips -0.67 0.53 -0.05
#> Chest.girth -0.62 0.58 -0.29
#> Chest.width -0.67 0.42 0.59
#>
#> Promax Rotation Pattern Matrix:
#> Factor 1 Factor 2 Factor 3
#> Height -0.92 0.10 -0.05
#> Arm.span -0.95 -0.10 0.12
#> Forearm -0.95 -0.07 0.02
#> Leg.length -0.93 0.10 -0.10
#> Weight -0.07 0.87 0.06
#> Hips 0.01 0.75 0.17
#> Chest.girth 0.06 0.99 -0.13
#> Chest.width 0.00 0.07 0.94
#>
#> Promax Rotation Structure Matrix:
#> Factor 1 Factor 2 Factor 3
#> Height -0.94 0.44 0.37
#> Arm.span -0.95 0.35 0.42
#> Forearm -0.93 0.33 0.35
#> Leg.length -0.93 0.42 0.32
#> Weight -0.45 0.93 0.61
#> Hips -0.36 0.85 0.62
#> Chest.girth -0.30 0.89 0.44
#> Chest.width -0.40 0.64 0.99
#>
#> Eigenvalues and factor proportions of variance:
#> Eigenvalues Proportion of Variance Cumulative Prop. Variance
#> Factor 1 3.51 1.17 1.17
#> Factor 2 2.33 0.78 1.95
#> Factor 3 0.96 0.32 2.27
#>
#> Promax Rotation Factor Correlations:
#> Factor 1 Factor 2 Factor 3
#> Factor 1 1.00 -0.41 -0.39
#> Factor 2 -0.41 1.00 0.60
#> Factor 3 -0.39 0.60 1.00
communalities
#> # A tibble: 8 x 2
#> variable Communalities
#> <chr> <dbl>
#> 1 Height 0.882
#> 2 Arm.span 0.909
#> 3 Forearm 0.872
#> 4 Leg.length 0.871
#> 5 Weight 0.872
#> 6 Hips 0.742
#> 7 Chest.girth 0.803
#> 8 Chest.width 0.975
selected_communalities <-
communalities %>%
filter(Communalities < 0.8)
selected_communalities
#> # A tibble: 1 x 2
#> variable Communalities
#> <chr> <dbl>
#> 1 Hips 0.742
selected_variables <- selected_communalities$variable
selected_variables
#> [1] "Hips"
由 reprex package (v2.0.1)
于 2021-09-10 创建
我是新来的,仍在学习如何正确使用 R,但我发现自己需要一些专家的帮助。我目前正在使用包 EFA.dimensions
来做我的 PCA。为此,我的脚本如下所示:
PCA(data, corkind='pearson', Nfactors=11, Ncases=NULL)
从出现在结果中的“公性”table(如下图所示),我想提取那些提取公性低于 0.80[的变量列表。在所示示例中,只有一个变量“ZLocomotionSocial”,但我有另一个数据集,它最终可能包含许多变量,所以最好不要一个一个地寻找它们。如果有帮助,最后的 objective 是从“数据”中删除这些变量,然后重新 运行 PCA。
Communalities table example
关于我可以使用哪些代码来解决这个问题有什么建议吗?
您可以转换数据框中的 communalities
对象,然后使用 dplyr
包进行一些基本过滤:
library(tidyverse)
library(EFA.dimensions)
communalities <-
data_Harman %>%
PCA(Nfactors=3, corkind = "pearson") %>%
pluck("communalities") %>%
as_tibble(rownames = "variable")
#>
#> Ncases must be provided when data is a correlation matrix.
#>
#>
#> Principal Components Analysis
#>
#> Specified kind of correlations for this analysis: from user
#>
#> The specified number of factors to extract = 3
#>
#> Model Fit Coefficients:
#>
#> RMSR = 0.046
#>
#> GFI = 0.993
#>
#> CAF = 0.5
#>
#>
#> Eigenvalues and factor proportions of variance:
#> Eigenvalues Proportion of Variance Cumulative Prop. Variance
#> Factor 1 4.67 0.58 0.58
#> Factor 2 1.77 0.22 0.81
#> Factor 3 0.48 0.06 0.87
#> Factor 4 0.42 0.05 0.92
#> Factor 5 0.23 0.03 0.95
#> Factor 6 0.19 0.02 0.97
#> Factor 7 0.14 0.02 0.99
#> Factor 8 0.10 0.01 1.00
#>
#> Unrotated PCA Loadings:
#> Factor 1 Factor 2 Factor 3
#> Height -0.86 -0.37 -0.07
#> Arm.span -0.84 -0.44 0.08
#> Forearm -0.81 -0.46 0.01
#> Leg.length -0.84 -0.40 -0.10
#> Weight -0.76 0.52 -0.15
#> Hips -0.67 0.53 -0.05
#> Chest.girth -0.62 0.58 -0.29
#> Chest.width -0.67 0.42 0.59
#>
#> Promax Rotation Pattern Matrix:
#> Factor 1 Factor 2 Factor 3
#> Height -0.92 0.10 -0.05
#> Arm.span -0.95 -0.10 0.12
#> Forearm -0.95 -0.07 0.02
#> Leg.length -0.93 0.10 -0.10
#> Weight -0.07 0.87 0.06
#> Hips 0.01 0.75 0.17
#> Chest.girth 0.06 0.99 -0.13
#> Chest.width 0.00 0.07 0.94
#>
#> Promax Rotation Structure Matrix:
#> Factor 1 Factor 2 Factor 3
#> Height -0.94 0.44 0.37
#> Arm.span -0.95 0.35 0.42
#> Forearm -0.93 0.33 0.35
#> Leg.length -0.93 0.42 0.32
#> Weight -0.45 0.93 0.61
#> Hips -0.36 0.85 0.62
#> Chest.girth -0.30 0.89 0.44
#> Chest.width -0.40 0.64 0.99
#>
#> Eigenvalues and factor proportions of variance:
#> Eigenvalues Proportion of Variance Cumulative Prop. Variance
#> Factor 1 3.51 1.17 1.17
#> Factor 2 2.33 0.78 1.95
#> Factor 3 0.96 0.32 2.27
#>
#> Promax Rotation Factor Correlations:
#> Factor 1 Factor 2 Factor 3
#> Factor 1 1.00 -0.41 -0.39
#> Factor 2 -0.41 1.00 0.60
#> Factor 3 -0.39 0.60 1.00
communalities
#> # A tibble: 8 x 2
#> variable Communalities
#> <chr> <dbl>
#> 1 Height 0.882
#> 2 Arm.span 0.909
#> 3 Forearm 0.872
#> 4 Leg.length 0.871
#> 5 Weight 0.872
#> 6 Hips 0.742
#> 7 Chest.girth 0.803
#> 8 Chest.width 0.975
selected_communalities <-
communalities %>%
filter(Communalities < 0.8)
selected_communalities
#> # A tibble: 1 x 2
#> variable Communalities
#> <chr> <dbl>
#> 1 Hips 0.742
selected_variables <- selected_communalities$variable
selected_variables
#> [1] "Hips"
由 reprex package (v2.0.1)
于 2021-09-10 创建