| pca | R Documentation |
Computes principal components from a numeric matrix or data frame with automatic scaling and zero-variance removal. Returns all principal components as a data frame. Wrapper for stats::prcomp().
pca(x = NULL, colnames.prefix = "pca_factor")
x |
Numeric matrix or data frame to decompose into principal components. |
colnames.prefix |
Character string used as prefix for column names in the output. Default: |
This function performs Principal Component Analysis (PCA) to create uncorrelated linear combinations of the original variables. The PCA process:
Removes columns with zero variance (constant values)
Scales all remaining variables to mean = 0 and standard deviation = 1
Computes principal components using singular value decomposition
Returns all principal components ordered by decreasing variance explained
Usage in spatial analysis:
PCA is useful for dimension reduction when working with spatial distance matrices or multiple correlated spatial predictors. It creates orthogonal (uncorrelated) variables that capture the main patterns of variation while reducing dimensionality.
For spatial modeling with rf_spatial(), principal components of distance matrices can serve as alternative spatial predictors to Moran's Eigenvector Maps (MEMs). Use pca_multithreshold() to compute PCA across multiple distance thresholds for multi-scale spatial modeling.
Data frame where each column is a principal component, ordered by decreasing variance explained. Columns are named with the pattern <prefix>_<number> (e.g., "pca_factor_1", "pca_factor_2"). The number of rows matches the number of rows in x.
pca_multithreshold(), mem(), stats::prcomp()
Other spatial_analysis:
filter_spatial_predictors(),
mem(),
mem_multithreshold(),
moran(),
moran_multithreshold(),
pca_multithreshold(),
rank_spatial_predictors(),
residuals_diagnostics(),
residuals_test(),
select_spatial_predictors_recursive(),
select_spatial_predictors_sequential()
data(plants_distance)
# Compute principal components from distance matrix
pca_components <- pca(x = plants_distance)
# View structure
head(pca_components)
dim(pca_components)
# Check column names
colnames(pca_components)[1:5]
# Custom column prefix
pca_custom <- pca(
x = plants_distance,
colnames.prefix = "distance_pc"
)
colnames(pca_custom)[1:3]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.