This function performs Principal Component Analysis (PCA) on the input data, providing a detailed analysis of variance, eigenvalues, and eigenvectors. It offers options to generate a scree plot for visualizing variance explained by each principal component and a biplot to understand the relationship between variables and observations in reduced dimensions.
pca(
data,
variance_threshold = 0.9,
center = TRUE,
scale = FALSE,
scree_plot = FALSE,
biplot = FALSE,
choices = 1:2,
groups = NULL,
length_scale = 1,
scree_legend = TRUE,
scree_legend_pos = c(0.7, 0.5),
html = FALSE
)
A list containing: - summary_table: A matrix summarizing eigenvalues and cumulative variance explained. - scree_plot: A scree plot if scree_plot is TRUE. - biplot: A biplot if biplot is TRUE.
Numeric matrix or data frame containing the variables for PCA.
Proportion of total variance to retain (default: 0.90).
Logical, indicating whether to center the data (default: TRUE).
Logical, indicating whether to scale the data (default: FALSE).
Logical, whether to generate a scree plot (default: FALSE).
Logical, whether to generate a biplot (default: FALSE).
Numeric vector of length 2, indicating the principal components to plot in the biplot.
Optional grouping variable for coloring points in the biplot.
Scaling factor for adjusting the length of vectors in the biplot (default: 1).
Logical, indicating whether to show legend in scree plot (default: True).
A vector c(x, y) to adjust the position of the legend.
Whether the output should be in HTML format,used when knitting into HTML. Default is FALSE.
data(mtcars)
pca_result <- pca(mtcars, scree_plot = TRUE, biplot = TRUE)
pca_result$summary_table
pca_result$scree_plot
pca_result$biplot
Run the code above in your browser using DataLab