

{"id":4931,"date":"2018-01-12T10:53:30","date_gmt":"2018-01-12T05:23:30","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=4931"},"modified":"2024-05-16T22:22:42","modified_gmt":"2024-05-16T16:52:42","slug":"principal-components-and-factor-analysis-in-r","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/","title":{"rendered":"Principal Components and Factor Analysis in R &#8211; Functions &amp; Methods"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2049,&quot;href&quot;:&quot;https:\\\/\\\/www.r-project.org\\\/bugs.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250923123728\\\/https:\\\/\\\/www.r-project.org\\\/bugs.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 00:01:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-14 20:26:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-18 08:56:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-21 16:15:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-25 07:23:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-29 22:14:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-02 01:41:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-05 11:01:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-09 12:38:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 13:53:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 15:23:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-19 02:36:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-22 10:50:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-26 13:56:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-29 15:22:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-03 07:22:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-06 07:25:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 12:49:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 21:28:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-16 00:10:35&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 03:50:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-22 17:40:40&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-26 08:21:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-01 12:21:52&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-04 14:00:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 15:46:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-11 13:16:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 17:29:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-19 02:02:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 08:29:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-25 13:57:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 16:05:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 23:28:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-04 10:15:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-07 20:22:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 21:43:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 04:20:43&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-17 05:57:17&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-21 01:56:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-26 00:30:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-29 05:36:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-02 15:57:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-06 10:14:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-09 15:07:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-13 07:26:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-16 07:34:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-19 14:33:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-22 20:54:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-26 03:30:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-29 06:56:00&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-02 15:32:45&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-06 15:33:52&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-09 22:43:08&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-09 22:43:08&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>With this tutorial, learn about the concept of principal components, reasons to use it and different functions and methods of principal component analysis in R programming. Also, understand the complete technique of factor analysis in R.<\/p>\n<h2>Introduction to Principal Components and Factor Analysis in R<\/h2>\n<div class=\"\">\n<div class=\"public-DraftStyleDefault-block public-DraftStyleDefault-ltr\">We use R principal component and factor analysis as the multivariate analysis method. The aim of this is to reveal systematic covariations among a group of variables. Also, the analysis can <span class=\"passivevoice\">be motivated<\/span> in many different ways. It includes describing the basic anomaly patterns that appear in spatial data sets.<\/div>\n<\/div>\n<p><span style=\"font-weight: 400\">Thus, it is always performed on a symmetric correlation or covariance matrix. Hence, it means the matrix should be numeric.<\/span><\/p>\n<p>Principal Component Analysis has wide applications in various fields and particularly in aspects like exploratory data analysis (EDA) and dimensionality reduction. Both these operations are one of the most important steps in any Data Science or Machine Learning projects.<\/p>\n<p>A practical use case of PCA is in the field of image processing where it is used in order to reduce the dimensionality of the image dataset without losing important information in the data. By transforming high dimensional data into low dimensional data, PCA helps in reducing the computational complexity and overfitting without losing significant information.<\/p>\n<p>Overall, the versatility and wide range applications of PCA make it a valuable and very important tool for gaining insights from the data as well as to reduce the complexity of high dimensional datasets.<\/p>\n<p><em><strong>Wait! Before proceeding ahead, make sure to complete the <a href=\"https:\/\/data-flair.training\/blogs\/r-matrix-functions\/\">R Matrix Function Tutorial<\/a><\/strong><\/em><\/p>\n<h3>What are Principal Components in R?<\/h3>\n<p><span style=\"font-weight: 400\">It is a normalized linear combination of the original predictors in a data set. We can write the principal component in the following way:<\/span><\/p>\n<p style=\"text-align: center\"><em><strong>Z\u00b9 = \u03a6\u00b9\u00b9X\u00b9 + \u03a6\u00b2\u00b9X\u00b2 + \u03a6\u00b3\u00b9X\u00b3 + &#8230;. +\u03a6p\u00b9Xp<\/strong><\/em><\/p>\n<p><span style=\"font-weight: 400\">where,<\/span><\/p>\n<p><span style=\"font-weight: 400\"><em>Z\u00b9<\/em> is the first principal component.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><em>\u03a6p\u00b9<\/em> is the loading vector comprising of loadings (\u03a6\u00b9, \u03a6\u00b2..) of a first principal component. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, the loadings are constrained\u00a0<\/span><span style=\"font-weight: 400\">to a sum of square equal to 1. This is because the large size of loadings may lead to large variance. The direction of the principal component (Z\u00b9) which has the highest variation of data is also defined. Moreover, it results in a line in p dimensional space which is closest to the n observations. We can measure closeness using average squared Euclidean distance.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><em>X\u00b9..Xp<\/em> is normalized predictors. The means of normalized predictors are equal to 0 and have a standard deviation of 1.<\/span><\/p>\n<h3>Why use Principal Components Analysis?<\/h3>\n<p><span style=\"font-weight: 400\">The main aim of principal components analysis in R is to report hidden structure in a data set. In doing so, we may be able to do the following things:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">Basically, it is prior to identifying how different variables work together to create the dynamics of the system.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Reduce the dimensionality of the data.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Decreases redundancy in the data.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Filter some of the noise in the data.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Compress the data.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Prepare the data for further analysis using other techniques.<\/span><\/li>\n<\/ul>\n<h3>Functions to Perform Principal Analysis in R<\/h3>\n<ol>\n<li><span style=\"font-weight: 400\">prcomp() (stats)<\/span><\/li>\n<li><span style=\"font-weight: 400\">princomp() (stats)<\/span><\/li>\n<li><span style=\"font-weight: 400\">PCA() (FactoMineR)<\/span><\/li>\n<li><span style=\"font-weight: 400\">dudi.pca() (ade4)<\/span><\/li>\n<li><span style=\"font-weight: 400\">acp() (amap)<\/span><\/li>\n<\/ol>\n<h3>Implementing Principal Components Analysis in R<\/h3>\n<p>We will now proceed towards implementing our own\u00a0Principal Components Analysis (PCA) in R. For carrying out this operation, we will utilise the<em> pca()<\/em> function that is provided to us by the <strong>FactoMineR library<\/strong>. We will make use of the <em>mtcars<\/em> dataset which is provided to us by R. In this dataset, there are total 11 features out of which we require 9 features as two of them are categorical in nature. We will then have a look at our PCA objects with the help of <em>summary()<\/em> function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; library(FactoMineR)   #Author DataFlair\r\n&gt; pca &lt;- PCA(mtcars[,c(1:7,10,11)], scale. = TRUE)\r\n&gt; summary(pca)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65154 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1.png\" alt=\"LibraryFactoMinoR- Principal Components and Factor Analysis in R\" width=\"1301\" height=\"738\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1.png 1301w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1-150x85.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1-300x170.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1-768x436.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1-1024x581.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/PCA-1-520x295.png 520w\" sizes=\"auto, (max-width: 1301px) 100vw, 1301px\" \/><\/a><\/p>\n<p>In order to display the matrix with its constituent eigenvalues, we will write the following code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; pca$eig #Author DataFlair<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65155 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig.png\" alt=\"pca$eig - Principal Components and Factor Analysis in R\" width=\"1300\" height=\"739\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig.png 1300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig-150x85.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig-768x437.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig-1024x582.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcaeigeig-520x296.png 520w\" sizes=\"auto, (max-width: 1300px) 100vw, 1300px\" \/><\/a><\/p>\n<p>Furthermore, for finding correlations between variables and their correlations, we write the following line of code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; pca$var$coord #DataFlair<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65156 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord.png\" alt=\"pca$var$coord - Principal Components and Factor Analysis in R\" width=\"1301\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord.png 1301w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord-150x85.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord-768x437.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord-1024x583.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/pcavarcoord-520x296.png 520w\" sizes=\"auto, (max-width: 1301px) 100vw, 1301px\" \/><\/a><\/p>\n<p>While the default graph provided to us by the PCA() function is good, we can choose to create a better visualisation of our data using the ggbiplot library. You can install this package as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; library(devtools)\r\n&gt; install_github(\"vqv\/ggbiplot\")<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65157 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools.png\" alt=\"library-devtools - Principal Components and Factor Analysis in R\" width=\"1297\" height=\"739\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools.png 1297w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools-150x85.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools-1024x583.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-devtools-520x296.png 520w\" sizes=\"auto, (max-width: 1297px) 100vw, 1297px\" \/><\/a><\/p>\n<p>Finally, we import this package and plot our PCA graph:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; library(ggbiplot)  #AuthorDataFlair\r\n&gt; ggbiplot(pca)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65158 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot.png\" alt=\"library(ggbiplot) - Principal Components and Factor Analysis in R\" width=\"1301\" height=\"738\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot.png 1301w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot-150x85.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot-300x170.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot-768x436.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot-1024x581.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/libraryggbiplot-520x295.png 520w\" sizes=\"auto, (max-width: 1301px) 100vw, 1301px\" \/><\/a><\/p>\n<p><em><strong>Grab a complete <a href=\"https:\/\/data-flair.training\/blogs\/r-recursive-function\/\">tutorial on R Recursive Function<\/a><\/strong><\/em><\/p>\n<h3>Methods for Principal Component Analysis in R<\/h3>\n<p>There are two methods<span style=\"font-weight: 400\">\u00a0for R principal component analysis:<\/span><\/p>\n<h4>1. Spectral Decomposition<\/h4>\n<p><span style=\"font-weight: 400\">It examines the covariances\/correlations between variables.<\/span><\/p>\n<h4>2. Singular Value Decomposition<\/h4>\n<p><span style=\"font-weight: 400\">It examines the covariances\/correlations between individuals. Function <em>princomp()<\/em> is used here for carrying out a spectral approach.\u00a0<\/span><span style=\"font-weight: 400\">\u00a0And, we can also use the functions <em>prcomp()<\/em> and <em>PCA()<\/em> in the singular value decomposition.<\/span><\/p>\n<h3>prcomp() and princomp() functions<\/h3>\n<p><span style=\"font-weight: 400\">The simplified format of these two functions are :<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">prcomp(x, scale = FALSE)<\/span><\/li>\n<li><span style=\"font-weight: 400\">princomp(x, cor = FALSE, scores = TRUE)<\/span><\/li>\n<\/ul>\n<p><strong>Arguments for prcomp()<\/strong><br \/>\n<b><\/b><\/p>\n<ul>\n<li><b>x<\/b><span style=\"font-weight: 400\">: A numeric matrix or data frame.<\/span><br \/>\n<b><\/b><\/li>\n<li><b>scale<\/b><span style=\"font-weight: 400\">:\u00a0It is a logical value. It indicates whether the variables should <span class=\"passivevoice\">be scaled<\/span> to have unit variance and will take place before the analysis takes place.<\/span><\/li>\n<\/ul>\n<p><strong>Arguments for princomp()<\/strong><br \/>\n<b><\/b><\/p>\n<ul>\n<li><b>x<\/b><span style=\"font-weight: 400\">: A numeric matrix or data frame.<\/span><br \/>\n<b><\/b><\/li>\n<li><b>cor<\/b><span style=\"font-weight: 400\">: A logical value. If TRUE, then data will be centred and also scaled before the analysis.<\/span><br \/>\n<b><\/b><\/li>\n<li><b>scores<\/b><span style=\"font-weight: 400\">: A logical value. If TRUE, then coordinates on each principal component are calculated.<\/span><\/li>\n<\/ul>\n<h2>Factor Analysis in R<\/h2>\n<p><span style=\"font-weight: 400\"><em>Exploratory Factor Analysis or simply Factor Analysis is a technique used for the identification of the latent relational structure.<\/em> Using this technique, the variance of a large number can be explained with the help of fewer variables. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Let us understand factor analysis through the following example:<\/span><\/p>\n<p><span style=\"font-weight: 400\">Assume an instance of a demographics based survey. Suppose that there is a survey about the number of dropouts in academic institutions. It is observed that the number of dropouts is much greater at higher levels of institutions. That is, the number of high school dropouts is much higher than in junior school. Similarly, the number of dropouts in college is much higher than in high school.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> In this case, the driving factor behind the number of dropouts is the increase in academic difficulty. But besides this, there can be many other factors like<em> financial background, localities with higher pupil-teacher ratio and even gender in the most remote parts.<\/em> <\/span><\/p>\n<p><span style=\"font-weight: 400\">Since there are multiple factors that contribute towards the dropout rate, we have to define variables in a structured and a defined manner. The main principle of factor analysis is the categorization of weights based on the influence that the category has.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">With factor analysis, we are able to assess the variables that are hidden from plain observation but are reflected in the variables of the data. We perform the transformation on our dataset to an equal number of variables such that each variable is a combination of the current ones. This is performed without any removal or addition of new information. Therefore, the transformation of these variables in the direction of eigenvalues will help us to determine influential factors. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Eigenvalue having a value more than 1 will have greater variance than the original one. These factors are then arranged in a decreasing format based on their variances. Therefore, the first factor will have a higher variance than the second one and so on. <em>Weights that contribute towards the variance are known as \u2018factor loadings\u2019.<\/em><\/span><\/p>\n<p><span style=\"font-weight: 400\">Now, let us take a practical example of factor analysis in <a href=\"https:\/\/www.r-project.org\/bugs.html\">R<\/a>. We will use the BFI dataset that comprises of personality items. There are about 2800 data points with five main factors &#8211; <em>A (Agreeableness), C (<\/em><\/span><span style=\"font-weight: 400\"><em>Conscientiousness), E (Extraversion), N (Neuroticism), O (Openness)<\/em>. We will implement factor analysis to assess the association of the variables with each factor.\u00a0<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">library(psych)                #Author DataFlair\r\ndataset_bfi = bfi             #Loading the Dataset\r\ndataset_bfi = dataset_bfi[complete.cases(dataset_bfi),] #Removing the rows with Missing Values\r\ncor_mat &lt;- cor(dataset_bfi)   #Creating Correlation Matrix \r\nFactorLoading &lt;- fa(r = cor_mat, nfactors = 6)\r\nFactorLoading\r\n<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65117\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code.jpg\" alt=\"library psych code\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65119\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output.jpg\" alt=\"library psych code_output\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/library-psych-code_output-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">From the above output, we observe that the first factor N has the highest variance among all the variables. We infer that most members have neuroticism in our data.<\/span><\/p>\n<h2>Summary<\/h2>\n<p>We have studied the principal component and factor analysis in R. Along with this, we have also discussed its usage, functions, components.<\/p>\n<p><em><strong>Now, it&#8217;s time for learning the Major Functions to Organise the data with <a href=\"https:\/\/data-flair.training\/blogs\/r-data-reshaping-function-package\/\">R Data Reshaping Tutorial<\/a><\/strong><\/em><\/p>\n<p>Feel free to share your thoughts in the comment section below. Hope you enjoyed learning!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With this tutorial, learn about the concept of principal components, reasons to use it and different functions and methods of principal component analysis in R programming. Also, understand the complete technique of factor analysis&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":65121,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[9970,20691,20692],"class_list":["post-4931","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-principal-components-and-factor-analysis-in-r","tag-r-principal-analysis-functions","tag-r-principal-analysis-methods"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Principal Components and Factor Analysis in R - Functions &amp; Methods - DataFlair<\/title>\n<meta name=\"description\" content=\"Understand the complete concept of Principal Components and Factor Analysis in R programming. Also, explore reasons to learn Principal Components Analysis with its functions and methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Principal Components and Factor Analysis in R - Functions &amp; Methods - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Understand the complete concept of Principal Components and Factor Analysis in R programming. Also, explore reasons to learn Principal Components Analysis with its functions and methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-12T05:23:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-16T16:52:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Principal-Components-Factor-Analysis-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Principal Components and Factor Analysis in R - Functions &amp; Methods - DataFlair","description":"Understand the complete concept of Principal Components and Factor Analysis in R programming. Also, explore reasons to learn Principal Components Analysis with its functions and methods.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Principal Components and Factor Analysis in R - Functions &amp; Methods - DataFlair","og_description":"Understand the complete concept of Principal Components and Factor Analysis in R programming. Also, explore reasons to learn Principal Components Analysis with its functions and methods.","og_url":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-12T05:23:30+00:00","article_modified_time":"2024-05-16T16:52:42+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Principal-Components-Factor-Analysis-in-R.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Principal Components and Factor Analysis in R &#8211; Functions &amp; Methods","datePublished":"2018-01-12T05:23:30+00:00","dateModified":"2024-05-16T16:52:42+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/"},"wordCount":1335,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Principal-Components-Factor-Analysis-in-R.jpg","keywords":["Principal components and factor analysis in R","R Principal Analysis Functions","R Principal Analysis Methods"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/","url":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/","name":"Principal Components and Factor Analysis in R - Functions &amp; Methods - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Principal-Components-Factor-Analysis-in-R.jpg","datePublished":"2018-01-12T05:23:30+00:00","dateModified":"2024-05-16T16:52:42+00:00","description":"Understand the complete concept of Principal Components and Factor Analysis in R programming. Also, explore reasons to learn Principal Components Analysis with its functions and methods.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Principal-Components-Factor-Analysis-in-R.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Principal-Components-Factor-Analysis-in-R.jpg","width":802,"height":420,"caption":"Principal Components & Factor Analysis in R"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"Principal Components and Factor Analysis in R &#8211; Functions &amp; Methods"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=4931"}],"version-history":[{"count":14,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4931\/revisions"}],"predecessor-version":[{"id":142458,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4931\/revisions\/142458"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/65121"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=4931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=4931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=4931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}