COA Principal Components Analysis

Author

Kaitlan Wong

Overview of Analysis

I ran a Principal Components Analysis (PCA) on the variables used to create the composite index score in the City of Austin’s equity indicators map for Travis County. The variables included in the analysis are:

  • uninsured_est

  • est_child_pov

  • disability_est

  • EAL_VALP_x100

  • med_inc_hh_est

  • persistent_poverty

  • est_underemp_perc

  • eviction_filing_rate

  • below_pov_est

  • Energy_Burden___income

  • limited_english_hh_est

  • est_no_internet_perc

  • est_65plus_ambulatory

  • less_than_highschool_est

  • low_physical_activity_est

  • hh_support_risk_score

Overall, I found that low_physical_activity_est and less_than_highschool_est are highly correlated using a correlation coefficient of 85%. Using a correlation coefficient of 80%, est_child_pov and below_pov_est are also highly correlated.

Data Prep

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.1     ✔ stringr   1.5.2
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── 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(recipes)
Warning: package 'recipes' was built under R version 4.5.2

Attaching package: 'recipes'

The following object is masked from 'package:stringr':

    fixed

The following object is masked from 'package:stats':

    step
library(ggplot2)
library(writexl)
df <- readr::read_csv("IndexLayer_0.csv")
Rows: 261 Columns: 41
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (41): OBJECTID, SOURCE_ID, uninsured_est, est_child_pov, disability_est,...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
vars <- c(
  "uninsured_est","est_child_pov","disability_est","EAL_VALP_x100",
  "med_inc_hh_est","persistent_poverty","est_underemp_perc","eviction_filing_rate",
  "below_pov_est","Energy_Burden____income_","limited_english_hh_est","est_no_internet_perc",
  "est_65plus_ambulatory","less_than_highschool_est","low_physical_activity_est",
  "hh_support_risk_score"
)

Data Exploration

# correlation look (pairwise)
corr_df <- df %>%
  dplyr::select(dplyr::all_of(vars)) %>%
  mutate(across(everything(), as.numeric)) %>%
  cor(use = "pairwise.complete.obs", method = "pearson") %>% # for each pair of variables, use all rows where both of those variables have non-missing values
  as.data.frame()

corr_df
                          uninsured_est est_child_pov disability_est
uninsured_est                1.00000000    0.43005007     0.29465805
est_child_pov                0.43005007    1.00000000     0.30487184
disability_est               0.29465805    0.30487184     1.00000000
EAL_VALP_x100                0.08130599    0.03823415    -0.06904510
med_inc_hh_est              -0.60100961   -0.40626408    -0.40560257
persistent_poverty           0.07849296    0.18237177     0.09708204
est_underemp_perc           -0.01164555    0.20329567     0.02053200
eviction_filing_rate         0.20464477    0.17174222     0.29479053
below_pov_est                0.49422080    0.81984746     0.32091600
Energy_Burden____income_     0.58277128    0.42359295     0.40149521
limited_english_hh_est       0.58994085    0.34403478     0.23385816
est_no_internet_perc         0.50199026    0.36091025     0.41230203
est_65plus_ambulatory        0.33111702    0.18187726     0.42949357
less_than_highschool_est     0.70504758    0.41850697     0.35197961
low_physical_activity_est    0.71207034    0.58990834     0.45929837
hh_support_risk_score        0.19496301    0.16386972     0.14676875
                          EAL_VALP_x100 med_inc_hh_est persistent_poverty
uninsured_est                0.08130599    -0.60100961         0.07849296
est_child_pov                0.03823415    -0.40626408         0.18237177
disability_est              -0.06904510    -0.40560257         0.09708204
EAL_VALP_x100                1.00000000     0.04460869         0.05587774
med_inc_hh_est               0.04460869     1.00000000        -0.15847980
persistent_poverty           0.05587774    -0.15847980         1.00000000
est_underemp_perc            0.10918098    -0.01902626         0.22976882
eviction_filing_rate         0.07226350    -0.25449057        -0.04111819
below_pov_est                0.04670211    -0.56409826         0.36190576
Energy_Burden____income_     0.09869988    -0.50976342         0.09448161
limited_english_hh_est       0.04719554    -0.47848225        -0.01454474
est_no_internet_perc        -0.02023873    -0.40100140         0.25862173
est_65plus_ambulatory       -0.06819569    -0.30024171         0.07838723
less_than_highschool_est     0.05926045    -0.47412608         0.11855364
low_physical_activity_est    0.08380192    -0.56842092         0.16729565
hh_support_risk_score       -0.05018786    -0.15019547        -0.02884535
                          est_underemp_perc eviction_filing_rate below_pov_est
uninsured_est                   -0.01164555           0.20464477    0.49422080
est_child_pov                    0.20329567           0.17174222    0.81984746
disability_est                   0.02053200           0.29479053    0.32091600
EAL_VALP_x100                    0.10918098           0.07226350    0.04670211
med_inc_hh_est                  -0.01902626          -0.25449057   -0.56409826
persistent_poverty               0.22976882          -0.04111819    0.36190576
est_underemp_perc                1.00000000          -0.01838666    0.35236067
eviction_filing_rate            -0.01838666           1.00000000    0.17239898
below_pov_est                    0.35236067           0.17239898    1.00000000
Energy_Burden____income_         0.19171729           0.31259431    0.48019817
limited_english_hh_est           0.03413853           0.26287397    0.39094134
est_no_internet_perc             0.01852707           0.11733368    0.42232854
est_65plus_ambulatory           -0.09709964           0.16517782    0.21330040
less_than_highschool_est        -0.01868326           0.31609522    0.41298754
low_physical_activity_est        0.08975800           0.35229652    0.62095173
hh_support_risk_score           -0.06639248           0.14867547    0.15633334
                          Energy_Burden____income_ limited_english_hh_est
uninsured_est                           0.58277128             0.58994085
est_child_pov                           0.42359295             0.34403478
disability_est                          0.40149521             0.23385816
EAL_VALP_x100                           0.09869988             0.04719554
med_inc_hh_est                         -0.50976342            -0.47848225
persistent_poverty                      0.09448161            -0.01454474
est_underemp_perc                       0.19171729             0.03413853
eviction_filing_rate                    0.31259431             0.26287397
below_pov_est                           0.48019817             0.39094134
Energy_Burden____income_                1.00000000             0.48875182
limited_english_hh_est                  0.48875182             1.00000000
est_no_internet_perc                    0.42163165             0.48732225
est_65plus_ambulatory                   0.26938924             0.15847689
less_than_highschool_est                0.61206437             0.62952414
low_physical_activity_est               0.72351288             0.60414233
hh_support_risk_score                   0.22005172             0.18811889
                          est_no_internet_perc est_65plus_ambulatory
