<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/"></div></div><div><a data-url="http://www.r-bloggers.com/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/" data-counturl="http://www.r-bloggers.com/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/" data-count="horizontal" data-text="Why you should read Nina Zumel’s 3 part series on principal components analysis and regression" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2016/06/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<h1>Short form:</h1>
<p>Win-Vector LLC’s Dr. Nina Zumel has a three part series on Principal Components Regression that we think is well worth your time.</p>
<ul>
<li><a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part1_xonly/">Part 1</a>: the proper preparation of data (including scaling) and use of principal components analysis (particularly for supervised learning or regression).</li>
<li><a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part2_yaware/">Part 2</a>: the introduction of <em>y</em>-aware scaling to direct the principal components analysis to preserve variation correlated with the outcome we are trying to predict.</li>
<li><a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part3_pickk/">Part 3</a>: how to pick the number of components to retain for analysis.</li>
</ul>
<p><span></span></p>
<hr>
<h1>Long form:</h1>
<hr>
<h1>Part 1 Principal Components Regression/Analysis: The Standard Methods</h1>
<p>You can read her first article <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part1_xonly">part 1 here</a>. Principal Components Regression (PCR) is the use of Principal Components Analysis (PCA) as a dimension reduction step prior to linear regression. It is one of the best known dimensionality reduction techniques and a staple procedure in many scientific fields. PCA is used because:</p>
<ul>
<li>It can find important latent structure and relations.</li>
<li>It can reduce over fit.</li>
<li>It can ease the curse of dimensionality.</li>
<li>It is used in a ritualistic manner in many scientific disciplines. In some fields it is considered ignorant and uncouth to regress using original variables.</li>
</ul>
<p>We often find ourselves having to often remind readers that this last reason is not actually positive. The standard derivation of PCA involves trotting out the math and showing the determination of eigenvector directions. It yields visually attractive diagrams such as the following.</p>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Principal_component_analysis#/media/File:GaussianScatterPCA.svg"><img title="GaussianScatterPCA.svg.png" alt="GaussianScatterPCA svg" src="http://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/05/GaussianScatterPCA.svg_.png?w=500" data-recalc-dims="1"></a></p>
<p>Wikipedia: PCA</p>
<p>And this leads to a deficiency in much of the teaching of the method: glossing over the operational consequences and outcomes of applying the method. The mathematics is important to the extent it allows you to reason about the appropriateness of the method, the consequences of the transform, and the pitfalls of the technique. The mathematics is also critical to the correct implementation, but that is what one hopes is <em>already</em> supplied in a reliable analysis platform (such as <a target="_blank" href="https://cran.r-project.org/">R</a>). Dr. Zumel uses the expressive and graphical power of R to work through the <em>use</em> of Principal Components Regression in an operational series of examples. She works through how Principal Components Regression is typically mis-applied and continues on to how to correctly apply it. Taking the extra time to work through the all too common errors allows her to demonstrate and quantify the benefits of correct technique. Dr. Zumel will soon follow <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part1_xonly">part 1</a> later with a shorter part 2 article demonstrating important &quot;<em>y</em>-aware&quot; techniques that squeeze much more modeling power out of your data in predictive analytic situations (which is what regression actually is). Some of the methods are already in the literature, but are still not used widely enough. We hope the demonstrated techniques and included references will give you a perspective to improve how you use or even teach Principal Components Regression. Please read on <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part1_xonly">here</a>.</p>
<hr>
<h1>Part 2: <em>Y</em>-Aware Methods</h1>
<p>In <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part2_yaware">part 2</a> of her series on Principal Components Regression Dr. Nina Zumel illustrates so-called <em>y</em>-aware techniques. These often neglected methods use the fact that for predictive modeling problems we know the dependent variable, outcome or <em>y</em>, so we can use this during data preparation <em>in addition to</em> using it during modeling. Dr. Zumel shows the incorporation of <em>y</em>-aware preparation into Principal Components Analyses can capture more of the problem structure in fewer variables. Such methods include:</p>
<ul>
<li>Effects based variable pruning</li>
<li>Significance based variable pruning</li>
<li>Effects based variable scaling.</li>
</ul>
<p>This recovers more domain structure and leads to better models. Using the foundation set in the first article Dr. Zumel quickly shows how to move from a traditional <em>x</em>-only analysis that fails to preserve a domain-specific relation of two variables to outcome to a <em>y</em>-aware analysis that preserves the relation. Or in other words how to move away from a middling result where different values of y (rendered as three colors) are hopelessly intermingled when plotted against the first two found latent variables as shown below.</p>
<div>
<img title="NewImage.png" alt="NewImage" src="http://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/05/NewImage-1.png?w=500" data-recalc-dims="1">
</div>
<p>Dr. Zumel shows how to perform a decisive analysis where <em>y</em> is somewhat sortable by the each of the first two latent variable <em>and</em> the first two latent variables capture complementary effects, making them good mutual candidates for further modeling (as shown below).</p>
<div>
<img title="NewImage.png" alt="NewImage" src="http://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/05/NewImage.png?w=500" data-recalc-dims="1">
</div>
<p>Click <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part2_yaware">here (part 2 <em>y</em>-aware methods)</a> for the discussion, examples, and references. Part 1 (<em>x</em> only methods) can be found <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part1_xonly">here</a>.</p>
<hr>
<h1>Part 3: picking <em>k</em> and wrapping up</h1>
<p>In her series on principal components analysis for regression in <a target="_blank" href="https://cran.r-project.org/">R</a> <a target="_blank" href="http://www.win-vector.com/">Win-Vector LLC</a>‘s <a target="_blank" href="http://www.win-vector.com/site/staff/nina-zumel/">Dr. Nina Zumel</a> broke the demonstration down into the following pieces:</p>
<ul>
<li><a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part1_xonly/">Part 1</a>: the proper preparation of data and use of principal components analysis (particularly for supervised learning or regression).</li>
<li><a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part2_yaware/">Part 2</a>: the introduction of <em>y</em>-aware scaling to direct the principal components analysis to preserve variation correlated with the outcome we are trying to predict.</li>
<li>And now <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part3_pickk/">Part 3</a>: how to pick the number of components to retain for analysis.</li>
</ul>
<p>In the earlier parts Dr. Zumel demonstrates common poor practice versus best practice and quantifies the degree of available improvement. In part 3 she moves from the usual &quot;pick the number of components by eyeballing it&quot; non-advice and teaches decisive decision procedures. For picking the number of components to retain for analysis there are a number of standard techniques in the literature including:</p>
<ul>
<li>Pick 2, as that is all you can legibly graph.</li>
<li>Pick enough to cover some fixed fraction of the variation (say 95%).</li>
<li>(for variance scaled data only) Retain components with singular values at least 1.0.</li>
<li>Look for a &quot;knee in the curve&quot; (the curve being the plot of the singular value magnitudes).</li>
<li>Perform a statistical test to see which singular values are larger than we would expect from an appropriate null hypothesis or noise process.</li>
</ul>
<p>Dr. Zumel shows that the last method (designing a formal statistical test) is particularly easy to encode as a permutation test in the <em>y</em>-aware setting (there is also an obvious similarly good bootstrap test). This is well-founded and pretty much state of the art. It is also a great example of why to use a scriptable analysis platform (such as R) as it is easy to wrap arbitrarily complex methods into functions and then directly perform empirical tests on these methods. The following &quot;broken stick&quot; type test yields the following graph which identifies five principal components as being significant:</p>
<div>
<img title="replot-1.png" alt="Replot 1" src="http://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/05/replot-1.png?w=500" data-recalc-dims="1">
</div>
<p>However, Dr. Zumel goes on to show that in a supervised learning or regression setting we can further exploit the structure of the problem and replace the traditional component magnitude tests with simple model fit significance pruning. The significance method in this case gets the stronger result of finding the two principal components that encode the known even and odd loadings of the example problem:</p>
<div>
<img title="plotsig-1.png" alt="Plotsig 1" src="http://i1.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/05/plotsig-1.png?w=500" data-recalc-dims="1">
</div>
<p>In fact that is sort of her point: significance pruning either on the original variables or on the derived latent components is enough to give us the right answer. In general we get much better results when (in a supervised learning or regression situation) we use knowledge of the dependent variable (the &quot;<em>y</em>&quot; or outcome) and do <em>all</em> of the following:</p>
<ul>
<li>Model fit significance prune incoming variables.</li>
<li>Convert incoming variables into consistent response units by <em>y</em>-aware scaling.</li>
<li>Model fit significance prune resulting latent components.</li>
</ul>
<p>The above will become much clearer and much more specific if you <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part3_pickk/">click here to read part 3</a>.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/"></div></div><div><a data-url="http://www.r-bloggers.com/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/" data-counturl="http://www.r-bloggers.com/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/" data-count="vertical" data-text="Why you should read Nina Zumel’s 3 part series on principal components analysis and regression" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.win-vector.com/blog/2016/06/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/"> R – Win-Vector Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/O8x3RC-n9Is"></a></div>