utils_pca: Utilities for Principal Component Axis analysis

utils_pcaR Documentation

Utilities for Principal Component Axis analysis

Description

  • pca() Computes a Principal Component Analysis. It wrappers stats::prcomp(), but returns more results such as data, scores, contributions and quality of measurements for individuals and variables.

  • get_biplot(): Produces a biplot for an object computed with pca().

  • plot.pca(): Produces several types of plots, depending on the type and which arguments.

    • type = "var" Produces a barplot with the contribution (which = "contrib"), qualitity of adjustment which = "cos2", and a scatter plot with coordinates (which = "coord") for the variables.

    • type = "ind" Produces a barplot with the contribution (which = "contrib"), qualitity of adjustment which = "cos2", and a scatter plot with coordinates (which = "coord") for the individuals.

    • type = "biplot" Produces a biplot.

Usage

pca(x, scale = TRUE)

get_biplot(
  x,
  axes = c(1, 2),
  show = c("both"),
  show_ind_id = TRUE,
  show_unit_circle = TRUE,
  expand = NULL
)

## S3 method for class 'pca'
plot(x, type = "var", which = "contrib", axis = 1, ...)

Arguments

x
  • For pca(), a numeric or complex matrix (or data frame) which provides the data for the principal components analysis.

  • For plot.pca() and get_biplot(), an object computed with pca().

scale

A logical value indicating whether the variables should be scaled to have unit variance before the analysis takes place. Defaults to TRUE.

axes

The principal component axes to plot. Defaults to axes = c(1, 2), i.e., the first and second interaction principal component axis.

show

Which to show in the biplot. Defaults to "both" (both variables and individuals). One can also use "var", or "ind".

show_ind_id

Shows the labels for individuals? Defaults to TRUE.

show_unit_circle

Shows the unit variance circle? Defaults to TRUE.

expand

An expansion factor to apply when plotting the second set of points relative to the first. This can be used to tweak the scaling of the two sets to a physically comparable scale. Setting to TRUE will automatically compute the expansion factor. Alternatively, a numeric value can be informed.

type

One of "var" (to plot variables), "ind" (to plot individuals), or "biplot" to create a biplot.

which

Which measure to plot. Either which = "contribution" (default), which = "cos2" (quality of representation), or which = "coord" (coordinates)

axis

The axist to plot the contribution/cos2. Defaults to 1.

...

Further arguments passed on to get_biplot() when type = "biplot". Otherwise, When which = "coord", further arguments passed on to get_biplot(). When which = "contrib", or which = "cos2" further arguments passed on to graphics::barplot().

Value

  • pca() returns a list including:

    • data: The raw data used to compute the PCA.

    • variances: Variances (eigenvalues), and proportion of explained variance for each component.

    • ⁠center,scale⁠: the centering and scaling used.

    • ⁠ind,var⁠ A list with the following objects for individuals/variables, respectively.

    • coord: coordinates for the individuals/variables (loadings * the component standard deviations)

    • cos2: cos2 for the individuals/variables (coord^2)

    • contrib: The contribution (in percentage) of a variable to a given principal component: (cos2 * 100) / (total cos2 of the component)

  • plot.pca() returns a list with the coordinates used.

  • get_biplot() returns a NULL object

Examples

library(pliman)
pc <- pca(mtcars[1:10 ,1:6])
plot(pc)
plot(pc, type = "ind")
plot(pc, type = "var", which = "coord")
plot(pc, type = "ind", which = "coord")
plot(pc, type = "biplot")

pliman documentation built on Oct. 15, 2023, 1:06 a.m.

Related to utils_pca in pliman...