uninsured_est                       0.50199026            0.33111702
est_child_pov                       0.36091025            0.18187726
disability_est                      0.41230203            0.42949357
EAL_VALP_x100                      -0.02023873           -0.06819569
med_inc_hh_est                     -0.40100140           -0.30024171
persistent_poverty                  0.25862173            0.07838723
est_underemp_perc                   0.01852707           -0.09709964
eviction_filing_rate                0.11733368            0.16517782
below_pov_est                       0.42232854            0.21330040
Energy_Burden____income_            0.42163165            0.26938924
limited_english_hh_est              0.48732225            0.15847689
est_no_internet_perc                1.00000000            0.24523309
est_65plus_ambulatory               0.24523309            1.00000000
less_than_highschool_est            0.61174368            0.32533158
low_physical_activity_est           0.56604415            0.33452977
hh_support_risk_score               0.21236745            0.11525592
                          less_than_highschool_est low_physical_activity_est
uninsured_est                           0.70504758                0.71207034
est_child_pov                           0.41850697                0.58990834
disability_est                          0.35197961                0.45929837
EAL_VALP_x100                           0.05926045                0.08380192
med_inc_hh_est                         -0.47412608               -0.56842092
persistent_poverty                      0.11855364                0.16729565
est_underemp_perc                      -0.01868326                0.08975800
eviction_filing_rate                    0.31609522                0.35229652
below_pov_est                           0.41298754                0.62095173
Energy_Burden____income_                0.61206437                0.72351288
limited_english_hh_est                  0.62952414                0.60414233
est_no_internet_perc                    0.61174368                0.56604415
est_65plus_ambulatory                   0.32533158                0.33452977
less_than_highschool_est                1.00000000                0.85193101
low_physical_activity_est               0.85193101                1.00000000
hh_support_risk_score                   0.19978392                0.25901940
                          hh_support_risk_score
uninsured_est                        0.19496301
est_child_pov                        0.16386972
disability_est                       0.14676875
EAL_VALP_x100                       -0.05018786
med_inc_hh_est                      -0.15019547
persistent_poverty                  -0.02884535
est_underemp_perc                   -0.06639248
eviction_filing_rate                 0.14867547
below_pov_est                        0.15633334
Energy_Burden____income_             0.22005172
limited_english_hh_est               0.18811889
est_no_internet_perc                 0.21236745
est_65plus_ambulatory                0.11525592
less_than_highschool_est             0.19978392
low_physical_activity_est            0.25901940
hh_support_risk_score                1.00000000
# adding a heatmap here for visualization
corr_long <- corr_df %>%
  rownames_to_column("var1") %>%
  pivot_longer(-var1, names_to = "var2", values_to = "r")

ggplot(corr_long, aes(var1, var2, fill = r)) +
  geom_tile() +
  scale_fill_gradient2(limits = c(-1, 1)) +
  coord_fixed() +
  labs(title = "Correlation heatmap (Pearson)", x = NULL, y = NULL) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Visually, I can already see two pairs with strong positive correlations:

  • below_pov_est and est_child_pov

  • low_physical_activity and less_than_highschool_est

The first pair having a strong relationship makes sense, though it’s interesting that low_physical_activity and less_than_highschool_est have a strong relationship.

It makes sense that there is a negative correlation between median income and most of the other variables.

EAL_VALP_x100 and est_underemp_perc have weaker correlations overall (they’re contributing more independent information).

Principal Components Analysis (PCA)

Now, let’s run a PCA!

### PCA ###


# pre-processing data before PCA
pca_recipe <- recipe(~ ., data = df %>% dplyr::select(dplyr::all_of(vars))) %>%
  # ensure numeric
  step_mutate(across(everything(), as.numeric)) %>%
  # impute missing values to avoid dropping rows (If a variable has missing values, replace those missing values with the median of that variable. PCA cannot run if there are missing values.)
  step_impute_median(all_numeric_predictors()) %>%
  # standardize (center/scale) — critical for PCA across different units
  step_normalize(all_numeric_predictors())


# learn parameters and apply to data
pca_prep <- prep(pca_recipe)
X <- bake(pca_prep, new_data = NULL)  # matrix used for PCA


# run PCA (on already standardized data)
pca <- prcomp(X, center = FALSE, scale. = FALSE)

pca
Standard deviations (1, .., p=16):
 [1] 2.4516447 1.2733488 1.0993068 1.0126823 0.9869127 0.9349391 0.8750956
 [8] 0.8474783 0.7854821 0.7530780 0.6967042 0.5910913 0.5609195 0.5031253
[15] 0.3572221 0.2960287

Rotation (n x k) = (16 x 16):
                                  PC1          PC2         PC3          PC4
uninsured_est             -0.32435184 -0.107291206  0.14749204 -0.200230424
est_child_pov             -0.27426979  0.296846344 -0.05667610  0.004665550
disability_est            -0.22751972 -0.126455168 -0.39916048  0.373586874
EAL_VALP_x100             -0.02318265  0.176841057  0.57209650  0.330171652
med_inc_hh_est             0.29392382  0.024410189  0.10630089  0.031287002
persistent_poverty        -0.09385071  0.450469043 -0.30179617 -0.093404355
est_underemp_perc         -0.05315104  0.567262483  0.08298070  0.214305204
eviction_filing_rate      -0.15840422 -0.205533767  0.14221524  0.633152997
below_pov_est             -0.30142538  0.394075716 -0.10220272 -0.002610449
Energy_Burden____income_  -0.31280460 -0.004546782  0.14570731  0.131651646
limited_english_hh_est    -0.28281056 -0.135608389  0.29097681 -0.225481302
est_no_internet_perc      -0.27928939 -0.028571030 -0.10915903 -0.306751751
est_65plus_ambulatory     -0.17561781 -0.220844434 -0.44104635  0.259782674
less_than_highschool_est  -0.33680830 -0.156041412  0.15910990 -0.142843638
low_physical_activity_est -0.37169856 -0.028861120  0.10176329 -0.007787522
hh_support_risk_score     -0.12257075 -0.192566024 -0.02158305 -0.067553212
                                   PC5          PC6         PC7         PC8
uninsured_est             -0.128210714 -0.088534367 -0.16086094 -0.04105774
est_child_pov              0.285273404 -0.139177146 -0.39802319  0.20346047
disability_est            -0.076138555  0.024540427  0.10419107 -0.18367306
EAL_VALP_x100             -0.391363947  0.397233418 -0.37729335 -0.01969984
med_inc_hh_est             0.006582387  0.235394355  0.10185309 -0.20551648
persistent_poverty        -0.331968920  0.418600650  0.26771645  0.36757176
est_underemp_perc          0.167747590 -0.100426623  0.33165372 -0.55053279
eviction_filing_rate       0.159567620 -0.031071953  0.35802607  0.48088534
below_pov_est              0.197050788 -0.104913200 -0.24205890  0.16965068
Energy_Burden____income_   0.030932706 -0.040568894  0.11199850 -0.27744276
limited_english_hh_est     0.014572008 -0.145771139  0.18668766 -0.02898556
est_no_internet_perc      -0.177651104  0.246654996  0.27951704 -0.05084615
est_65plus_ambulatory     -0.283528975  0.056926744 -0.35741752 -0.29723685
less_than_highschool_est  -0.167335888  0.033952102  0.14842063 -0.03280339
low_physical_activity_est -0.016744989  0.008430128  0.02053257 -0.01954764
hh_support_risk_score      0.631776884  0.688114666 -0.08919894 -0.11009949
                                  PC9        PC10        PC11         PC12
