fix style

This commit is contained in:
Pablo Antonio Lillo Cea 2026-05-08 10:14:57 +02:00
parent eb093605b3
commit b445c1033f

View file

@ -40,11 +40,11 @@
library(tidyverse)
library(FactoMineR)
# 00-Load ----------------------------------------------------------------------
# 00 - Load --------------------------------------------------------------------
m_sample <- read_rds("data/processed/m_sample.rds")
all_vars <- setdiff(names(m_sample), c("code", "municipality"))
# 01-Exclude genuinely uninformative variables ---------------------------------
# 01 - Exclude genuinely uninformative variables -------------------------------
# Removed from every part of the analysis: redundant totals, geographic areas,
# and always-zero columns that add no discriminating information.
truly_exclude <- c(
@ -70,7 +70,7 @@ truly_exclude <- c(
analysis_vars <- setdiff(all_vars, truly_exclude)
# 02-Define variable roles -----------------------------------------------------
# 02 - Define variable roles ---------------------------------------------------
# (a) Educational provision: the research object → col.sup
col_sup_edu <- analysis_vars[
@ -142,7 +142,7 @@ active_vars <- analysis_vars[
# Everything else → post-hoc correlations with CA dimensions
outside_ca <- setdiff(analysis_vars, c(active_vars, col_sup_vars))
# 03-Build CA matrix -----------------------------------------------------------
# 03 - Build CA matrix ---------------------------------------------------------
X <- m_sample |>
select(all_of(c(active_vars, col_sup_vars))) |>
as.data.frame()
@ -156,7 +156,7 @@ if (na_count > 0) {
idx_sup <- seq(length(active_vars) + 1L, ncol(X))
# 04-Run CA --------------------------------------------------------------------
# 04 - Run CA ------------------------------------------------------------------
ca <- CA(X, ncp = 10, col.sup = idx_sup, graph = FALSE)
contribs <- ca$col$contrib |>
@ -169,7 +169,7 @@ for (d in paste0("Dim ", 1:5)) {
cat(paste0(" ", top5), sep = "\n")
}
# 05-Post-hoc: correlate row scores with outside-CA variables ------------------
# 05 - Post-hoc: correlate row scores with outside-CA variables ----------------
ca_row_coords <- as.data.frame(ca$row$coord)
outside_data <- m_sample |>
@ -187,7 +187,7 @@ posthoc_cor <- cor(
as.data.frame() |>
rownames_to_column("dimension")
# 06-Save ----------------------------------------------------------------------
# 06 - Save --------------------------------------------------------------------
write_rds(ca, "data/processed/ca_exploratory.rds")
write_rds(
list(