pca {AnalysisLin}R Documentation

Principal Component Analysis (PCA)

Description

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.

Usage

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
)

Arguments

data

Numeric matrix or data frame containing the variables for PCA.

variance_threshold

Proportion of total variance to retain (default: 0.90).

center

Logical, indicating whether to center the data (default: TRUE).

scale

Logical, indicating whether to scale the data (default: FALSE).

scree_plot

Logical, whether to generate a scree plot (default: FALSE).

biplot

Logical, whether to generate a biplot (default: FALSE).

choices

Numeric vector of length 2, indicating the principal components to plot in the biplot.

groups

Optional grouping variable for coloring points in the biplot.

length_scale

Scaling factor for adjusting the length of vectors in the biplot (default: 1).

scree_legend

Logical, indicating whether to show legend in scree plot (default: True).

scree_legend_pos

A vector c(x, y) to adjust the position of the legend.

html

Whether the output should be in HTML format,used when knitting into HTML. Default is FALSE.

Value

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.

Examples

data(mtcars)
pca_result <- pca(mtcars, scree_plot = TRUE, biplot = TRUE)
pca_result$summary_table
pca_result$scree_plot
pca_result$biplot


[Package AnalysisLin version 0.1.2 Index]