uninsured_est              0.24750807 -0.01003594  0.04948301  0.317520514
est_child_pov             -0.35911174  0.22247848  0.01898869 -0.069556863
disability_est            -0.44014812 -0.42941809  0.08406867 -0.238091851
EAL_VALP_x100             -0.11689732 -0.21752479 -0.10834435  0.008586888
med_inc_hh_est            -0.40698268  0.61253415  0.07437067 -0.190917227
persistent_poverty         0.28255868  0.05988743  0.08627780 -0.267832820
est_underemp_perc          0.15553563  0.04382249 -0.22845587  0.191635758
eviction_filing_rate       0.06494485  0.19621923 -0.15507642  0.205432696
below_pov_est             -0.04708850  0.01068496 -0.10363783  0.025685879
Energy_Burden____income_   0.17073332 -0.05486867  0.56225389 -0.169876992
limited_english_hh_est     0.01647929 -0.05322249 -0.55748468 -0.612347167
est_no_internet_perc      -0.42793889 -0.06870411 -0.22987036  0.487897424
est_65plus_ambulatory      0.27751095  0.37766423 -0.31708482 -0.010407046
less_than_highschool_est  -0.05708407  0.32306273  0.15745571  0.035448304
low_physical_activity_est -0.05116360  0.18647160  0.26582908 -0.079719393
hh_support_risk_score      0.17561492 -0.08384274 -0.05166448 -0.014814232
                                 PC13        PC14         PC15         PC16
uninsured_est              0.41709565 -0.65442376 -0.036474033 -0.037438548
est_child_pov             -0.05856644 -0.04683241 -0.561193573 -0.169222911
disability_est             0.33863662 -0.13141542 -0.005942485  0.092147276
EAL_VALP_x100             -0.02385762  0.06698205 -0.010858560  0.014685278
med_inc_hh_est             0.06332763 -0.40496503  0.194807127  0.062442100
persistent_poverty         0.06411605 -0.11453231 -0.119351539 -0.046646774
est_underemp_perc          0.17573155  0.07662215 -0.124579654 -0.063005682
eviction_filing_rate      -0.05238840 -0.11763979 -0.007618753 -0.009088448
below_pov_est             -0.07671584 -0.03503129  0.635652502  0.425777562
Energy_Burden____income_  -0.57875086 -0.20842118 -0.063399449  0.109039082
limited_english_hh_est    -0.08036175 -0.11109360 -0.010688309 -0.034478320
est_no_internet_perc      -0.38879575 -0.03588967  0.014744685 -0.103204909
est_65plus_ambulatory     -0.18493073  0.05347247 -0.008717650 -0.034963888
less_than_highschool_est   0.29131426  0.43416111 -0.215071626  0.557619507
low_physical_activity_est  0.20375091  0.31701306  0.400037792 -0.658015231
hh_support_risk_score      0.08108038  0.02839669 -0.032220785  0.031077894
# saving PCA data from above to Excel
library(openxlsx)
Warning: package 'openxlsx' was built under R version 4.5.2
# 1. Loadings (rotation matrix)
pca_loadings <- as.data.frame(pca$rotation) %>%
  rownames_to_column("variable")

# 2. Scores (component values per observation)
pca_scores <- as.data.frame(pca$x) %>%
  rownames_to_column("row_id")

# 3. Variance explained
variance_explained <- tibble(
  PC = paste0("PC", seq_along(pca$sdev)),
  Std_Dev = pca$sdev,
  Variance = pca$sdev^2,
  Prop_Variance = (pca$sdev^2) / sum(pca$sdev^2),
  Cum_Prop_Variance = cumsum((pca$sdev^2) / sum(pca$sdev^2))
)

# write to Excel in one file
wb <- createWorkbook()

addWorksheet(wb, "Loadings")
writeData(wb, "Loadings", pca_loadings)

addWorksheet(wb, "Scores")
writeData(wb, "Scores", pca_scores)

addWorksheet(wb, "Variance Explained")
writeData(wb, "Variance Explained", variance_explained)

saveWorkbook(wb, "PCA_results.xlsx", overwrite = TRUE)

Let’s remove collinear predictors by correlation (caret). I used a cut off of 85%, but this can be changed.

library(caret)
Warning: package 'caret' was built under R version 4.5.2
Loading required package: lattice

Attaching package: 'caret'
The following object is masked from 'package:purrr':

    lift
X <- df %>% select(all_of(vars)) %>% mutate(across(everything(), as.numeric))

# pairwise Pearson correlations with pairwise NAs
cm <- cor(X, use = "pairwise.complete.obs", method = "pearson")

# find variables to drop at a high-correlation cutoff (going with 85% for now)
to_drop <- findCorrelation(cm, cutoff = 0.85, names = TRUE, verbose = TRUE)
Compare row 15  and column  14 with corr  0.852 
  Means:  0.466 vs 0.276 so flagging column 15 
All correlations <= 0.85 
vars_pruned <- setdiff(vars, to_drop)

list(
  dropped_for_high_corr = to_drop,
  kept = vars_pruned
)
$dropped_for_high_corr
[1] "low_physical_activity_est"

$kept
 [1] "uninsured_est"            "est_child_pov"           
 [3] "disability_est"           "EAL_VALP_x100"           
 [5] "med_inc_hh_est"           "persistent_poverty"      
 [7] "est_underemp_perc"        "eviction_filing_rate"    
 [9] "below_pov_est"            "Energy_Burden____income_"
[11] "limited_english_hh_est"   "est_no_internet_perc"    
[13] "est_65plus_ambulatory"    "less_than_highschool_est"
[15] "hh_support_risk_score"   

The above analysis found one pair over the cutoff (≥ 0.85): low_physical_activity_est (row 15) vs less_than_highschool_est (col 14) with r = 0.852. This aligns with the heat map I previously made.

Each variable’s mean absolute correlation was compared with all others: low_physical_activity_est had 0.466 vs. less_than_highschool_est 0.276.

Since low_physical_activity_est is more correlated on average with the rest, it’s the more redundant one, so caret drops it.

After dropping that one, all remaining pairs are ≤ 0.85, so nothing else is removed.

