library(readr)
## Warning: пакет 'readr' был собран под R версии 4.5.2
library(haven)
## Warning: пакет 'haven' был собран под R версии 4.5.2
psychosemantics = read_sav(file.choose())
library("factoextra")
## Warning: пакет 'factoextra' был собран под R версии 4.5.3
## Загрузка требуемого пакета: ggplot2
## Warning: пакет 'ggplot2' был собран под R версии 4.5.2
## Welcome to factoextra!
## Want to learn more? See two factoextra-related books at https://www.datanovia.com/en/product/practical-guide-to-principal-component-methods-in-r/
library("FactoMineR")
## Warning: пакет 'FactoMineR' был собран под R версии 4.5.3
head(psychosemantics)
## # A tibble: 6 × 29
## Group.1 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 "Я верующий" 4.14 4.17 4.15 4.13 4.03 3.99 3.68 3.66 3.88 3.84 3.88
## 2 "Я верю в Б… 3.95 3.96 3.84 3.77 3.77 3.66 3.65 3.62 3.61 3.41 3.57
## 3 "Не могу ск… 3.77 3.78 3.62 3.57 3.61 3.53 3.56 3.47 3.51 3.15 3.48
## 4 "Религия ме… 3.77 3.82 3.62 3.58 3.58 3.5 3.54 3.57 3.55 3.01 3.36
## 5 "Атеист" 3.65 3.66 3.46 3.37 3.42 3.34 3.46 3.46 3.52 2.88 3.38
## 6 "" NA NA NA NA NA NA NA NA NA NA NA
## # ℹ 17 more variables: d12 <dbl>, d13 <dbl>, d14 <dbl>, d15 <dbl>, d16 <dbl>,
## # d17 <dbl>, d18 <dbl>, d19 <dbl>, d20 <dbl>, d21 <dbl>, d22 <dbl>,
## # d23 <dbl>, d24 <dbl>, d25 <dbl>, d26 <dbl>, d27 <dbl>, d28 <dbl>
df_pca <- psychosemantics[, 2:29] |>
na.omit()
head(df_pca)
## # A tibble: 5 × 28
## d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 4.14 4.17 4.15 4.13 4.03 3.99 3.68 3.66 3.88 3.84 3.88 4.12 3.92
## 2 3.95 3.96 3.84 3.77 3.77 3.66 3.65 3.62 3.61 3.41 3.57 3.82 3.74
## 3 3.77 3.78 3.62 3.57 3.61 3.53 3.56 3.47 3.51 3.15 3.48 3.58 3.58
## 4 3.77 3.82 3.62 3.58 3.58 3.5 3.54 3.57 3.55 3.01 3.36 3.38 3.56
## 5 3.65 3.66 3.46 3.37 3.42 3.34 3.46 3.46 3.52 2.88 3.38 3.24 3.44
## # ℹ 15 more variables: d14 <dbl>, d15 <dbl>, d16 <dbl>, d17 <dbl>, d18 <dbl>,
## # d19 <dbl>, d20 <dbl>, d21 <dbl>, d22 <dbl>, d23 <dbl>, d24 <dbl>,
## # d25 <dbl>, d26 <dbl>, d27 <dbl>, d28 <dbl>
res.pca <- PCA(df_pca, scale.unit = TRUE, ncp = 10, graph = FALSE)
res.pca
## **Results for the Principal Component Analysis (PCA)**
## The analysis was performed on 5 individuals, described by 28 variables
## *The results are available in the following objects:
##
## name description
## 1 "$eig" "eigenvalues"
## 2 "$var" "results for the variables"
## 3 "$var$coord" "coord. for the variables"
## 4 "$var$cor" "correlations variables - dimensions"
## 5 "$var$cos2" "cos2 for the variables"
## 6 "$var$contrib" "contributions of the variables"
## 7 "$ind" "results for the individuals"
## 8 "$ind$coord" "coord. for the individuals"
## 9 "$ind$cos2" "cos2 for the individuals"
## 10 "$ind$contrib" "contributions of the individuals"
## 11 "$call" "summary statistics"
## 12 "$call$centre" "mean of the variables"
## 13 "$call$ecart.type" "standard error of the variables"
## 14 "$call$row.w" "weights for the individuals"
## 15 "$call$col.w" "weights for the variables"
eig.val <- get_eigenvalue(res.pca)
eig.val
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 26.6564125 95.201473 95.20147
## Dim.2 0.6583989 2.351425 97.55290
## Dim.3 0.3853713 1.376326 98.92922
## Dim.4 0.2998172 1.070776 100.00000
fviz_eig(res.pca)
Dim.1 - Первая компонента объясняет 95.16% всей дисперсии
var <- get_pca_var(res.pca)
var$cos2
## Dim.1 Dim.2 Dim.3 Dim.4
## d1 0.9920022 7.512859e-03 4.846272e-04 2.792986e-07
## d2 0.9715783 2.434915e-02 3.157367e-03 9.151640e-04
## d3 0.9865669 1.183584e-02 8.985623e-04 6.986687e-04
## d4 0.9726745 1.858830e-02 1.564499e-04 8.580740e-03
## d5 0.9876296 3.792345e-03 6.396848e-05 8.514120e-03
## d6 0.9684391 1.132474e-02 4.076494e-03 1.615964e-02
## d7 0.9087615 1.778220e-02 7.236522e-02 1.091108e-03
## d8 0.7844915 1.118055e-01 8.817434e-02 1.552870e-02
## d9 0.8295245 9.348212e-02 7.699061e-02 2.722233e-06
## d10 0.9910830 1.722032e-04 7.960591e-03 7.841723e-04
## d11 0.9201234 2.105130e-04 7.896614e-02 6.999854e-04
## d12 0.9830579 1.463210e-02 1.247632e-05 2.297536e-03
## d13 0.9970555 1.584494e-03 7.613095e-04 5.987272e-04
## d14 0.9453157 5.422697e-02 3.625433e-04 9.477724e-05
## d15 0.8837774 1.596541e-02 1.853977e-04 1.000718e-01
## d16 0.9804350 3.456143e-05 2.117068e-03 1.741334e-02
## d17 0.9749768 1.797049e-03 2.692909e-04 2.295688e-02
## d18 0.9356300 3.954195e-02 6.397095e-04 2.418834e-02
## d19 0.9765412 1.133557e-02 7.042130e-03 5.081131e-03
## d20 0.9789208 4.802887e-03 2.328486e-03 1.394781e-02
## d21 0.9888919 6.966535e-05 1.333841e-04 1.090506e-02
## d22 0.9704899 2.894814e-02 5.359329e-04 2.598955e-05
## d23 0.9399904 2.669771e-04 2.804512e-02 3.169754e-02
## d24 0.9542293 4.131735e-02 3.069888e-03 1.383438e-03
## d25 0.9974746 1.577278e-03 4.678359e-04 4.802580e-04
## d26 0.9984366 1.222361e-03 6.150676e-05 2.795057e-04
## d27 0.8731015 1.228358e-01 2.912814e-03 1.149915e-03
## d28 0.9652135 1.738458e-02 3.132087e-03 1.426985e-02
var$contrib
## Dim.1 Dim.2 Dim.3 Dim.4
## d1 3.721439 1.141080086 0.12575590 9.315629e-05
## d2 3.644820 3.698237318 0.81930512 3.052406e-01
## d3 3.701049 1.797669849 0.23316792 2.330315e-01
## d4 3.648933 2.823257983 0.04059719 2.861990e+00
## d5 3.705036 0.575995024 0.01659918 2.839770e+00
## d6 3.633044 1.720041704 1.05780922 5.389832e+00
## d7 3.409166 2.700825169 18.77804834 3.639243e-01
## d8 2.942975 16.981420654 22.88035737 5.179388e+00
## d9 3.111914 14.198402259 19.97829182 9.079640e-04
## d10 3.717991 0.026154850 2.06569356 2.615501e-01
## d11 3.451790 0.031973468 20.49092078 2.334707e-01
## d12 3.687885 2.222376455 0.00323748 7.663123e-01
## d13 3.740396 0.240658652 0.19755218 1.996974e-01
## d14 3.546298 8.236188650 0.09407635 3.161167e-02
## d15 3.315440 2.424883741 0.04810885 3.337761e+01
## d16 3.678046 0.005249314 0.54935785 5.807984e+00
## d17 3.657569 0.272942222 0.06987829 7.656957e+00
## d18 3.509962 6.005774845 0.16599820 8.067696e+00
## d19 3.663438 1.721686809 1.82736220 1.694743e+00
## d20 3.672365 0.729479853 0.60421873 4.652102e+00
## d21 3.709771 0.010581024 0.03461183 3.637235e+00
## d22 3.640737 4.396747444 0.13906921 8.668464e-03
## d23 3.526320 0.040549447 7.27742707 1.057229e+01
## d24 3.579736 6.275428347 0.79660509 4.614270e-01
## d25 3.741969 0.239562719 0.12139874 1.601836e-01
## d26 3.745578 0.185656584 0.01596039 9.322537e-02
## d27 3.275390 18.656742439 0.75584601 3.835385e-01
## d28 3.620943 2.640433088 0.81274514 4.759517e+00
fviz_pca_var(res.pca, repel = TRUE)
На графике видно, что все 28 переменных (d1–d28) сгруппированы в крайней правой части круга корреляций, вдоль положительного полюса Dim.2.
fviz_pca_biplot(res.pca, repel = TRUE)
точки наблюдений (объекты исследования, обозначены цифрами: 1, 2, 3, 4, 5) — показывают положение объектов в пространстве главных компонент; векторы переменных (обозначены как d1, d2, …, d27) — демонстрируют направление и силу влияния каждой переменной на главные компоненты. Наиболее значимые переменные: d1 (0.993), d3 (0.988), d5 (0.989), d10 (0.991), d13 (0.998) — почти полностью определяются Dim.1.
ind <- get_pca_ind(res.pca)
pc1 <- ind$coord[, 1]
df_pca$pc1<-pc1
head(pc1)
## 1 2 3 4 5
## 8.467013 2.992209 -1.981828 -3.360237 -6.117156
1 8.32 Я верующий- Максимально высокая религиозность 2 2.90 Я верю в Бога по-своему- Выше среднего 3 -1.95- Не могу сказать, верю я или нет - Ниже среднего 4 -3.23 Религия меня не интересует- Низкая религиозность 5 -6.04 Атеист -Минимальная религиозность