For a study 102 children tasted 11 different types of ice cream (e.g. Magnum, Cornetto, Calippo). The children evaluated each type of ice cream on 14 properties. They classified statements like ‘tastes excellent’ or ‘looks good’ with ‘true’ or ‘false’. The data set (csv, rda) contains aggregated data, which for each combination of ice cream type and statement indicates the proportion of children who rated the statement as ‘true’.
Carry out a principal component analysis (PCA) with scaling using this data.
Compute the rotation matrix. Compute and visualize the variances explained by each component (screeplot). Provide the biplot of the first two principal components.
## Loading the necessary library for PCA
library(stats)
## Loading the data from the CSV file
Ice_1_ <- read.csv("~/Downloads/Ice (1).csv")
# Removing non-numeric columns (e.g., the first two columns with ice cream and statement names)
Ice_1_numeric <- Ice_1_[, -(1:2)]
In Principal Component Analysis (PCA), the rotation matrix is a matrix that specifies how the original variables (features) are linearly combined to create new variables called principal components. The purpose of the rotation matrix is to change the representation of the data from the original feature space to the principal component space, where the new variables (principal components) are orthogonal (uncorrelated) and capture the maximum variance in the data.
The rotation matrix is essentially a linear transformation that reorients the axes of the data. Each column of the rotation matrix corresponds to a principal component, and the elements of each column indicate the weights or coefficients for the original variables in that principal component. By multiplying the data by this rotation matrix, you transform the data into the space of principal components, which simplifies interpretation and often reduces multicollinearity among variables.
# Performing PCA with scaling
pca_result <- prcomp(Ice_1_numeric, scale. = TRUE)
# Computing the rotation matrix
rotation_matrix <- pca_result$rotation
A screeplot is a graphical representation used in Principal Component Analysis (PCA) to visualize the eigenvalues of principal components. In a screeplot, the eigenvalues, which represent the amount of variance explained by each principal component, are plotted against the corresponding component number. The plot helps identify an “elbow” point where the eigenvalues start to level off, indicating that additional components explain very little variance. This point assists in determining the optimal number of principal components to retain, allowing for dimensionality reduction while retaining as much of the original data’s variance as possible, thus simplifying data interpretation and analysis.
# Computing and visualizing the variances explained by each component (screeplot)
screeplot(pca_result, type = "line")
# Create a biplot of the first two principal components
biplot(pca_result, scale = 0)