I was wondering why child poverty or overall poverty weren’t flagged, so I wanted to check:

cm["below_pov_est", "est_child_pov"]
[1] 0.8198475

As seen above, child poverty and poverty do not meet the 85% cutoff, as their r = 0.8198. Though, they are still pretty highly correlated.

Additional Info

Now, let’s visualize how much variance each Principal Component (PC) explains.

# scree plot (variance explained)

eigs <- pca$sdev^2 # eigenvalues (how much variance each PC holds)
var_explained <- eigs / sum(eigs) # turn eigs into a % of total variance
scree_df <- tibble(
  PC = paste0("PC", seq_along(eigs)),
  Eigenvalue = eigs,
  Variance = var_explained,
  CumVariance = cumsum(var_explained) # shows how much total variance is covered by first couple PCs
)

ggplot(scree_df, aes(x = seq_along(PC), y = Variance)) +
  geom_point() +
  geom_line() +
  scale_x_continuous(breaks = seq_along(scree_df$PC)) +
  labs(title = "Scree plot", x = "Principal Component", y = "Proportion of Variance") +
  theme_minimal()

The scree plot shows us that PC1 explains the largest chunk of variance (around 40%), while PC2 explains much less (around 10%). PC3 and onward each contribute only around 5% and then gradually go down.

This means that there is one dominant underlying dimension shared across all the variables. So, many of the variables are reflecting the same underlying construct.

This is was we’d expect with these types of sociodemographic variables, as we know they are all related when it comes to equity outcomes.

Next, let’s see which variables drive each PC.

# absolute loadings near |1| indicate variables move together strongly along that PC

loadings <- as.data.frame(pca$rotation) %>%
  rownames_to_column("variable")

# top contributors per PC 
n <- 8 # can change n to list more/less
top_by_pc <- map_dfr(
  colnames(pca$rotation),
  ~ loadings %>%
    select(variable, all_of(.x)) %>%
    arrange(desc(abs(.data[[.x]]))) %>%
    slice_head(n = n) %>%
    mutate(PC = .x),
  .id = "pc_order"
) %>%
  select(PC, variable, loading = starts_with("PC"))

print(top_by_pc)
    loading3                  variable loading1   loading2   loading4
1        PC1 low_physical_activity_est        1 -0.3716986         NA
2        PC1  less_than_highschool_est        1 -0.3368083         NA
3        PC1             uninsured_est        1 -0.3243518         NA
4        PC1  Energy_Burden____income_        1 -0.3128046         NA
5        PC1             below_pov_est        1 -0.3014254         NA
6        PC1            med_inc_hh_est        1  0.2939238         NA
7        PC1    limited_english_hh_est        1 -0.2828106         NA
8        PC1      est_no_internet_perc        1 -0.2792894         NA
9        PC2         est_underemp_perc        2         NA  0.5672625
10       PC2        persistent_poverty        2         NA  0.4504690
11       PC2             below_pov_est        2         NA  0.3940757
12       PC2             est_child_pov        2         NA  0.2968463
13       PC2     est_65plus_ambulatory        2         NA -0.2208444
14       PC2      eviction_filing_rate        2         NA -0.2055338
15       PC2     hh_support_risk_score        2         NA -0.1925660
16       PC2             EAL_VALP_x100        2         NA  0.1768411
17       PC3             EAL_VALP_x100        3         NA         NA
18       PC3     est_65plus_ambulatory        3         NA         NA
19       PC3            disability_est        3         NA         NA
20       PC3        persistent_poverty        3         NA         NA
21       PC3    limited_english_hh_est        3         NA         NA
22       PC3  less_than_highschool_est        3         NA         NA
23       PC3             uninsured_est        3         NA         NA
24       PC3  Energy_Burden____income_        3         NA         NA
25       PC4      eviction_filing_rate        4         NA         NA
26       PC4            disability_est        4         NA         NA
27       PC4             EAL_VALP_x100        4         NA         NA
28       PC4      est_no_internet_perc        4         NA         NA
29       PC4     est_65plus_ambulatory        4         NA         NA
30       PC4    limited_english_hh_est        4         NA         NA
31       PC4         est_underemp_perc        4         NA         NA
32       PC4             uninsured_est        4         NA         NA
33       PC5     hh_support_risk_score        5         NA         NA
34       PC5             EAL_VALP_x100        5         NA         NA
35       PC5        persistent_poverty        5         NA         NA
36       PC5             est_child_pov        5         NA         NA
37       PC5     est_65plus_ambulatory        5         NA         NA
38       PC5             below_pov_est        5         NA         NA
39       PC5      est_no_internet_perc        5         NA         NA
40       PC5         est_underemp_perc        5         NA         NA
41       PC6     hh_support_risk_score        6         NA         NA
42       PC6        persistent_poverty        6         NA         NA
43       PC6             EAL_VALP_x100        6         NA         NA
44       PC6      est_no_internet_perc        6         NA         NA
45       PC6            med_inc_hh_est        6         NA         NA
46       PC6    limited_english_hh_est        6         NA         NA
47       PC6             est_child_pov        6         NA         NA
48       PC6             below_pov_est        6         NA         NA
49       PC7             est_child_pov        7         NA         NA
50       PC7             EAL_VALP_x100        7         NA         NA
51       PC7      eviction_filing_rate        7         NA         NA
52       PC7     est_65plus_ambulatory        7         NA         NA
53       PC7         est_underemp_perc        7         NA         NA
54       PC7      est_no_internet_perc        7         NA         NA
55       PC7        persistent_poverty        7         NA         NA
56       PC7             below_pov_est        7         NA         NA
57       PC8         est_underemp_perc        8         NA         NA
58       PC8      eviction_filing_rate        8         NA         NA
59       PC8        persistent_poverty        8         NA         NA
60       PC8     est_65plus_ambulatory        8         NA         NA
61       PC8  Energy_Burden____income_        8         NA         NA
62       PC8            med_inc_hh_est        8         NA         NA
63       PC8             est_child_pov        8         NA         NA
64       PC8            disability_est        8         NA         NA
65       PC9            disability_est        9         NA         NA
66       PC9      est_no_internet_perc        9         NA         NA
67       PC9            med_inc_hh_est        9         NA         NA
68       PC9             est_child_pov        9         NA         NA
69       PC9        persistent_poverty        9         NA         NA
70       PC9     est_65plus_ambulatory        9         NA         NA
71       PC9             uninsured_est        9         NA         NA
72       PC9     hh_support_risk_score        9         NA         NA
73      PC10            med_inc_hh_est       10         NA         NA
74      PC10            disability_est       10         NA         NA
75      PC10     est_65plus_ambulatory       10         NA         NA
76      PC10  less_than_highschool_est       10         NA         NA
77      PC10             est_child_pov       10         NA         NA
78      PC10             EAL_VALP_x100       10         NA         NA
79      PC10      eviction_filing_rate       10         NA         NA
80      PC10 low_physical_activity_est       10         NA         NA
81      PC11  Energy_Burden____income_       11         NA         NA
82      PC11    limited_english_hh_est       11         NA         NA
83      PC11     est_65plus_ambulatory       11         NA         NA
84      PC11 low_physical_activity_est       11         NA         NA
85      PC11      est_no_internet_perc       11         NA         NA
86      PC11         est_underemp_perc       11         NA         NA
87      PC11  less_than_highschool_est       11         NA         NA
88      PC11      eviction_filing_rate       11         NA         NA
89      PC12    limited_english_hh_est       12         NA         NA
90      PC12      est_no_internet_perc       12         NA         NA
91      PC12             uninsured_est       12         NA         NA
92      PC12        persistent_poverty       12         NA         NA
93      PC12            disability_est       12         NA         NA
94      PC12      eviction_filing_rate       12         NA         NA
95      PC12         est_underemp_perc       12         NA         NA
96      PC12            med_inc_hh_est       12         NA         NA
97      PC13  Energy_Burden____income_       13         NA         NA
98      PC13             uninsured_est       13         NA         NA
99      PC13      est_no_internet_perc       13         NA         NA
100     PC13            disability_est       13         NA         NA
101     PC13  less_than_highschool_est       13         NA         NA
102     PC13 low_physical_activity_est       13         NA         NA
103     PC13     est_65plus_ambulatory       13         NA         NA
104     PC13         est_underemp_perc       13         NA         NA
105     PC14             uninsured_est       14         NA         NA
106     PC14  less_than_highschool_est       14         NA         NA
107     PC14            med_inc_hh_est       14         NA         NA
108     PC14 low_physical_activity_est       14         NA         NA
109     PC14  Energy_Burden____income_       14         NA         NA
110     PC14            disability_est       14         NA         NA
111     PC14      eviction_filing_rate       14         NA         NA
112     PC14        persistent_poverty       14         NA         NA
113     PC15             below_pov_est       15         NA         NA
114     PC15             est_child_pov       15         NA         NA
115     PC15 low_physical_activity_est       15         NA         NA
116     PC15  less_than_highschool_est       15         NA         NA
117     PC15            med_inc_hh_est       15         NA         NA
118     PC15         est_underemp_perc       15         NA         NA
119     PC15        persistent_poverty       15         NA         NA
120     PC15  Energy_Burden____income_       15         NA         NA
121     PC16 low_physical_activity_est       16         NA         NA
122     PC16  less_than_highschool_est       16         NA         NA
123     PC16             below_pov_est       16         NA         NA
124     PC16             est_child_pov       16         NA         NA
125     PC16  Energy_Burden____income_       16         NA         NA
126     PC16      est_no_internet_perc       16         NA         NA
127     PC16            disability_est       16         NA         NA
128     PC16         est_underemp_perc       16         NA         NA
      loading5   loading6   loading7   loading8   loading9  loading10
