| Title: | Advanced Principal Component Analysis |
|---|---|
| Description: | Provides nine computational algorithms for dimensionality reduction via Principal Component Analysis (PCA), built using an object-oriented (S3) architecture. The package includes classical and modern methods: Singular Value Decomposition (SVD) based on Eckart and Young (1936) <doi:10.1007/BF02288367>, Power Iteration based on Hotelling (1933) <doi:10.1037/h0071325>, QR Algorithm based on Francis (1961) <doi:10.1093/comjnl/4.3.265>, Jacobi Algorithm based on Jacobi (1846) <doi:10.1515/crll.1846.30.51>, Arnoldi Iteration based on Arnoldi (1951) <doi:10.1090/qam/42792>, 'NIPALS' based on Wold (1975) <doi:10.1017/S0021900200047604>, Alternating Least Squares (ALS) based on Kolda and Bader (2009) <doi:10.1137/07070111X>, Probabilistic PCA (PPCA) with EM Algorithm based on Tipping and Bishop (1999) <doi:10.1111/1467-9868.00196>, and Generalized Hebbian Algorithm (GHA) based on Sanger (1989) <doi:10.1016/0893-6080(89)90044-0>. |
| Authors: | Angga Dwi Mulyanto [aut, cre] (Institut Teknologi Sepuluh Nopember, Universitas Islam Negeri Maulana Malik Ibrahim Malang), Bambang Widjanarko Otok [aut] (Institut Teknologi Sepuluh Nopember), Jerry Dwi Trijoyo Purnomo [aut] (Institut Teknologi Sepuluh Nopember) |
| Maintainer: | Angga Dwi Mulyanto <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-05-29 09:12:59 UTC |
| Source: | https://github.com/cran/apca |
Performs PCA using one of nine different computational algorithms. This is the main wrapper function for the apca package.
apca(data, n_components = 2, method = "svd", center = TRUE, scale = FALSE)apca(data, n_components = 2, method = "svd", center = TRUE, scale = FALSE)
data |
A numeric matrix or data frame. |
n_components |
Integer. Number of principal components to extract. |
method |
Character. The algorithm to use: "svd", "power", "qr", "nipals", "jacobi", "arnoldi", "als", "ppca", or "gha". |
center |
Logical. Whether to mean-center the data. Default is TRUE. |
scale |
Logical. Whether to scale variables to unit variance. Default is FALSE. |
An object of class "apca" containing scores, loadings, and variance metrics.
# Run PCA using the classical SVD algorithm data(mtcars) res_svd <- apca(mtcars, n_components = 2, method = "svd", scale = TRUE) # Print basic information print(res_svd) # --------------------------------------------------------- # Extracting specific mathematical components # --------------------------------------------------------- # 1. Extract the PCA scores (useful for clustering/regression) my_scores <- res_svd$scores head(my_scores) # 2. Extract the loadings matrix (variable weights) my_loadings <- res_svd$loadings print(my_loadings) # 3. Extract the eigenvalues my_eigen <- res_svd$eigenvalues print(my_eigen) # Run PCA using the NIPALS algorithm res_nipals <- apca(mtcars, n_components = 2, method = "nipals", scale = TRUE)# Run PCA using the classical SVD algorithm data(mtcars) res_svd <- apca(mtcars, n_components = 2, method = "svd", scale = TRUE) # Print basic information print(res_svd) # --------------------------------------------------------- # Extracting specific mathematical components # --------------------------------------------------------- # 1. Extract the PCA scores (useful for clustering/regression) my_scores <- res_svd$scores head(my_scores) # 2. Extract the loadings matrix (variable weights) my_loadings <- res_svd$loadings print(my_loadings) # 3. Extract the eigenvalues my_eigen <- res_svd$eigenvalues print(my_eigen) # Run PCA using the NIPALS algorithm res_nipals <- apca(mtcars, n_components = 2, method = "nipals", scale = TRUE)
Generates a scatter plot of the principal component scores.
## S3 method for class 'apca' plot( x, pc_x = 1, pc_y = 2, col = "steelblue", pch = 16, cex = 1.2, las = 1, ... )## S3 method for class 'apca' plot( x, pc_x = 1, pc_y = 2, col = "steelblue", pch = 16, cex = 1.2, las = 1, ... )
x |
An object of class "apca". |
pc_x |
Integer. The principal component to plot on the X-axis (default: 1). |
pc_y |
Integer. The principal component to plot on the Y-axis (default: 2). |
col |
Color of the points (default: "steelblue"). |
pch |
Point character (default: 16). |
cex |
Point size (default: 1.2). |
las |
Axis label orientation (default: 1). |
... |
Additional graphical parameters passed to the base plot function. |
No return value, called for side effects (plotting).
data(mtcars) res <- apca(mtcars, n_components = 3, method = "svd", scale = TRUE) # Plot PC1 vs PC2 (Default) plot(res) # Plot PC1 vs PC3 with custom base R graphical parameters plot(res, pc_x = 1, pc_y = 3, col = "red", pch = 19)data(mtcars) res <- apca(mtcars, n_components = 3, method = "svd", scale = TRUE) # Plot PC1 vs PC2 (Default) plot(res) # Plot PC1 vs PC3 with custom base R graphical parameters plot(res, pc_x = 1, pc_y = 3, col = "red", pch = 19)
Extracts and calculates cumulative variance metrics from an APCA object.
## S3 method for class 'apca' summary(object, ...)## S3 method for class 'apca' summary(object, ...)
object |
An object of class "apca". |
... |
Additional arguments affecting the summary produced. |
A list of class "summary.apca" containing variance explained, cumulative variance, and other specific algorithm metrics (like noise variance).
data(mtcars) res <- apca(mtcars, n_components = 3, method = "svd", scale = TRUE) # Display cumulative variance summary summary(res)data(mtcars) res <- apca(mtcars, n_components = 3, method = "svd", scale = TRUE) # Display cumulative variance summary summary(res)