Beginner's PCA Guide in R: Corrections & Tips
Beginner's PCA Guide in R: Corrections & Tips
The purpose of generating a scree plot in PCA is to visualize the number of components to retain by displaying the eigenvalues associated with each component and identifying any inflection points. In R, the implementation has evolved from using the obsolete scree.plot() in the psy package to the scree() or fa.parallel() in the psych package, which provide better visualization and component selection methods .
The guide suggests avoiding the 'attach' function because it can lead to variable conflicts by overwriting existing variables in the global environment. Instead, using PC$VariableName for accessing specific variables is a safer practice as it prevents such conflicts .
Using a GUI such as R Commander for PCA operations offers advantages like providing a user-friendly interface for beginners, automating many aspects of data analysis workflows, and reducing potential errors from manual scripting by providing point-and-click options for executing PCA procedures .
Common errors include using matrix objects in functions that require vectors, such as in hist(r) and qqnorm(r), where the corrected practice is to convert the matrix to a vector with as.vector(r). Additionally, the use of scree.plot() from the psy package has been updated to scree() or fa.parallel() from the psych package due to obsolescence. Furthermore, attach() can cause variable conflicts, so using PC$VariableName is recommended .
The suitability criteria for applying PCA include the Bartlett's Test of Sphericity and the Kaiser-Meyer-Olkin (KMO) Test. Bartlett's Test requires a p-value less than 0.05, indicating there are correlations among variables suitable for PCA. The KMO Test suggests a KMO index greater than 0.6 for adequate sampling adequacy .
The use of the regression method during PCA influences factor score estimation by providing a means for estimating scores based on the regression approach, which ensures that the scores are as predictive of the original variables as possible while remaining uncorrelated with each other, enhancing the reliability of the score interpretations .
Varimax rotation improves the interpretability of PCA results by producing orthogonal factors that make the structure of the data clearer and more distinct. This allows for easier interpretation of components as it simplifies the factor loadings, making latent variables more coherent and easier to label .
The 'psy' and 'psych' packages are crucial for implementing Bartlett's Test, the KMO Test, and PCA functions. The 'GPArotation' package facilitates rotated PCA solutions, such as Varimax rotation, which enhances the interpretability of the resulting factors .
The steps for preparing data before performing PCA include setting the working directory with setwd() and confirming it with getwd(), reading and attaching the dataset using read.csv() with header = TRUE for column names, and computing the correlation matrix for the data using cor().
The guide suggests saving the final dataset by appending PCA scores to the original dataset and writing it to a CSV file using cbind() to combine the original data with the PCA scores and write.csv() to save the data. This process ensures the augmented dataset, which includes both raw data and computed component scores, is preserved for further analysis or reporting .