1           NA         NA         NA         NA         NA         NA
2           NA         NA         NA         NA         NA         NA
3           NA         NA         NA         NA         NA         NA
4           NA         NA         NA         NA         NA         NA
5           NA         NA         NA         NA         NA         NA
6           NA         NA         NA         NA         NA         NA
7           NA         NA         NA         NA         NA         NA
8           NA         NA         NA         NA         NA         NA
9           NA         NA         NA         NA         NA         NA
10          NA         NA         NA         NA         NA         NA
11          NA         NA         NA         NA         NA         NA
12          NA         NA         NA         NA         NA         NA
13          NA         NA         NA         NA         NA         NA
14          NA         NA         NA         NA         NA         NA
15          NA         NA         NA         NA         NA         NA
16          NA         NA         NA         NA         NA         NA
17   0.5720965         NA         NA         NA         NA         NA
18  -0.4410464         NA         NA         NA         NA         NA
19  -0.3991605         NA         NA         NA         NA         NA
20  -0.3017962         NA         NA         NA         NA         NA
21   0.2909768         NA         NA         NA         NA         NA
22   0.1591099         NA         NA         NA         NA         NA
23   0.1474920         NA         NA         NA         NA         NA
24   0.1457073         NA         NA         NA         NA         NA
25          NA  0.6331530         NA         NA         NA         NA
26          NA  0.3735869         NA         NA         NA         NA
27          NA  0.3301717         NA         NA         NA         NA
28          NA -0.3067518         NA         NA         NA         NA
29          NA  0.2597827         NA         NA         NA         NA
30          NA -0.2254813         NA         NA         NA         NA
31          NA  0.2143052         NA         NA         NA         NA
32          NA -0.2002304         NA         NA         NA         NA
33          NA         NA  0.6317769         NA         NA         NA
34          NA         NA -0.3913639         NA         NA         NA
35          NA         NA -0.3319689         NA         NA         NA
36          NA         NA  0.2852734         NA         NA         NA
37          NA         NA -0.2835290         NA         NA         NA
38          NA         NA  0.1970508         NA         NA         NA
39          NA         NA -0.1776511         NA         NA         NA
40          NA         NA  0.1677476         NA         NA         NA
41          NA         NA         NA  0.6881147         NA         NA
42          NA         NA         NA  0.4186006         NA         NA
43          NA         NA         NA  0.3972334         NA         NA
44          NA         NA         NA  0.2466550         NA         NA
45          NA         NA         NA  0.2353944         NA         NA
46          NA         NA         NA -0.1457711         NA         NA
47          NA         NA         NA -0.1391771         NA         NA
48          NA         NA         NA -0.1049132         NA         NA
49          NA         NA         NA         NA -0.3980232         NA
50          NA         NA         NA         NA -0.3772934         NA
51          NA         NA         NA         NA  0.3580261         NA
52          NA         NA         NA         NA -0.3574175         NA
53          NA         NA         NA         NA  0.3316537         NA
54          NA         NA         NA         NA  0.2795170         NA
55          NA         NA         NA         NA  0.2677165         NA
56          NA         NA         NA         NA -0.2420589         NA
57          NA         NA         NA         NA         NA -0.5505328
58          NA         NA         NA         NA         NA  0.4808853
59          NA         NA         NA         NA         NA  0.3675718
60          NA         NA         NA         NA         NA -0.2972368
61          NA         NA         NA         NA         NA -0.2774428
62          NA         NA         NA         NA         NA -0.2055165
63          NA         NA         NA         NA         NA  0.2034605
64          NA         NA         NA         NA         NA -0.1836731
65          NA         NA         NA         NA         NA         NA
66          NA         NA         NA         NA         NA         NA
67          NA         NA         NA         NA         NA         NA
68          NA         NA         NA         NA         NA         NA
69          NA         NA         NA         NA         NA         NA
70          NA         NA         NA         NA         NA         NA
71          NA         NA         NA         NA         NA         NA
72          NA         NA         NA         NA         NA         NA
73          NA         NA         NA         NA         NA         NA
74          NA         NA         NA         NA         NA         NA
75          NA         NA         NA         NA         NA         NA
76          NA         NA         NA         NA         NA         NA
77          NA         NA         NA         NA         NA         NA
78          NA         NA         NA         NA         NA         NA
79          NA         NA         NA         NA         NA         NA
80          NA         NA         NA         NA         NA         NA
81          NA         NA         NA         NA         NA         NA
82          NA         NA         NA         NA         NA         NA
83          NA         NA         NA         NA         NA         NA
84          NA         NA         NA         NA         NA         NA
85          NA         NA         NA         NA         NA         NA
86          NA         NA         NA         NA         NA         NA
87          NA         NA         NA         NA         NA         NA
88          NA         NA         NA         NA         NA         NA
89          NA         NA         NA         NA         NA         NA
90          NA         NA         NA         NA         NA         NA
91          NA         NA         NA         NA         NA         NA
92          NA         NA         NA         NA         NA         NA
93          NA         NA         NA         NA         NA         NA
94          NA         NA         NA         NA         NA         NA
95          NA         NA         NA         NA         NA         NA
96          NA         NA         NA         NA         NA         NA
97          NA         NA         NA         NA         NA         NA
98          NA         NA         NA         NA         NA         NA
99          NA         NA         NA         NA         NA         NA
100         NA         NA         NA         NA         NA         NA
101         NA         NA         NA         NA         NA         NA
102         NA         NA         NA         NA         NA         NA
103         NA         NA         NA         NA         NA         NA
104         NA         NA         NA         NA         NA         NA
105         NA         NA         NA         NA         NA         NA
106         NA         NA         NA         NA         NA         NA
107         NA         NA         NA         NA         NA         NA
108         NA         NA         NA         NA         NA         NA
109         NA         NA         NA         NA         NA         NA
110         NA         NA         NA         NA         NA         NA
111         NA         NA         NA         NA         NA         NA
112         NA         NA         NA         NA         NA         NA
113         NA         NA         NA         NA         NA         NA
114         NA         NA         NA         NA         NA         NA
115         NA         NA         NA         NA         NA         NA
116         NA         NA         NA         NA         NA         NA
117         NA         NA         NA         NA         NA         NA
118         NA         NA         NA         NA         NA         NA
119         NA         NA         NA         NA         NA         NA
120         NA         NA         NA         NA         NA         NA
121         NA         NA         NA         NA         NA         NA
122         NA         NA         NA         NA         NA         NA
123         NA         NA         NA         NA         NA         NA
124         NA         NA         NA         NA         NA         NA
125         NA         NA         NA         NA         NA         NA
126         NA         NA         NA         NA         NA         NA
127         NA         NA         NA         NA         NA         NA
128         NA         NA         NA         NA         NA         NA
     loading11  loading12  loading13  loading14  loading15  loading16
