When cos2/contrib are not supplied they are computed from the
coordinates:
contrib = 100 * coord^2 / colSums(coord^2) - the exact
contribution of each element to each dimension.
cos2 = coord^2 / rowSums(coord^2) - the quality of
representation within the supplied dimensions. This equals the true
cos2 only when all components are provided; with a truncated set of
dimensions it is the quality restricted to that sub-space. Pass
ind.cos2/var.cos2 explicitly if you have the exact values.
tidymodels (recipe / workflow). The recipe and workflow
methods extract a PCA fitted with recipes::step_pca() through the public
recipes/workflows API: the scores from the baked training data (or, for a fitted
workflow, workflows::extract_mold()), the loadings from
tidy(step, type = "coef"), and the full set of eigenvalues from
tidy(step, type = "variance") (so the scree plot and axis percentages are
honest even when num_comp keeps only a few components). Variable
coordinates are loading times the square root of the eigenvalue. Exact
variable-component correlations and cos2 are recovered from the full PCA
inertia when every PCA input is provably centered. When those metrics cannot
be recovered (for example, for a bare step_pca() with no centering or a
zero-inertia variable), their entries in get_pca_var() are NULL.
Scores, eigenvalues, variable coordinates and contributions are still returned,
so the individual, scree, variable-arrow and biplot displays remain available;
correlation/cos2-dependent displays fail with an explicit unavailable-metric
error. The correlation circle is omitted and a warning explains how to recover
the metrics. scale.unit is set to TRUE only when every
PCA input is both centered and unit-scaled at the PCA boundary; partial scaling
therefore does not draw a correlation circle. For fully normalized data,
variable coordinates, correlations, cos2 and contributions, and the eigenvalue
percentages match a full FactoMineR::PCA() regardless of how many
components step_pca() keeps; the individual cos2 is computed over
the retained components (it equals the full-space cos2 only when all components
are kept). The two-dimensional plots (fviz_pca_ind(),
fviz_pca_var(), fviz_pca_biplot()) need num_comp >= 2. The
recipe must be prepped, and its single PCA step must be an unweighted
step_pca() and must be the final recipe step. Case-weighted PCA is
rejected because the adapter cannot yet propagate those weights into individual
contributions. Later steps could transform the baked/mold PCA
scores without updating the fitted PCA loadings or eigenvalues, so such recipes
fail explicitly instead of returning internally inconsistent geometry.
Non-linear embedding steps such as step_umap() have no eigenvalues and
are rejected with a message. For the loadings display of a recipe PCA see also
learntidymodels::plot_top_loadings().