This function calculates the coordinate points for drawing a Hotelling's T-squared ellipse based on multivariate data. It can generate points for both 2D and 3D ellipses.

ellipseCoord(x, pcx = 1, pcy = 2, pcz = NULL, conf.limit = 0.95, pts = 200)

Arguments

x

A matrix, data frame or tibble containing scores from PCA, PLS, ICA, or other dimensionality reduction methods. Each column should represent a component, and each row an observation.

pcx

An integer specifying which component to use for the x-axis (default is 1).

pcy

An integer specifying which component to use for the y-axis (default is 2).

pcz

An integer specifying which component to use for the z-axis for 3D ellipsoids. If NULL (default), a 2D ellipse is computed.

conf.limit

A numeric value between 0 and 1 specifying the confidence level for the ellipse (default is 0.95, i.e., 95% confidence).

pts

An integer specifying the number of points to generate for drawing the ellipse (default is 200). Higher values result in smoother ellipses.

Value

A data frame containing the coordinate points of the Hotelling's T-squared ellipse:

  • For 2D ellipses: columns x and y

  • For 3D ellipsoids: columns x, y, and z

Details

The function computes the shape and orientation of the ellipse based on the Hotelling's T-squared distribution and the specified components. It then generates a set of points that lie on the ellipse's surface at the specified confidence level. For 2D ellipses, the function uses two components pcx and pcy. For 3D ellipsoids, it uses three components pcx, pcy, and pcz. The conf.limit parameter determines the size of the ellipse. A higher confidence level results in a larger ellipse that encompasses more data points.

Author

Christian L. Goueguel christian.goueguel@gmail.com

Examples

if (FALSE) {
# Load required libraries
library(HotellingEllipse)
library(dplyr)

data("specData", package = "HotellingEllipse")

# Perform PCA
set.seed(123)
pca_mod <- specData %>%
  select(where(is.numeric)) %>%
  FactoMineR::PCA(scale.unit = FALSE, graph = FALSE)

# Extract PCA scores
pca_scores <- pca_mod$ind$coord %>% as.data.frame()

# Example 1: Calculate Hotelling's T-squared ellipse coordinates
xy_coord <- ellipseCoord(pca_scores, pcx = 1, pcy = 2)

# Example 2: Calculate Hotelling's T-squared ellipsoid coordinates
xyz_coord <- ellipseCoord(pca_scores, pcx = 1, pcy = 2, pcz = 3)
}