1           NA         NA         NA         NA         NA         NA
2           NA         NA         NA         NA         NA         NA
3           NA         NA         NA         NA         NA         NA
4           NA         NA         NA         NA         NA         NA
5           NA         NA         NA         NA         NA         NA
6           NA         NA         NA         NA         NA         NA
7           NA         NA         NA         NA         NA         NA
8           NA         NA         NA         NA         NA         NA
9           NA         NA         NA         NA         NA         NA
10          NA         NA         NA         NA         NA         NA
11          NA         NA         NA         NA         NA         NA
12          NA         NA         NA         NA         NA         NA
13          NA         NA         NA         NA         NA         NA
14          NA         NA         NA         NA         NA         NA
15          NA         NA         NA         NA         NA         NA
16          NA         NA         NA         NA         NA         NA
17          NA         NA         NA         NA         NA         NA
18          NA         NA         NA         NA         NA         NA
19          NA         NA         NA         NA         NA         NA
20          NA         NA         NA         NA         NA         NA
21          NA         NA         NA         NA         NA         NA
22          NA         NA         NA         NA         NA         NA
23          NA         NA         NA         NA         NA         NA
24          NA         NA         NA         NA         NA         NA
25          NA         NA         NA         NA         NA         NA
26          NA         NA         NA         NA         NA         NA
27          NA         NA         NA         NA         NA         NA
28          NA         NA         NA         NA         NA         NA
29          NA         NA         NA         NA         NA         NA
30          NA         NA         NA         NA         NA         NA
31          NA         NA         NA         NA         NA         NA
32          NA         NA         NA         NA         NA         NA
33          NA         NA         NA         NA         NA         NA
34          NA         NA         NA         NA         NA         NA
35          NA         NA         NA         NA         NA         NA
36          NA         NA         NA         NA         NA         NA
37          NA         NA         NA         NA         NA         NA
38          NA         NA         NA         NA         NA         NA
39          NA         NA         NA         NA         NA         NA
40          NA         NA         NA         NA         NA         NA
41          NA         NA         NA         NA         NA         NA
42          NA         NA         NA         NA         NA         NA
43          NA         NA         NA         NA         NA         NA
44          NA         NA         NA         NA         NA         NA
45          NA         NA         NA         NA         NA         NA
46          NA         NA         NA         NA         NA         NA
47          NA         NA         NA         NA         NA         NA
48          NA         NA         NA         NA         NA         NA
49          NA         NA         NA         NA         NA         NA
50          NA         NA         NA         NA         NA         NA
51          NA         NA         NA         NA         NA         NA
52          NA         NA         NA         NA         NA         NA
53          NA         NA         NA         NA         NA         NA
54          NA         NA         NA         NA         NA         NA
55          NA         NA         NA         NA         NA         NA
56          NA         NA         NA         NA         NA         NA
57          NA         NA         NA         NA         NA         NA
58          NA         NA         NA         NA         NA         NA
59          NA         NA         NA         NA         NA         NA
60          NA         NA         NA         NA         NA         NA
61          NA         NA         NA         NA         NA         NA
62          NA         NA         NA         NA         NA         NA
63          NA         NA         NA         NA         NA         NA
64          NA         NA         NA         NA         NA         NA
65  -0.4401481         NA         NA         NA         NA         NA
66  -0.4279389         NA         NA         NA         NA         NA
67  -0.4069827         NA         NA         NA         NA         NA
68  -0.3591117         NA         NA         NA         NA         NA
69   0.2825587         NA         NA         NA         NA         NA
70   0.2775109         NA         NA         NA         NA         NA
71   0.2475081         NA         NA         NA         NA         NA
72   0.1756149         NA         NA         NA         NA         NA
73          NA  0.6125342         NA         NA         NA         NA
74          NA -0.4294181         NA         NA         NA         NA
75          NA  0.3776642         NA         NA         NA         NA
76          NA  0.3230627         NA         NA         NA         NA
77          NA  0.2224785         NA         NA         NA         NA
78          NA -0.2175248         NA         NA         NA         NA
79          NA  0.1962192         NA         NA         NA         NA
80          NA  0.1864716         NA         NA         NA         NA
81          NA         NA  0.5622539         NA         NA         NA
82          NA         NA -0.5574847         NA         NA         NA
83          NA         NA -0.3170848         NA         NA         NA
84          NA         NA  0.2658291         NA         NA         NA
85          NA         NA -0.2298704         NA         NA         NA
86          NA         NA -0.2284559         NA         NA         NA
87          NA         NA  0.1574557         NA         NA         NA
88          NA         NA -0.1550764         NA         NA         NA
89          NA         NA         NA -0.6123472         NA         NA
90          NA         NA         NA  0.4878974         NA         NA
91          NA         NA         NA  0.3175205         NA         NA
92          NA         NA         NA -0.2678328         NA         NA
93          NA         NA         NA -0.2380919         NA         NA
94          NA         NA         NA  0.2054327         NA         NA
95          NA         NA         NA  0.1916358         NA         NA
96          NA         NA         NA -0.1909172         NA         NA
97          NA         NA         NA         NA -0.5787509         NA
98          NA         NA         NA         NA  0.4170957         NA
99          NA         NA         NA         NA -0.3887958         NA
100         NA         NA         NA         NA  0.3386366         NA
101         NA         NA         NA         NA  0.2913143         NA
102         NA         NA         NA         NA  0.2037509         NA
103         NA         NA         NA         NA -0.1849307         NA
104         NA         NA         NA         NA  0.1757315         NA
105         NA         NA         NA         NA         NA -0.6544238
106         NA         NA         NA         NA         NA  0.4341611
107         NA         NA         NA         NA         NA -0.4049650
108         NA         NA         NA         NA         NA  0.3170131
109         NA         NA         NA         NA         NA -0.2084212
110         NA         NA         NA         NA         NA -0.1314154
111         NA         NA         NA         NA         NA -0.1176398
112         NA         NA         NA         NA         NA -0.1145323
113         NA         NA         NA         NA         NA         NA
114         NA         NA         NA         NA         NA         NA
115         NA         NA         NA         NA         NA         NA
116         NA         NA         NA         NA         NA         NA
117         NA         NA         NA         NA         NA         NA
118         NA         NA         NA         NA         NA         NA
119         NA         NA         NA         NA         NA         NA
120         NA         NA         NA         NA         NA         NA
121         NA         NA         NA         NA         NA         NA
122         NA         NA         NA         NA         NA         NA
123         NA         NA         NA         NA         NA         NA
124         NA         NA         NA         NA         NA         NA
125         NA         NA         NA         NA         NA         NA
126         NA         NA         NA         NA         NA         NA
127         NA         NA         NA         NA         NA         NA
128         NA         NA         NA         NA         NA         NA
      loading17   loading18
