<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/how-many-factors-to-retain-in-factor-analysis/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://neuropsychology.github.io/psycho.R//2018/05/24/n_factors.html"> Dominique Makowski</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/24/n_factors.html#the-method-agreement-procedure" target="_blank">The method agreement procedure</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/24/n_factors.html#tweaking" target="_blank">Tweaking</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/24/n_factors.html#credits" target="_blank">Credits</a></li>
</ul>
<h1>The method agreement procedure</h1>
<p>When running a factor analysis, one often needs to know how many components / latent variables to retain. Fortunately, many methods exist to statistically answer this question. Unfortunately, there is no consensus on which method to use. Therefore, the <code>n_factors()</code> function, available in the <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R" target="_blank">psycho</a> package, performs the <strong>method agreement procedure</strong>: it runs all the routines and returns the number of factors with the highest consensus.</p>
<div>
<div>
<pre><code><span># devtools::install_github(&quot;neuropsychology/psycho.R&quot;) # Install the last psycho version if needed</span><span>
</span><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>psycho</span><span>)</span><span>
</span><span>results</span><span> </span><span>&lt;-</span><span> </span><span>attitude</span><span> </span><span>%>%</span><span>
</span><span>psycho</span><span>::</span><span>n_factors</span><span>()</span><span>
</span><span>print</span><span>(</span><span>results</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## The choice of 1 factor is supported by 5 (out of 9; 55.56%) methods (Optimal Coordinates, Acceleration Factor, Parallel Analysis, Velicer MAP, VSS Complexity 1).
</code></pre>
</div>
</div>
<p>We can have an overview of all values by using the <code>summary</code> method.</p>
<table>
<thead>
<tr>
<th>n.Factors</th>
<th>n.Methods</th>
<th>Eigenvalues</th>
<th>Cum.Variance</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>5</td>
<td>3.72</td>
<td>0.53</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>1.14</td>
<td>0.69</td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>0.85</td>
<td>0.81</td>
</tr>
<tr>
<td>4</td>
<td>0</td>
<td>0.61</td>
<td>0.90</td>
</tr>
<tr>
<td>5</td>
<td>0</td>
<td>0.32</td>
<td>0.95</td>
</tr>
<tr>
<td>6</td>
<td>0</td>
<td>0.22</td>
<td>0.98</td>
</tr>
<tr>
<td>7</td>
<td>0</td>
<td>0.14</td>
<td>1.00</td>
</tr>
</tbody>
</table>
<p>And, of course, plot it <img alt="🙂" src="https://s.w.org/images/core/emoji/2.4/72x72/1f642.png" class="wp-smiley"></p>
<div>
<div>
<pre><code><span>plot</span><span>(</span><span>results</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p><img alt="" src="https://i2.wp.com/raw.githubusercontent.com/neuropsychology/psycho.R/master/docs/_posts/2018-05-24-n_factors_files/figure-markdown_github/unnamed-chunk-4-1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>The plot shows the <strong>number of methods</strong> (in yellow), the <strong>Eigenvalues</strong> (red line) and the cumulative proportion of <strong>explained variance</strong> (blue line).</p>
<p>For more details, we can also extract the final result (the optimal number of factors) for each method:</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>n_optimal</th>
</tr>
</thead>
<tbody>
<tr>
<td>Optimal Coordinates</td>
<td>1</td>
</tr>
<tr>
<td>Acceleration Factor</td>
<td>1</td>
</tr>
<tr>
<td>Parallel Analysis</td>
<td>1</td>
</tr>
<tr>
<td>Eigenvalues (Kaiser Criterion)</td>
<td>2</td>
</tr>
<tr>
<td>Velicer MAP</td>
<td>1</td>
</tr>
<tr>
<td>BIC</td>
<td>2</td>
</tr>
<tr>
<td>Sample Size Adjusted BIC</td>
<td>3</td>
</tr>
<tr>
<td>VSS Complexity 1</td>
<td>1</td>
</tr>
<tr>
<td>VSS Complexity 2</td>
<td>2</td>
</tr>
</tbody>
</table>
<h1>Tweaking</h1>
<p>We can also provide a correlation matrix, as well as changing the rotation and the factoring method.</p>
<div>
<div>
<pre><code><span>df</span><span> </span><span>&lt;-</span><span> </span><span>psycho</span><span>::</span><span>affective</span><span>
</span><span>cor_mat</span><span> </span><span>&lt;-</span><span> </span><span>psycho</span><span>::</span><span>correlation</span><span>(</span><span>df</span><span>)</span><span>
</span><span>cor_mat</span><span> </span><span>&lt;-</span><span> </span><span>cor_mat</span><span>$</span><span>values</span><span>$</span><span>r</span><span>
</span><span>results</span><span> </span><span>&lt;-</span><span> </span><span>cor_mat</span><span> </span><span>%>%</span><span>
</span><span>psycho</span><span>::</span><span>n_factors</span><span>(</span><span>rotate</span><span> </span><span>=</span><span> </span><span>&quot;oblimin&quot;</span><span>,</span><span> </span><span>fm</span><span> </span><span>=</span><span> </span><span>&quot;mle&quot;</span><span>,</span><span> </span><span>n</span><span>=</span><span>nrow</span><span>(</span><span>df</span><span>))</span><span>
</span><span>print</span><span>(</span><span>results</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## The choice of 2 factors is supported by 5 (out of 9; 55.56%) methods (Parallel Analysis, Eigenvalues (Kaiser Criterion), BIC, Sample Size Adjusted BIC, VSS Complexity 2).
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>plot</span><span>(</span><span>results</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p><img alt="" src="https://i2.wp.com/raw.githubusercontent.com/neuropsychology/psycho.R/master/docs/_posts/2018-05-24-n_factors_files/figure-markdown_github/unnamed-chunk-7-1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h1>Credits</h1>
<p>This package helped you? Don’t forget to cite the various packages you used <img alt="🙂" src="https://s.w.org/images/core/emoji/2.4/72x72/1f642.png" class="wp-smiley"></p>
<p>You can cite <code>psycho</code> as follows:</p>
<ul>
<li>Makowski, (2018). <em>The psycho Package: an Efficient and Publishing-Oriented Workflow for Psychological Science</em>. Journal of Open Source Software, 3(22), 470. <a rel="nofollow" href="https://doi.org/10.21105/joss.00470" target="_blank">https://doi.org/10.21105/joss.00470</a></li>
</ul>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://neuropsychology.github.io/psycho.R//2018/05/24/n_factors.html"> Dominique Makowski</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/GGulSHSXsG4" height="1"></a></div>