library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.1 ✔ tibble 3.3.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(FactoMineR)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(arules)
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
##
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
##
##
## Attaching package: 'arules'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following objects are masked from 'package:base':
##
## abbreviate, write
ess <- read_csv("~/Desktop/tasks/ESS11e04_1.csv", show_col_types = FALSE)
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
The ESS Round 11 integrated file is used to keep the broadest possible geographical coverage. The analysis focuses on trust in institutions and social trust variables.
trust_vars <- ess %>%
select(
trstplt,
trstplc,
trstprl,
trstprt,
trstlgl,
trstep,
trstun,
ppltrst,
pplhlp,
pplfair
)
Only valid responses are kept. Higher values indicate higher trust.
trust_clean <- trust_vars %>%
filter(if_all(everything(), ~ .x >= 0 & .x <= 10)) %>%
drop_na()
dim(trust_clean)
## [1] 43744 10
Variables are standardized to ensure comparability before dimension reduction.
trust_scaled <- scale(trust_clean)
Principal Component Analysis is applied to identify latent dimensions of institutional and social trust.
pca_res <- FactoMineR::PCA(trust_scaled, scale.unit = FALSE, graph = FALSE)
Each respondent is treated as one transaction, and their characteristics are treated as items.
vars_disc <- trust_clean %>%
mutate(across(everything(), ~ factor(.x)))
trans <- as(vars_disc, "transactions")
summary(trans)
## transactions as itemMatrix in sparse format with
## 43744 rows (elements/itemsets/transactions) and
## 110 columns (items) and a density of 0.09090909
##
## most frequent items:
## pplhlp=5 pplfair=5 trstplc=8 trstep=5 ppltrst=5 (Other)
## 8780 8711 8517 8316 8308 394808
##
## element (itemset/transaction) length distribution:
## sizes
## 10
## 43744
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10 10 10 10 10 10
##
## includes extended item information - examples:
## labels variables levels
## 1 trstplt=0 trstplt 0
## 2 trstplt=1 trstplt 1
## 3 trstplt=2 trstplt 2
##
## includes extended transaction information - examples:
## transactionID
## 1 1
## 2 2
## 3 3
factoextra::get_eigenvalue(pca_res)
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 5.1295848 51.297021 51.29702
## Dim.2 1.5013194 15.013538 66.31056
## Dim.3 0.8208126 8.208314 74.51887
## Dim.4 0.7229474 7.229640 81.74851
## Dim.5 0.4876258 4.876369 86.62488
## Dim.6 0.3971862 3.971953 90.59683
## Dim.7 0.3168997 3.169070 93.76590
## Dim.8 0.2563056 2.563115 96.32902
## Dim.9 0.2442347 2.442403 98.77142
## Dim.10 0.1228551 1.228579 100.00000
Scree plot
fviz_eig(pca_res, addlabels = TRUE)
## Warning in geom_bar(stat = "identity", fill = barfill, color = barcolor, :
## Ignoring empty aesthetic: `width`.
Variable contribution plot
fviz_pca_var(pca_res, col.var = "contrib")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## ℹ The deprecated feature was likely used in the ggpubr package.
## Please report the issue at <https://github.com/kassambara/ggpubr/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Individuals plot
fviz_pca_ind(pca_res, alpha.ind = 0.2)
The first principal components explain a substantial share of the total variance in trust related variables. The results suggest a clear separation between institutional trust (eg. trust in politicians, parliament, legal system) and social trust (trust in other people, fairness, helpfulness). Overall, the dimension reduction indicates that trust attitudes in Europe can be summarized by a small number of latent dimensions, capturing general patterns of confidence in institutions and society across countries.
ess <- read_csv(“~/Desktop/tasks/ESS11e04_1.csv”, show_col_types = FALSE)
## Variable inspection and selection
The ESS Round 11 integrated file is used to keep the broadest possible geographical coverage.
The analysis focuses on trust in institutions and social trust variables.
``` r
trust_vars <- ess %>%
select(
trstplt,
trstplc,
trstprl,
trstprt,
trstlgl,
trstep,
trstun,
ppltrst,
pplhlp,
pplfair
)
Only valid responses are kept. Higher values indicate higher trust.
trust_clean <- trust_vars %>%
filter(if_all(everything(), ~ .x >= 0 & .x <= 10)) %>%
drop_na()
dim(trust_clean)
## [1] 43744 10
Variables are standardized to ensure comparability before dimension reduction.
trust_scaled <- scale(trust_clean)
Principal Component Analysis is applied to identify latent dimensions of institutional and social trust.
pca_res <- PCA(trust_scaled, scale.unit = FALSE, graph = FALSE)
Each respondent is treated as one transaction, and their characteristics are treated as items.
trans <- as(vars_disc, "transactions")
summary(trans)
## transactions as itemMatrix in sparse format with
## 43744 rows (elements/itemsets/transactions) and
## 110 columns (items) and a density of 0.09090909
##
## most frequent items:
## pplhlp=5 pplfair=5 trstplc=8 trstep=5 ppltrst=5 (Other)
## 8780 8711 8517 8316 8308 394808
##
## element (itemset/transaction) length distribution:
## sizes
## 10
## 43744
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10 10 10 10 10 10
##
## includes extended item information - examples:
## labels variables levels
## 1 trstplt=0 trstplt 0
## 2 trstplt=1 trstplt 1
## 3 trstplt=2 trstplt 2
##
## includes extended transaction information - examples:
## transactionID
## 1 1
## 2 2
## 3 3
get_eigenvalue(pca_res)
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 5.1295848 51.297021 51.29702
## Dim.2 1.5013194 15.013538 66.31056
## Dim.3 0.8208126 8.208314 74.51887
## Dim.4 0.7229474 7.229640 81.74851
## Dim.5 0.4876258 4.876369 86.62488
## Dim.6 0.3971862 3.971953 90.59683
## Dim.7 0.3168997 3.169070 93.76590
## Dim.8 0.2563056 2.563115 96.32902
## Dim.9 0.2442347 2.442403 98.77142
## Dim.10 0.1228551 1.228579 100.00000
Scree plot
fviz_eig(pca_res, addlabels = TRUE)
## Warning in geom_bar(stat = "identity", fill = barfill, color = barcolor, :
## Ignoring empty aesthetic: `width`.
Variable contribution plot
fviz_pca_var(pca_res, col.var = "contrib")
Individuals plot
fviz_pca_ind(pca_res, alpha.ind = 0.2)
The first principal components explain a substantial share of the total variance in trust related variables. The results suggest a clear separation between institutional trust (eg. trust in politicians, parliament, legal system) and social trust (trust in other people, fairness, helpfulness). Overall, the dimension reduction indicates that trust attitudes in Europe can be summarized by a small number of latent dimensions, capturing general patterns of confidence in institutions and society across countries.