1            NA          NA
2            NA          NA
3            NA          NA
4            NA          NA
5            NA          NA
6            NA          NA
7            NA          NA
8            NA          NA
9            NA          NA
10           NA          NA
11           NA          NA
12           NA          NA
13           NA          NA
14           NA          NA
15           NA          NA
16           NA          NA
17           NA          NA
18           NA          NA
19           NA          NA
20           NA          NA
21           NA          NA
22           NA          NA
23           NA          NA
24           NA          NA
25           NA          NA
26           NA          NA
27           NA          NA
28           NA          NA
29           NA          NA
30           NA          NA
31           NA          NA
32           NA          NA
33           NA          NA
34           NA          NA
35           NA          NA
36           NA          NA
37           NA          NA
38           NA          NA
39           NA          NA
40           NA          NA
41           NA          NA
42           NA          NA
43           NA          NA
44           NA          NA
45           NA          NA
46           NA          NA
47           NA          NA
48           NA          NA
49           NA          NA
50           NA          NA
51           NA          NA
52           NA          NA
53           NA          NA
54           NA          NA
55           NA          NA
56           NA          NA
57           NA          NA
58           NA          NA
59           NA          NA
60           NA          NA
61           NA          NA
62           NA          NA
63           NA          NA
64           NA          NA
65           NA          NA
66           NA          NA
67           NA          NA
68           NA          NA
69           NA          NA
70           NA          NA
71           NA          NA
72           NA          NA
73           NA          NA
74           NA          NA
75           NA          NA
76           NA          NA
77           NA          NA
78           NA          NA
79           NA          NA
80           NA          NA
81           NA          NA
82           NA          NA
83           NA          NA
84           NA          NA
85           NA          NA
86           NA          NA
87           NA          NA
88           NA          NA
89           NA          NA
90           NA          NA
91           NA          NA
92           NA          NA
93           NA          NA
94           NA          NA
95           NA          NA
96           NA          NA
97           NA          NA
98           NA          NA
99           NA          NA
100          NA          NA
101          NA          NA
102          NA          NA
103          NA          NA
104          NA          NA
105          NA          NA
106          NA          NA
107          NA          NA
108          NA          NA
109          NA          NA
110          NA          NA
111          NA          NA
112          NA          NA
113  0.63565250          NA
114 -0.56119357          NA
115  0.40003779          NA
116 -0.21507163          NA
117  0.19480713          NA
118 -0.12457965          NA
119 -0.11935154          NA
120 -0.06339945          NA
121          NA -0.65801523
122          NA  0.55761951
123          NA  0.42577756
124          NA -0.16922291
125          NA  0.10903908
126          NA -0.10320491
127          NA  0.09214728
128          NA -0.06300568
write_xlsx(top_by_pc, "top_by_pc_loadings.xlsx")

How much variance of each variable is explained by retained PCs:

# communalities

# choose how many PCs to keep; common choices: Kaiser (eigenvalue > 1) or target cum var (e.g., 70–90%)
k_kaiser <- sum(eigs > 1)
k_target <- which(scree_df$CumVariance >= 0.80)[1]  # 80% target
k <- max(k_kaiser, k_target, na.rm = TRUE)          # take the more conservative

communalities <- loadings %>%
  select(variable, starts_with("PC")) %>%
  mutate(comm = rowSums(across(all_of(paste0("PC", 1:k)), ~ .x^2))) %>%
  arrange(desc(comm))

print(communalities)
                    variable         PC1          PC2         PC3          PC4
1      hh_support_risk_score -0.12257075 -0.192566024 -0.02158305 -0.067553212
2              EAL_VALP_x100 -0.02318265  0.176841057  0.57209650  0.330171652
3       eviction_filing_rate -0.15840422 -0.205533767  0.14221524  0.633152997
4          est_underemp_perc -0.05315104  0.567262483  0.08298070  0.214305204
5         persistent_poverty -0.09385071  0.450469043 -0.30179617 -0.093404355
6      est_65plus_ambulatory -0.17561781 -0.220844434 -0.44104635  0.259782674
7              est_child_pov -0.27426979  0.296846344 -0.05667610  0.004665550
8             disability_est -0.22751972 -0.126455168 -0.39916048  0.373586874
9              below_pov_est -0.30142538  0.394075716 -0.10220272 -0.002610449
10      est_no_internet_perc -0.27928939 -0.028571030 -0.10915903 -0.306751751
11    limited_english_hh_est -0.28281056 -0.135608389  0.29097681 -0.225481302
12  less_than_highschool_est -0.33680830 -0.156041412  0.15910990 -0.142843638
13             uninsured_est -0.32435184 -0.107291206  0.14749204 -0.200230424
14  Energy_Burden____income_ -0.31280460 -0.004546782  0.14570731  0.131651646
15            med_inc_hh_est  0.29392382  0.024410189  0.10630089  0.031287002
16 low_physical_activity_est -0.37169856 -0.028861120  0.10176329 -0.007787522
            PC5          PC6         PC7         PC8         PC9        PC10
1   0.631776884  0.688114666 -0.08919894 -0.11009949  0.17561492 -0.08384274
2  -0.391363947  0.397233418 -0.37729335 -0.01969984 -0.11689732 -0.21752479
3   0.159567620 -0.031071953  0.35802607  0.48088534  0.06494485  0.19621923
4   0.167747590 -0.100426623  0.33165372 -0.55053279  0.15553563  0.04382249
5  -0.331968920  0.418600650  0.26771645  0.36757176  0.28255868  0.05988743
6  -0.283528975  0.056926744 -0.35741752 -0.29723685  0.27751095  0.37766423
7   0.285273404 -0.139177146 -0.39802319  0.20346047 -0.35911174  0.22247848
8  -0.076138555  0.024540427  0.10419107 -0.18367306 -0.44014812 -0.42941809
9   0.197050788 -0.104913200 -0.24205890  0.16965068 -0.04708850  0.01068496
10 -0.177651104  0.246654996  0.27951704 -0.05084615 -0.42793889 -0.06870411
11  0.014572008 -0.145771139  0.18668766 -0.02898556  0.01647929 -0.05322249
12 -0.167335888  0.033952102  0.14842063 -0.03280339 -0.05708407  0.32306273
13 -0.128210714 -0.088534367 -0.16086094 -0.04105774  0.24750807 -0.01003594
14  0.030932706 -0.040568894  0.11199850 -0.27744276  0.17073332 -0.05486867
15  0.006582387  0.235394355  0.10185309 -0.20551648 -0.40698268  0.61253415
16 -0.016744989  0.008430128  0.02053257 -0.01954764 -0.05116360  0.18647160
          PC11         PC12        PC13        PC14         PC15         PC16
1  -0.05166448 -0.014814232  0.08108038  0.02839669 -0.032220785  0.031077894
2  -0.10834435  0.008586888 -0.02385762  0.06698205 -0.010858560  0.014685278
3  -0.15507642  0.205432696 -0.05238840 -0.11763979 -0.007618753 -0.009088448
4  -0.22845587  0.191635758  0.17573155  0.07662215 -0.124579654 -0.063005682
5   0.08627780 -0.267832820  0.06411605 -0.11453231 -0.119351539 -0.046646774
6  -0.31708482 -0.010407046 -0.18493073  0.05347247 -0.008717650 -0.034963888
7   0.01898869 -0.069556863 -0.05856644 -0.04683241 -0.561193573 -0.169222911
8   0.08406867 -0.238091851  0.33863662 -0.13141542 -0.005942485  0.092147276
9  -0.10363783  0.025685879 -0.07671584 -0.03503129  0.635652502  0.425777562
10 -0.22987036  0.487897424 -0.38879575 -0.03588967  0.014744685 -0.103204909
11 -0.55748468 -0.612347167 -0.08036175 -0.11109360 -0.010688309 -0.034478320
12  0.15745571  0.035448304  0.29131426  0.43416111 -0.215071626  0.557619507
13  0.04948301  0.317520514  0.41709565 -0.65442376 -0.036474033 -0.037438548
14  0.56225389 -0.169876992 -0.57875086 -0.20842118 -0.063399449  0.109039082
15  0.07437067 -0.190917227  0.06332763 -0.40496503  0.194807127  0.062442100
16  0.26582908 -0.079719393  0.20375091  0.31701306  0.400037792 -0.658015231
        comm
1  0.9498567
2  0.9218164
3  0.8743046
4  0.8287296
5  0.8037466
6  0.6413492
7  0.4671454
8  0.4176433
9  0.3938148
10 0.3579449
11 0.2910348
12 0.2357678
13 0.2303999
14 0.2285510
15 0.2073307
16 0.1505644
write_xlsx(communalities, "communalities.xlsx")

Final read-out

# 1) If the first 1–2 PCs explain a large share of variance (e.g., > 60–70%),
#    your predictors share substantial common signal (i.e., multicollinearity).
# 2) Variables with very high absolute loadings on the SAME PC tend to be redundant.
# 3) High communalities (~0.7+) mean a variable is largely explained by the common factors (less unique info).

cat("\n--- PCA quick summary ---\n")

--- PCA quick summary ---
cat(sprintf("Eigenvalues (first 5): %s\n", paste(round(eigs[1:min(5, length(eigs))], 2), collapse = ", ")))
Eigenvalues (first 5): 6.01, 1.62, 1.21, 1.03, 0.97
cat(sprintf("Variance explained by first 5 PCs: %s\n", paste(round(100*var_explained[1:min(5, length(var_explained))], 1), collapse = "%, "), "%\n"))
Warning in sprintf("Variance explained by first 5 PCs: %s\n", paste(round(100 * : one argument not used by format 'Variance explained by first 5 PCs: %s
'
Variance explained by first 5 PCs: 37.6%, 10.1%, 7.6%, 6.4%, 6.1
cat(sprintf("Cumulative variance (first %d PCs): %.1f%%\n", k, 100*scree_df$CumVariance[k]))
Cumulative variance (first 8 PCs): 82.5%
cat(sprintf("Kaiser PCs (eigenvalue > 1): %d\n", k_kaiser))
Kaiser PCs (eigenvalue > 1): 4
cat(sprintf("PCs to reach 80%% variance: %d\n", k_target))
PCs to reach 80% variance: 8
cat("Inspect `top_by_pc` and `communalities` to see clusters/redundancy.\n")
Inspect `top_by_pc` and `communalities` to see clusters/redundancy.
# ---- Optional: biplot (exploratory) ----
# plot(pca, type = "l")  # another scree
# biplot(pca, scale = 0) # can be busy on large datasets