CINXE.COM

Pca visualization in MATLAB

<!DOCTYPE html> <html> <head> <!-- This page was last built at 2024-11-27 15:11 --> <meta charset="utf-8" /> <link rel="canonical" href="https://plotly.com/matlab/pca-visualization/" /> <link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@1,500&display=swap" rel="stylesheet" /> <!-- Media query magic - http://stackoverflow.com/questions/19945658/my-iphone-thinks-its-980px-wide --> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script src="/all_static/javascripts/algolia/instantsearch.js"></script> <script src="/all_static/javascripts/algolia/polyfill.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script> const theme = localStorage.getItem('theme'); if (theme === "dark-mode") { var root = document.getElementsByTagName('html')[0]; // '0' to assign the first (and only `HTML` tag) root.setAttribute('class', 'dark-mode'); } </script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" crossorigin="anonymous"></script> <link href="https://esm.sh/@markprompt/css@0.18.0?css" rel="stylesheet" /> <link href="/all_static/css/markprompt.css" rel="stylesheet" /> <!-- code highlighting --> <!-- <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/highlight.min.js"></script> <script> hljs.initHighlightingOnLoad(); </script>--> <!-- Mathjax --> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script> <!-- Plotly.js --> <script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js"></script> <script type="text/javascript"> if (typeof require !== "undefined") { require.undef("plotly"); requirejs.config({ paths: { plotly: [ "https://cdn.plot.ly/plotly-2.35.2.min", ], }, }); require(["plotly"], function(Plotly) { window._Plotly = Plotly; }); } </script> <!-- //// Stylesheets --> <style> .mcode { border: 1px solid #cfcfcf; border-radius: 2px; background: #f7f7f7; padding: 10px; } </style> <!-- Fonts --> <link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic|Ubuntu+Mono:400,700|Asap" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" /> <!-- Main Stylesheets --> <link rel="stylesheet" type="text/css" href="/all_static/css/main.css?version=false" /> <link rel="stylesheet" type="text/css" href="/all_static/css/improve.css?version=2024-11-27-15-11"> <!-- LOCAL DEV STYLESHEET --> <!--<link rel="stylesheet" type="text/css" href="http://api.plotly.dev/all_static/css/main.css">--> <!-- Icon --> <link rel="shortcut icon" href="https://dash.plotly.com/assets/favicon.ico" /> <!-- Google Tags--> <!-- Google Tag Manager Tag --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-N6T2RXG');</script> <!-- META TAGS --> <!-- Capture language --> <!-- Create a title --> <!-- Count number of plots on the page --> <!-- SEO Tags - title, meta_description --> <title> Pca visualization in MATLAB </title> <meta name="description" content="Detailed examples of PCA Visualization including changing color, size, log axes, and more in MATLAB."> <!-- Bing tags --> <meta name="msvalidate.01" content="D319859A832F9F1D15A7646E2A42150A" /> <!-- Facebook tags --> <meta property="og:title" content= Pca visualization in MATLAB /> <meta property="og:type" content="website"/> <meta property="og:image" content="https://help.plot.ly/images/twitter-default.png"> <meta property="og:description" content="Detailed examples of PCA Visualization including changing color, size, log axes, and more in MATLAB."/> <meta property="og:url" /> <meta property="fb:admins" content="1123751525"/> <meta property="fb:admins" content="22418"/> <!-- twitter tags --> <meta name="twitter:card" content="photo" /> <meta name="twitter:title" content= Pca visualization in MATLAB /> <meta name="twitter:url" content="https://plotly.com/matlab/pca-visualization/"/> <meta name="twitter:description" content="Detailed examples of PCA Visualization including changing color, size, log axes, and more in MATLAB."/> <meta name="twitter:image" content="https://help.plot.ly/images/twitter-default.png"> <meta name="twitter:site" content="@plotlygraphs"/> </head> <body data-spy="scroll" data-target=".watch" style="position:relative;" class="darkmode"> <!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N6T2RXG" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) --> <!--[if lt IE 10]> <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> <div class="menu-mobile"> <div class="switch-mode"> <div class="icon-dark"></div> <div class="switch"></div> <div class="icon-light"></div> </div> <div class="close-menu"></div> <ul> <li><a style="font-weight: bold;" href="https://community.plotly.com/c/plotly-r-matlab-julia-net/29">Forum</a> </li> <li><a style="font-weight: bold;" href="https://plotly.com/get-pricing/">Pricing</a></li> <li><a style="font-weight: bold;" href="https://dash.plotly.com">Dash</a></li> <!--<li><a style="font-weight: bold;" href="http://plotly.cloud">Dash Cloud</a></li>--> </ul> </div> <div class="header-container"> <header class="header-main --default"> <div class="--wrap"> <div class="--wrap-left"> <div class="-identity"> <a href="https://plotly.com/"><img src="/all_static/images/graphing_library_dark.svg" style="height: 30px;" class="logo-dark"></a> <a href="/graphing-libraries/"><img src="/all_static/images/graphing_library.svg" style="height: 30px;" class="logo-white"></a> </div> </div> <div class="--wrap-right"> <nav class="--nav-meta" role="navigation"> <ul> <li class="languages"> <a class="matlab"> <div class="icon"></div> MATLAB® </a> <ul> <li> <a href="https://plotly.com/python/" class="python"> <div class="icon"></div>Python (v5.24.1) </a> </li> <li> <a href="https://plotly.com/r/" class="r"> <div class="icon"></div>R </a> </li> <li> <a href="https://plotly.com/julia/" class="julia"> <div class="icon"></div>Julia </a> </li> <li> <a href="https://plotly.com/javascript/" class="plotly_js"> <div class="icon"></div>Javascript (v2.35.2) </a> </li> <li> <a href="https://plotly.com/ggplot2/" class="ggplot2"> <div class="icon"></div>ggplot2 </a> </li> <li> <a href="https://plotly.com/matlab/" class="matlab"> <div class="icon"></div>MATLAB </a> </li> <li> <a href="https://plotly.com/fsharp/" class="fsharp"> <div class="icon"></div>F# </a> </li> <li> <a href="https://dash.plotly.com/" class="dash"> <div class="icon"></div>Dash </a> </li> </ul> </li> <li><a style="font-weight: bold;" href="https://community.plotly.com/c/plotly-r-matlab-julia-net/29">Forum</a> </li> <li><a style="font-weight: bold;" href="https://plotly.com/get-pricing/">Pricing</a></li> <li><a style="font-weight: bold;" href="https://dash.plotly.com">Dash</a></li> <!--<li><a style="font-weight: bold;" href="http://plotly.cloud">Dash Cloud</a></li>--> <iframe src="https://ghbtns.com/github-btn.html?user=plotly&repo=plotly_matlab&type=star&count=true&size=large" style="padding-top: 5px;" frameborder="0" scrolling="0" width="160px" height="40px"></iframe> </ul> <div class="switch-mode"> <div class="icon-dark"></div> <div class="switch"></div> <div class="icon-light"></div> </div> </nav> </div> <div class="menu-icon"> <span></span><span></span><span></span> </div> </div> </header> </div> <main class="--page page--single --index"> <div class="--wrap"> <!-- aside - Main Sidebar--> <!-- START OF GGPLOT CUSTOM LAYOUT --> <aside class="--sidebar-container"> <div class="--sidebar-fixed reference" data-spy="affix" id="where"> <div class="brand"> <a href="/graphing-libraries/"><img src="/all_static/images/graphing_library.svg" style="height: 30px;"></a> </div> <details style="color: white;margin-top: 20px;" > <summary>Quick Reference</summary> <nav class="--sidebar-body watch" id="where"> <ul class="--sidebar-list" style="margin-left: 15px;"> <!-- Getting Started --> <li class="--sidebar-item"> <a href="/matlab/getting-started" class="js-splash--navigation-item">Getting Started</a> </li> <li class="--sidebar-item"> <a href="/matlab/is-plotly-free" class="js-splash--navigation-item">Is Plotly Free?</a> </li> <!-- Reference Pages --> <li class="--sidebar-item"> <a href="/matlab/reference/index/" class="js-splash--navigation-item">Figure Reference</a> </li> <!-- Python Specific --> <!-- JS Specific --> <!-- R Specific --> <!-- Python/v3 Index Page Specific --> <!-- User Guides --> <li class="--sidebar-item"> <a href="/matlab/user-guide/" class="js-splash--navigation-item">User Guide</a> </li> <!-- Github Links --> <li class="--sidebar-item"> <a target="_blank" href="https://github.com/plotly/plotly-graphing-library-for-matlab" class="js-splash--navigation-item">GitHub</a> </li> <li class="--sidebar-item"> <a target="_blank" href="http://community.plotly.com/" class="js-splash--navigation-item">community.plotly.com</a> </li> </ul> </nav> </details> <details style="color: white;margin-top: 20px;" open> <summary>On This Page</summary> <nav class="--sidebar-body watch" id="where"> <ul class="--sidebar-list" id="nav_header_insertion_list"></ul> </nav> </details> </div> <a href="https://go.plotly.com/dash-club?utm_source=Dash+Club+2022&utm_medium=graphing_libraries&utm_content=sidebar" target="_blank"> <img src="https://images.prismic.io/plotly-marketing-website-2/7953022d-73b1-481e-8f6b-9ce9bd80e588_Dash+Club.jpeg?auto=compress,format" style="width: 200px; height: 200px; position: fixed; bottom: 10px; left: 50px" alt="Sign up to Dash Club to get two free cheat sheets as well as tips and tricks, community apps, and deep dives delivered every two month"> </a> </aside> <!-- Main--> <section class="--page-body --tutorial-index --base"> <header class="--welcome"> <div class="--welcome-body"> <!--div.--wrap-inner--> <div class="--title"> <div class="--body"> <div class="nav-breadcrumb-container"> <div> <div class="breadcrumb-nav"> <a href="/matlab"> MATLAB<sup>&reg;</sup> </a> &gt; <a href="/matlab/#ai-ml">Artificial Intelligence and Machine Learning</a> &gt; <span>PCA Visualization</span> </div> </div> <div class="nav-breadcrumb-right"> <div class="--fork"> <a id="forklink" href= "https://github.com/plotly/graphing-library-docs/edit/master/_posts/matlab/md/2021-08-04-pca-visualization.md" > <div class="icon"> <svg style="width:20px;height:20px" viewbox="0 0 24 24"> <path fill="#000000" d="M2.6,10.59L8.38,4.8L10.07,6.5C9.83,7.35 10.22,8.28 11,8.73V14.27C10.4,14.61 10,15.26 10,16A2,2 0 0,0 12,18A2,2 0 0,0 14,16C14,15.26 13.6,14.61 13,14.27V9.41L15.07,11.5C15,11.65 15,11.82 15,12A2,2 0 0,0 17,14A2,2 0 0,0 19,12A2,2 0 0,0 17,10C16.82,10 16.65,10 16.5,10.07L13.93,7.5C14.19,6.57 13.71,5.55 12.78,5.16C12.35,5 11.9,4.96 11.5,5.07L9.8,3.38L10.59,2.6C11.37,1.81 12.63,1.81 13.41,2.6L21.4,10.59C22.19,11.37 22.19,12.63 21.4,13.41L13.41,21.4C12.63,22.19 11.37,22.19 10.59,21.4L2.6,13.41C1.81,12.63 1.81,11.37 2.6,10.59Z"> </path> </svg> </div> <span>Suggest an edit to this page</span> </a> </div> </div> </div> <h1> PCA Visualization in MATLAB<sup>&reg;</sup> </h1> <p>How to do PCA Visualization in MATLAB<sup>&reg;</sup> with Plotly. </p> <br> <!-- <div class="db-client-lib"> <label> This page in another language </label> <div class="list-lib-wrap"> <div class="list-lib"> <a href=" /julia/pca-visualization/" class="list-lib-item julia"> <div class="item-icon"> </div> <p class="item-language"> Julia </p> </a> <a href=" /matlab/pca-visualization/" class="current list-lib-item matlab"> <div class="item-icon"> </div> <p class="item-language"> MATLAB® </p> </a> <a href=" /ggplot2/pca-visualization/" class="list-lib-item ggplot2"> <div class="item-icon"> </div> <p class="item-language"> ggplot2 </p> </a> <a href=" /r/pca-visualization/" class="list-lib-item r"> <div class="item-icon"> </div> <p class="item-language"> R </p> </a> <a href=" /python/pca-visualization/" class="list-lib-item python"> <div class="item-icon"> </div> <p class="item-language"> Python </p> </a> </div> </div> </div> --> </div> </div> </div> </header> <!-- Start Plotly Basics Section --> <section class="tutorial-content"> <h2>Principal Components of a Data Set</h2> <p>Load the sample data set. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> </code></pre></div> <p>The ingredients data has 13 observations for 4 variables. </p> <p>Find the principal components for the ingredients data. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="n">coeff</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">)</span> </code></pre></div> <pre class="code-output"> coeff = Columns 1 through 3 -0.067799985695474 -0.646018286568728 0.567314540990512 -0.678516235418647 -0.019993340484099 -0.543969276583817 0.029020832106229 0.755309622491133 0.403553469172668 0.730873909451461 -0.108480477171676 -0.468397518388289 Column 4 0.506179559977705 0.493268092159297 0.515567418476836 0.484416225289198 </pre> <p>The rows of <code>coeff</code> contain the coefficients for the four ingredient variables, and its columns correspond to four principal components. </p> <h2>PCA in the Presence of Missing Data</h2> <p>Find the principal component coefficients when there are missing values in a data set.</p> <p>Load the sample data set.</p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> </code></pre></div> <p>Data matrix <code>X</code> has 13 continuous variables in columns 3 to 15: wheel-base, length, width, height, curb-weight, engine-size, bore, stroke, compression-ratio, horsepower, peak-rpm, city-mpg, and highway-mpg. The variables bore and stroke are missing four values in rows 56 to 59, and the variables horsepower and peak-rpm are missing two values in rows 131 and 132.</p> <p>Perform principal component analysis.</p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> <span class="n">coeff</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">X</span><span class="p">(:,</span><span class="mi">3</span><span class="p">:</span><span class="mi">15</span><span class="p">));</span> </code></pre></div> <p>By default, <code>pca</code> performs the action specified by the <code>&#39;Rows&#39;,&#39;complete&#39;</code> name-value pair argument. This option removes the observations with <code>NaN</code> values before calculation. Rows of <code>NaN</code>s are reinserted into <code>score</code> and <code>tsquared</code> at the corresponding locations, namely rows 56 to 59, 131, and 132.</p> <p>Use <code>&#39;pairwise&#39;</code> to perform the principal component analysis.</p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> <span class="n">coeff</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">X</span><span class="p">(:,</span><span class="mi">3</span><span class="p">:</span><span class="mi">15</span><span class="p">),</span><span class="s1">'Rows'</span><span class="p">,</span><span class="s1">'pairwise'</span><span class="p">);</span> </code></pre></div> <p>In this case, <code>pca</code> computes the (i,j) element of the covariance matrix using the rows with no <code>NaN</code> values in the columns i or j of <code>X</code>. Note that the resulting covariance matrix might not be positive definite. This option applies when the algorithm <code>pca</code> uses is eigenvalue decomposition. When you don’t specify the algorithm, as in this example, <code>pca</code> sets it to <code>&#39;eig&#39;</code>. If you require <code>&#39;svd&#39;</code> as the algorithm, with the <code>&#39;pairwise&#39;</code> option, then <code>pca</code> returns a warning message, sets the algorithm to <code>&#39;eig&#39;</code> and continues. </p> <p>If you use the <code>&#39;Rows&#39;,&#39;all&#39;</code> name-value pair argument, <code>pca</code> terminates because this option assumes there are no missing values in the data set. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> <span class="n">coeff</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">X</span><span class="p">(:,</span><span class="mi">3</span><span class="p">:</span><span class="mi">15</span><span class="p">),</span><span class="s1">'Rows'</span><span class="p">,</span><span class="s1">'all'</span><span class="p">);</span> </code></pre></div> <pre class="code-output"> <font color="red">...ERROR...<br>Raw data contains NaN missing value while 'Rows' option is set to 'all'. Consider using 'complete' or 'pairwise' option, or using 'als' algorithm instead.</font> </pre> <h2>Weighted PCA</h2> <p>Use the inverse variable variances as weights while performing the principal components analysis. </p> <p>Load the sample data set. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> </code></pre></div> <p>Perform the principal component analysis using the inverse of variances of the ingredients as variable weights. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">wcoeff</span><span class="p">,</span><span class="o">~</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="o">~</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">,</span><span class="s1">'VariableWeights'</span><span class="p">,</span><span class="s1">'variance'</span><span class="p">);</span> </code></pre></div> <p>Note that the coefficient matrix, <code>wcoeff</code>, is not orthonormal. </p> <p>Calculate the orthonormal coefficient matrix. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">wcoeff</span><span class="p">,</span><span class="o">~</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="o">~</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">,</span><span class="s1">'VariableWeights'</span><span class="p">,</span><span class="s1">'variance'</span><span class="p">);</span> <span class="n">coefforth</span> <span class="o">=</span> <span class="nb">inv</span><span class="p">(</span><span class="nb">diag</span><span class="p">(</span><span class="nb">std</span><span class="p">(</span><span class="n">ingredients</span><span class="p">)))</span><span class="o">*</span> <span class="n">wcoeff</span> </code></pre></div> <pre class="code-output"> coefforth = Columns 1 through 3 -0.475955172748972 0.508979384806409 -0.675500187964285 -0.563870242191993 -0.413931487136986 0.314420442819292 0.394066533909305 -0.604969078471438 -0.637691091806566 0.547931191260862 0.451235109330017 0.195420962611708 Column 4 0.241052184051094 0.641756074427214 0.268466110294533 0.676734019481283 </pre> <p>Check orthonormality of the new coefficient matrix, <code>coefforth</code>. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">wcoeff</span><span class="p">,</span><span class="o">~</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="o">~</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">,</span><span class="s1">'VariableWeights'</span><span class="p">,</span><span class="s1">'variance'</span><span class="p">);</span> <span class="n">coefforth</span> <span class="o">=</span> <span class="nb">inv</span><span class="p">(</span><span class="nb">diag</span><span class="p">(</span><span class="nb">std</span><span class="p">(</span><span class="n">ingredients</span><span class="p">)))</span><span class="o">*</span> <span class="n">wcoeff</span><span class="p">;</span> <span class="n">coefforth</span><span class="o">*</span><span class="n">coefforth</span><span class="o">'</span> </code></pre></div> <pre class="code-output"> ans = Columns 1 through 3 1.000000000000000 0.000000000000000 -0.000000000000000 0.000000000000000 1.000000000000000 0.000000000000000 -0.000000000000000 0.000000000000000 1.000000000000000 -0.000000000000000 0.000000000000000 -0.000000000000000 Column 4 -0.000000000000000 0.000000000000000 -0.000000000000000 1.000000000000000 </pre> <h2>PCA Using ALS for Missing Data</h2> <p>Find the principal components using the alternating least squares (ALS) algorithm when there are missing values in the data. </p> <p>Load the sample data. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> </code></pre></div> <p>The ingredients data has 13 observations for 4 variables. </p> <p>Perform principal component analysis using the ALS algorithm and display the component coefficients. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">coeff</span> </code></pre></div> <pre class="code-output"> coeff = Columns 1 through 3 -0.067799985695474 -0.646018286568728 0.567314540990512 -0.678516235418647 -0.019993340484099 -0.543969276583817 0.029020832106229 0.755309622491133 0.403553469172668 0.730873909451461 -0.108480477171676 -0.468397518388289 Column 4 0.506179559977705 0.493268092159297 0.515567418476836 0.484416225289198 </pre> <p>Introduce missing values randomly. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span> </code></pre></div> <pre class="code-output"> y = 7 26 6 NaN 1 29 15 52 NaN NaN 8 20 11 31 NaN 47 7 52 6 33 NaN 55 NaN NaN NaN 71 NaN 6 1 31 NaN 44 2 NaN NaN 22 21 47 4 26 NaN 40 23 34 11 66 9 NaN 10 68 8 12 </pre> <p>Approximately 30% of the data has missing values now, indicated by <code>NaN</code>. </p> <p>Perform principal component analysis using the ALS algorithm and display the component coefficients. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff1</span><span class="p">,</span><span class="n">score1</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu1</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'algorithm'</span><span class="p">,</span><span class="s1">'als'</span><span class="p">);</span> <span class="n">coeff1</span> </code></pre></div> <pre class="code-output"> coeff1 = Columns 1 through 3 -0.036212338541055 0.821521833463707 -0.525180807034516 -0.683141604556494 -0.099847237932408 0.182836485390674 0.016929757180232 0.557510085824824 0.821489828858883 0.729191057256728 -0.065687977768361 0.126136436504135 Column 4 0.219033475985740 0.699942066753560 -0.118534166411284 0.669369173908958 </pre> <p>Display the estimated mean. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff1</span><span class="p">,</span><span class="n">score1</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu1</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'algorithm'</span><span class="p">,</span><span class="s1">'als'</span><span class="p">);</span> <span class="n">mu1</span> </code></pre></div> <pre class="code-output"> mu1 = Columns 1 through 3 8.995597151700496 47.908800869772193 9.045133815910839 Column 4 28.551458070546648 </pre> <p>Reconstruct the observed data. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff1</span><span class="p">,</span><span class="n">score1</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu1</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'algorithm'</span><span class="p">,</span><span class="s1">'als'</span><span class="p">);</span> <span class="n">t</span> <span class="o">=</span> <span class="n">score1</span><span class="o">*</span><span class="n">coeff1</span><span class="o">'</span> <span class="o">+</span> <span class="nb">repmat</span><span class="p">(</span><span class="n">mu1</span><span class="p">,</span><span class="mi">13</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> </code></pre></div> <pre class="code-output"> t = Columns 1 through 3 6.999999999999997 25.999999999999972 5.999999999999996 0.999999999999986 28.999999999999968 15.000000000000011 10.781877383662085 53.023021922864480 7.999999999999999 11.000000000000002 30.999999999999996 13.549987432049472 6.999999999999996 52.000000000000000 6.000000000000012 10.481832029571297 55.000000000000000 7.832799509066273 3.098161701207570 71.000000000000014 11.949103806476206 0.999999999999980 30.999999999999968 -0.516112356202619 1.999999999999988 53.791389384174103 5.770961215451544 21.000000000000014 47.000000000000000 3.999999999999998 21.580891857665534 39.999999999999986 23.000000000000014 10.999999999999996 66.000000000000014 9.000000000000002 9.999999999999998 68.000000000000000 8.000000000000009 Column 4 51.524967145094379 52.000000000000021 19.999999999999996 47.000000000000014 32.999999999999950 17.936171158236188 5.999999999999915 44.000000000000000 22.000000000000000 25.999999999999989 33.999999999999993 5.707816613776032 11.999999999999943 </pre> <p>The ALS algorithm estimates the missing values in the data. </p> <p>Another way to compare the results is to find the angle between the two spaces spanned by the coefficient vectors. Find the angle between the coefficients found for complete data and data with missing values using ALS. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff1</span><span class="p">,</span><span class="n">score1</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu1</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'algorithm'</span><span class="p">,</span><span class="s1">'als'</span><span class="p">);</span> <span class="n">t</span> <span class="o">=</span> <span class="n">score1</span><span class="o">*</span><span class="n">coeff1</span><span class="o">'</span> <span class="o">+</span> <span class="nb">repmat</span><span class="p">(</span><span class="n">mu1</span><span class="p">,</span><span class="mi">13</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span> <span class="nb">subspace</span><span class="p">(</span><span class="n">coeff</span><span class="p">,</span><span class="n">coeff1</span><span class="p">)</span> </code></pre></div> <pre class="code-output"> ans = 6.872983007538972e-16 </pre> <p>This is a small value. It indicates that the results if you use <code>pca</code> with <code>&#39;Rows&#39;,&#39;complete&#39;</code> name-value pair argument when there is no missing data and if you use <code>pca</code> with <code>&#39;algorithm&#39;,&#39;als&#39;</code> name-value pair argument when there is missing data are close to each other. </p> <p>Perform the principal component analysis using <code>&#39;Rows&#39;,&#39;complete&#39;</code> name-value pair argument and display the component coefficients. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff2</span><span class="p">,</span><span class="n">score2</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu2</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'Rows'</span><span class="p">,</span><span class="s1">'complete'</span><span class="p">);</span> <span class="n">coeff2</span> </code></pre></div> <pre class="code-output"> coeff2 = -0.205420225953307 0.858688026698708 0.049181247828161 -0.669364063599413 -0.371998098041251 0.551021387596589 0.147356319504436 -0.351257041216125 -0.518714827525170 0.698598880784301 -0.029845918549515 0.651837067815822 </pre> <p>In this case, <code>pca</code> removes the rows with missing values, and <code>y</code> has only four rows with no missing values. <code>pca</code> returns only three principal components. You cannot use the <code>&#39;Rows&#39;,&#39;pairwise&#39;</code> option because the covariance matrix is not positive semidefinite and <code>pca</code> returns an error message. </p> <p>Find the angle between the coefficients found for complete data and data with missing values using listwise deletion (when <code>&#39;Rows&#39;,&#39;complete&#39;</code>). </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff2</span><span class="p">,</span><span class="n">score2</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu2</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'Rows'</span><span class="p">,</span><span class="s1">'complete'</span><span class="p">);</span> <span class="nb">subspace</span><span class="p">(</span><span class="n">coeff</span><span class="p">(:,</span><span class="mi">1</span><span class="p">:</span><span class="mi">3</span><span class="p">),</span><span class="n">coeff2</span><span class="p">)</span> </code></pre></div> <pre class="code-output"> ans = 0.357607357590711 </pre> <p>The angle between the two spaces is substantially larger. This indicates that these two results are different. </p> <p>Display the estimated mean. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff2</span><span class="p">,</span><span class="n">score2</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu2</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'Rows'</span><span class="p">,</span><span class="s1">'complete'</span><span class="p">);</span> <span class="n">mu2</span> </code></pre></div> <pre class="code-output"> mu2 = Columns 1 through 3 7.888888888888889 46.909090909090907 9.875000000000000 Column 4 29.600000000000001 </pre> <p>In this case, the mean is just the sample mean of <code>y</code>. </p> <p>Reconstruct the observed data. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ingredients</span><span class="p">;</span> <span class="nb">rng</span><span class="p">(</span><span class="s1">'default'</span><span class="p">);</span> <span class="c1">% for reproducibility</span> <span class="n">ix</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="s1">'unif'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="nb">size</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">&lt;</span><span class="mf">0.30</span><span class="p">;</span> <span class="n">y</span><span class="p">(</span><span class="n">ix</span><span class="p">)</span> <span class="o">=</span> <span class="nb">NaN</span><span class="p">;</span> <span class="p">[</span><span class="n">coeff2</span><span class="p">,</span><span class="n">score2</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">,</span><span class="n">mu2</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="s1">'Rows'</span><span class="p">,</span><span class="s1">'complete'</span><span class="p">);</span> <span class="n">score2</span><span class="o">*</span><span class="n">coeff2</span><span class="o">'</span> </code></pre></div> <pre class="code-output"> ans = Columns 1 through 3 NaN NaN NaN -7.516185143683813 -18.354534728448066 4.096758018165185 NaN NaN NaN NaN NaN NaN -0.564429969715416 5.321307756733086 -3.343158339022808 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 12.831514933168062 -0.107632488812891 -6.333304231731043 NaN NaN NaN NaN NaN NaN 1.467986895710465 20.634225817831361 -2.929186618770285 Column 4 NaN 22.005631390194360 NaN NaN 3.603980833482452 NaN NaN NaN NaN -3.775776525301393 NaN NaN -18.004319332087810 </pre> <p>This shows that deleting rows containing <code>NaN</code> values does not work as well as the ALS algorithm. Using ALS is better when the data has too many missing values. </p> <h2>Principal Component Coefficients, Scores, and Variances</h2> <p>Find the coefficients, scores, and variances of the principal components. </p> <p>Load the sample data set. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> </code></pre></div> <p>The ingredients data has 13 observations for 4 variables. </p> <p>Find the principal component coefficients, scores, and variances of the components for the ingredients data. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> </code></pre></div> <p>Each column of <code>score</code> corresponds to one principal component. The vector, <code>latent</code>, stores the variances of the four principal components. </p> <p>Reconstruct the centered ingredients data. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">Xcentered</span> <span class="o">=</span> <span class="n">score</span><span class="o">*</span><span class="n">coeff</span><span class="o">'</span> </code></pre></div> <pre class="code-output"> Xcentered = Columns 1 through 3 -0.461538461538459 -22.153846153846157 -5.769230769230774 -6.461538461538464 -19.153846153846153 3.230769230769226 3.538461538461541 7.846153846153848 -3.769230769230770 3.538461538461538 -17.153846153846143 -3.769230769230777 -0.461538461538459 3.846153846153846 -5.769230769230769 3.538461538461541 6.846153846153848 -2.769230769230769 -4.461538461538460 22.846153846153818 5.230769230769237 -6.461538461538467 -17.153846153846153 10.230769230769228 -5.461538461538463 5.846153846153832 6.230769230769233 13.538461538461540 -1.153846153846135 -7.769230769230773 -6.461538461538466 -8.153846153846160 11.230769230769232 3.538461538461542 17.846153846153840 -2.769230769230766 2.538461538461542 19.846153846153840 -3.769230769230764 Column 4 30.000000000000021 22.000000000000021 -10.000000000000000 17.000000000000000 3.000000000000000 -8.000000000000005 -23.999999999999996 14.000000000000007 -7.999999999999992 -4.000000000000015 4.000000000000006 -18.000000000000007 -18.000000000000000 </pre> <p>The new data in <code>Xcentered</code> is the original ingredients data centered by subtracting the column means from corresponding columns. </p> <p>Visualize both the orthonormal principal component coefficients for each variable and the principal component scores for each observation in a single plot.</p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">Xcentered</span> <span class="o">=</span> <span class="n">score</span><span class="o">*</span><span class="n">coeff</span><span class="o">'</span><span class="p">;</span> <span class="n">biplot</span><span class="p">(</span><span class="n">coeff</span><span class="p">(:,</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">),</span><span class="s1">'scores'</span><span class="p">,</span><span class="n">score</span><span class="p">(:,</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">),</span><span class="s1">'varlabels'</span><span class="p">,{</span><span class="s1">'v_1'</span><span class="p">,</span><span class="s1">'v_2'</span><span class="p">,</span><span class="s1">'v_3'</span><span class="p">,</span><span class="s1">'v_4'</span><span class="p">});</span> <span class="n">fig2plotly</span><span class="p">(</span><span class="nb">gcf</span><span class="p">);</span> </code></pre></div> <div id="plot-9997773" class="plotly-graph-div js-plotly-plot"></div> <script type = "text/javascript" > require(["plotly"], function(Plotly) { window.PLOTLYENV = window.PLOTLYENV || {}; if (document.getElementById("plot-9997773" )) { Plotly.newPlot("plot-9997773", {"data": [{"type": "scatter", "xaxis": "x1", "yaxis": "y1", "visible": true, "name": "", "mode": "lines", "x": [0, -0.0677999856954741, null, 0, -0.678516235418647, null, 0, 0.029020832106229, null, 0, 0.730873909451461, null], "y": [0, -0.646018286568728, null, 0, -0.0199933404840993, null, 0, 0.755309622491133, null, 0, -0.108480477171676, null], "line": {"color": "rgb(0,113.985,188.955)", "width": 0.5, "dash": "solid"}, "marker": {"size": 3.6, "line": {"width": 0.5}, "color": "rgb(0,113.985,188.955)"}, "showlegend": false}, {"type": "scatter", "xaxis": "x1", "yaxis": "y1", "visible": true, "name": "", "mode": "markers", "x": [-0.0677999856954741, -0.678516235418647, 0.029020832106229, 0.730873909451461], "y": [-0.646018286568728, -0.0199933404840993, 0.755309622491133, -0.108480477171676], "line": {}, "marker": {"size": 3.6, "symbol": "circle", "maxdisplayed": 5, "line": {"width": 0.5}, "color": "rgb(0,113.985,188.955)"}, "showlegend": false}, {"type": "scatter", "xaxis": "x1", "yaxis": "y1", "visible": true, "name": "", "mode": "lines", "x": [-0.830840584740246, 0.830840584740246, null, 0, 0], "y": [0, 0, null, -0.830840584740246, 0.830840584740246], "line": {"color": "rgb(33,33,33)", "width": 0.5, "dash": "solid"}, "marker": {"size": 3.6, "line": {"width": 0.5}, "color": "rgb(33,33,33)"}, "showlegend": false}, {"type": "scatter", "xaxis": "x1", "yaxis": "y1", "visible": true, "name": "", "mode": "markers", "x": [0.755866942340936, 0.607768860563822, -0.266485836948459, 0.486808481996306, -0.011355745941142, -0.221955434404188, -0.668959704808564, 0.464057025402233, -0.190139497525539, -0.0674122966083764, 0.189265918790288, -0.5251990102672, -0.552259702590116], "y": [-0.141043240541916, 0.0946507446783786, -0.0863171443649695, -0.136181758610551, -0.0915890433446132, -0.0748556740171551, 0.184335479565507, 0.220178057380639, 0.184448937378935, -0.2906161669747, 0.254257597446798, -0.0571017280472755, -0.0601660605490777], "line": {}, "marker": {"size": 3.6, "symbol": "circle", "maxdisplayed": 14, "line": {"width": 0.5}, "color": "rgb(216.75,82.875,24.99)"}, "showlegend": false}], "layout": {"autosize": false, "margin": {"pad": 0, "l": 0, "r": 0, "b": 0, "t": 0}, "showlegend": false, "width": 840, "height": 630, "paper_bgcolor": "rgb(255,255,255)", "hovermode": "closest", "xaxis1": {"side": "bottom", "zeroline": false, "autorange": false, "linecolor": "rgb(38.250000,38.250000,38.250000)", "linewidth": 1, "exponentformat": "none", "tickfont": {"size": 10, "family": "Arial, sans-serif", "color": "rgb(38.250000,38.250000,38.250000)"}, "ticklen": 6.51, "tickcolor": "rgb(38.250000,38.250000,38.250000)", "tickwidth": 1, "tickangle": -0, "ticks": "inside", "showgrid": true, "gridwidth": 1, "gridcolor": "rgba(38.250000,,38.250000,38.250000,0.150000)", "type": "linear", "showticklabels": true, "tickmode": "array", "tickvals": [-0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8], "range": [-0.830840584740246, 0.830840584740246], "mirror": false, "ticktext": ["-0.8", "-0.6", "-0.4", "-0.2", "0", "0.2", "0.4", "0.6", "0.8"], "title": "Component 1", "titlefont": {"color": "rgb(38.250000,38.250000,38.250000)", "size": 11, "family": "Arial, sans-serif"}, "showline": true, "domain": [0.13, 0.905], "anchor": "y1"}, "scene1": {"domain": {"x": [0.13, 0.905], "y": [0.11, 0.925]}}, "yaxis1": {"side": "left", "zeroline": false, "autorange": false, "linecolor": "rgb(38.250000,38.250000,38.250000)", "linewidth": 1, "exponentformat": "none", "tickfont": {"size": 10, "family": "Arial, sans-serif", "color": "rgb(38.250000,38.250000,38.250000)"}, "ticklen": 6.51, "tickcolor": "rgb(38.250000,38.250000,38.250000)", "tickwidth": 1, "tickangle": -0, "ticks": "inside", "showgrid": true, "gridwidth": 1, "gridcolor": "rgba(38.250000,,38.250000,38.250000,0.150000)", "type": "linear", "showticklabels": true, "tickmode": "array", "tickvals": [-0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8], "range": [-0.830840584740246, 0.830840584740246], "mirror": false, "ticktext": ["-0.8", "-0.6", "-0.4", "-0.2", "0", "0.2", "0.4", "0.6", "0.8"], "title": "Component 2", "titlefont": {"color": "rgb(38.250000,38.250000,38.250000)", "size": 11, "family": "Arial, sans-serif"}, "showline": true, "domain": [0.11, 0.925], "anchor": "x1"}, "annotations": [{"showarrow": false, "xref": "paper", "yref": "paper", "xanchor": "center", "align": "center", "yanchor": "bottom", "text": "<b><b><\/b><\/b>", "x": 0.5175, "y": 0.935, "font": {"color": "rgb(0,0,0)", "family": "Arial, sans-serif", "size": 11}, "bordercolor": "rgba(0,0,0,0)", "textangle": 0, "borderwidth": 0.5, "borderpad": 3}, {"showarrow": false, "xref": "x1", "yref": "y1", "xanchor": "left", "align": "left", "yanchor": "middle", "text": "v_4", "x": 0.746873909451461, "y": -0.0924804771716762, "font": {"color": "rgb(0,0,0)", "family": "Arial, sans-serif", "size": 10}, "bordercolor": "rgba(0,0,0,0)", "textangle": 0, "borderwidth": 0.5, "borderpad": 3}, {"showarrow": false, "xref": "x1", "yref": "y1", "xanchor": "left", "align": "left", "yanchor": "middle", "text": "v_3", "x": 0.045020832106229, "y": 0.771309622491133, "font": {"color": "rgb(0,0,0)", "family": "Arial, sans-serif", "size": 10}, "bordercolor": "rgba(0,0,0,0)", "textangle": 0, "borderwidth": 0.5, "borderpad": 3}, {"showarrow": false, "xref": "x1", "yref": "y1", "xanchor": "left", "align": "left", "yanchor": "middle", "text": "v_2", "x": -0.662516235418647, "y": -0.0039933404840993, "font": {"color": "rgb(0,0,0)", "family": "Arial, sans-serif", "size": 10}, "bordercolor": "rgba(0,0,0,0)", "textangle": 0, "borderwidth": 0.5, "borderpad": 3}, {"showarrow": false, "xref": "x1", "yref": "y1", "xanchor": "left", "align": "left", "yanchor": "middle", "text": "v_1", "x": -0.0517999856954741, "y": -0.630018286568728, "font": {"color": "rgb(0,0,0)", "family": "Arial, sans-serif", "size": 10}, "bordercolor": "rgba(0,0,0,0)", "textangle": 0, "borderwidth": 0.5, "borderpad": 3}]}, "frames": []} , {"responsive": true} ).then(function() { var gd = document.getElementById("plot-9997773"); var x = new MutationObserver(function(mutations, observer) { { var display = window.getComputedStyle(gd).display; if (!display || display === 'none') { { console.log([gd, 'removed!']); Plotly.purge(gd); observer.disconnect(); } } } }); // Listen for the removal of the full notebook cells var notebookContainer = gd.closest('#notebook-container'); if (notebookContainer) { { x.observe(notebookContainer, { childList: true }); } } // Listen for the clearing of the current output cell var outputEl = gd.closest('.output'); if (outputEl) { { x.observe(outputEl, { childList: true }); } } }) }; }); </script> <p>All four variables are represented in this biplot by a vector, and the direction and length of the vector indicate how each variable contributes to the two principal components in the plot. For example, the first principal component, which is on the horizontal axis, has positive coefficients for the third and fourth variables. Therefore, vectors v3 and v4 are directed into the right half of the plot. The largest coefficient in the first principal component is the fourth, corresponding to the variable v4.</p> <p>The second principal component, which is on the vertical axis, has negative coefficients for the variables v1, v2, and v4, and a positive coefficient for the variable v3.</p> <p>This 2-D biplot also includes a point for each of the 13 observations, with coordinates indicating the score of each observation for the two principal components in the plot. For example, points near the left edge of the plot have the lowest scores for the first principal component. The points are scaled with respect to the maximum score value and maximum coefficient length, so only their relative locations can be determined from the plot.</p> <h2>T-Squared Statistic</h2> <p>Find the Hotelling’s T-squared statistic values. </p> <p>Load the sample data set. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> </code></pre></div> <p>The ingredients data has 13 observations for 4 variables. </p> <p>Perform the principal component analysis and request the T-squared values. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">);</span> <span class="n">tsquared</span> </code></pre></div> <pre class="code-output"> tsquared = 5.680340841490951 3.075837035211966 6.000232793912613 2.619763232047952 3.368139445336655 0.566796674771214 3.481840731756962 3.979397901620163 2.608586242833568 7.481756329327637 4.183022234152593 2.232718720505654 2.721567817032093 </pre> <p>Request only the first two principal components and compute the T-squared values in the reduced space of requested principal components. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">,</span><span class="s1">'NumComponents'</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span> <span class="n">tsquared</span> </code></pre></div> <pre class="code-output"> tsquared = 5.680340841490951 3.075837035211966 6.000232793912613 2.619763232047952 3.368139445336655 0.566796674771214 3.481840731756962 3.979397901620163 2.608586242833568 7.481756329327637 4.183022234152593 2.232718720505654 2.721567817032093 </pre> <p>Note that even when you specify a reduced component space, <code>pca</code> computes the T-squared values in the full space, using all four components. </p> <p>The T-squared value in the reduced space corresponds to the Mahalanobis distance in the reduced space. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">,</span><span class="s1">'NumComponents'</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span> <span class="n">tsqreduced</span> <span class="o">=</span> <span class="n">mahal</span><span class="p">(</span><span class="n">score</span><span class="p">,</span><span class="n">score</span><span class="p">)</span> </code></pre></div> <pre class="code-output"> tsqreduced = 3.317920809184487 2.007906801224291 0.587427300774747 1.738161538935849 0.295525889978777 0.422793560910442 3.245670063829735 2.691429716874080 1.361859279884830 2.990295498144076 2.437109148953179 1.378818611291408 1.525081780014097 </pre> <p>Calculate the T-squared values in the discarded space by taking the difference of the T-squared values in the full space and Mahalanobis distance in the reduced space. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">hald</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">ingredients</span><span class="p">,</span><span class="s1">'NumComponents'</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span> <span class="n">tsqreduced</span> <span class="o">=</span> <span class="n">mahal</span><span class="p">(</span><span class="n">score</span><span class="p">,</span><span class="n">score</span><span class="p">);</span> <span class="n">tsqdiscarded</span> <span class="o">=</span> <span class="n">tsquared</span> <span class="o">-</span> <span class="n">tsqreduced</span> </code></pre></div> <pre class="code-output"> tsqdiscarded = 2.362420032306464 1.067930233987675 5.412805493137867 0.881601693112104 3.072613555357878 0.144003113860771 0.236170667927227 1.287968184746083 1.246726962948738 4.491460831183561 1.745913085199414 0.853900109214246 1.196486037017995 </pre> <h2>Percent Variability Explained by Principal Components</h2> <p>Find the percent variability explained by the principal components. Show the data representation in the principal components space.</p> <p>Load the sample data set. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> </code></pre></div> <p>Data matrix <code>X</code> has 13 continuous variables in columns 3 to 15: wheel-base, length, width, height, curb-weight, engine-size, bore, stroke, compression-ratio, horsepower, peak-rpm, city-mpg, and highway-mpg. </p> <p>Find the percent variability explained by principal components of these variables. </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">X</span><span class="p">(:,</span><span class="mi">3</span><span class="p">:</span><span class="mi">15</span><span class="p">));</span> <span class="n">explained</span> </code></pre></div> <pre class="code-output"> explained = 64.342913356114238 35.448392662688399 0.154993220067715 0.037863222808984 0.007807396888358 0.004771746794250 0.001304050511812 0.001056438605476 0.000529182750646 0.000186613509121 0.000158017147436 0.000017269286049 0.000006822827515 </pre> <p>The first three components explain 99.95% of all variability. </p> <p>Visualize the data representation in the space of the first three principal components.</p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="n">tsquared</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">X</span><span class="p">(:,</span><span class="mi">3</span><span class="p">:</span><span class="mi">15</span><span class="p">));</span> <span class="nb">scatter3</span><span class="p">(</span><span class="n">score</span><span class="p">(:,</span><span class="mi">1</span><span class="p">),</span><span class="n">score</span><span class="p">(:,</span><span class="mi">2</span><span class="p">),</span><span class="n">score</span><span class="p">(:,</span><span class="mi">3</span><span class="p">))</span> <span class="nb">axis</span> <span class="n">equal</span> <span class="nb">xlabel</span><span class="p">(</span><span class="s1">'1st Principal Component'</span><span class="p">)</span> <span class="nb">ylabel</span><span class="p">(</span><span class="s1">'2nd Principal Component'</span><span class="p">)</span> <span class="nb">zlabel</span><span class="p">(</span><span class="s1">'3rd Principal Component'</span><span class="p">)</span> <span class="n">fig2plotly</span><span class="p">(</span><span class="nb">gcf</span><span class="p">);</span> </code></pre></div> <div id="plot-179669" class="plotly-graph-div js-plotly-plot"></div> <script type = "text/javascript" > require(["plotly"], function(Plotly) { window.PLOTLYENV = window.PLOTLYENV || {}; if (document.getElementById("plot-179669" )) { Plotly.newPlot("plot-179669", {"data": [{"type": "scatter3d", "scene": "scene1", "mode": "markers", "visible": true, "name": "", "x": [60.9330460982172, 60.9330460982189, 295.512756394536, -385.325784926617, 26.9009637846355, -240.258243810407, 43.8839912860603, 136.518005426043, 248.587564187436, 221.216091238923, -496.904037421166, -496.904037421166, 600.779213717667, 647.096220787659, 891.58965576803, 429.187103885566, 555.592489720539, 661.004472073843, -892.332383529972, -724.688909585178, -695.162335418226, -776.491432300275, -776.427970341212, -562.365402943768, -699.79467541983, -681.267872591833, -681.267872591833, -509.311675258018, 48.8600284550539, 285.349073423336, -540.341968777633, -1091.54967739205, -810.399064384003, -989.456153972971, -975.982115552609, -930.24055709682, -918.558612959472, -631.522353504318, -586.889601236872, -574.114527058352, -516.857969375254, -437.903844947286, -422.582823413483, -12.1351218496337, -724.688909585178, -695.214450540638, 216.252722205668, 1483.46816488866, 1483.46816488866, 1259.05368342661, -497.238189148218, -488.877804296457, -484.667167290094, -450.84369660382, -446.633044378404, null, null, null, null, 29.2775349394428, 50.3334073210532, 29.2775349394428, 50.3334073210532, 157.426312154624, 62.9653183401417, 164.849189600747, 615.410582546754, 1226.7788269294, 1424.68205076709, 1209.84564205341, 1441.78154479391, 1206.87292050916, 1159.98674928424, 1480.68218416821, 1324.42890415188, 369.119868057382, -741.007545027111, -719.048748432852, -668.521104356497, -548.054995705398, -357.049863726905, -125.581995157694, 303.875866465824, 377.983080821621, 382.193717827984, -94.430779211089, -60.7456831601863, -329.26715738539, -329.26715738539, -604.533995417315, -283.301592610859, -580.112300780411, -563.269752754959, -490.760232631482, -552.322096538416, -487.474686987399, -535.479548512965, -479.812576414939, -504.369805426311, -235.628687547211, -254.155490375207, 419.519305326097, 588.840521076404, 390.06032048847, 399.298855603637, 458.107993790521, 456.768680324131, 457.862514079391, 1062.87040872407, 634.983324468989, 1259.44219989096, 504.103516802092, 1109.18741579406, 681.221341247472, 1305.75920696095, 504.179521149382, 1109.18741579406, 232.296893497621, -741.122103648936, -562.365402943768, -699.79467541983, -681.087866678748, -510.52710211522, 48.8600314988645, 291.243958490547, -10.1494295484479, -237.642950872792, -237.642950872792, -200.589345216799, 360.00528566082, null, null, 19.8140294508941, 50.9727210958697, 61.0778530829002, 104.026747376042, 14.4341160722878, 47.2770847219179, -308.754464893138, 18.3066943308605, 119.351495784728, -173.897706300185, 77.8558833926313, -222.949592400225, 28.3593656020519, 134.692167981614, -51.6987438800033, -126.06443340389, 57.8384027006266, 252.671979856016, -310.589896375307, -264.238306295422, -285.291491327236, -61.9154445035531, -53.4286284240501, 637.115840619456, -228.91793015967, -205.33866151846, 94.9609106956486, 94.8486314491247, -218.101358076682, -194.354364386417, -179.196071163511, -154.74932886313, -125.27486981859, -1034.35145375599, -1004.87699471145, 162.368212823226, 158.999703218136, 171.631614237225, 279.423921600113, 308.898380644653, 528.695125348902, 300.552218466775, 268.523728325766, 374.686837957931, 374.688330930039, 411.740443613923, 319.100862000494, 352.792668862815, 449.530576800443, 465.816048754227, -78.0426171721703, -360.300255431124, -75.5162349683527, -357.773873227306, -304.719846947134, 131.789067109145, -416.697946071824, -456.031978835174, -483.714041291151, -110.50104600986, 350.981554382964, -195.428004810286, 154.890411637274, 257.631895456269, 174.252631055125, 264.362203855031, 428.527331118504, 522.847540924773, 188.619053563883, 325.549384935146, 188.330533053078, 732.422132469376, 281.303130242202], "y": [-109.379610318519, -109.379610318519, 39.9715702983918, 199.705855894334, 459.962238784637, 291.485791236185, 470.414098415928, 528.76131165529, 600.454499443054, 583.983506985827, 483.77328276521, 483.77328276521, -654.898355329008, -625.724748709327, -471.736134575074, 597.795674036164, 677.408969438407, 743.793630259215, -594.327934969095, -133.447111141255, -114.854148690986, -48.0075951338528, -47.9250123029576, 88.2307004650038, 0.344119874166747, 12.013562522039, 12.013562522039, 121.647814726654, -117.919672841349, 33.2677130354446, -726.573078957238, 344.547891337906, -69.6824580648055, 408.846789902798, 417.333657283069, 446.112895858146, 453.4766107501, 398.434874360622, 426.547622557769, 434.57987748558, 470.643856674796, 520.953027129764, 176.188703763871, -392.934762277246, -133.447111141255, -114.882088746913, -12.385742876501, 493.921629060001, 493.921629060001, 651.201282035035, -462.663332105973, -457.432644386546, -454.780498330212, -433.489144213798, -430.8369919557, null, null, null, null, -366.653703687957, -353.393638972795, -366.653703687957, -353.393638972795, -464.004343277259, -345.437200803791, -43.6205334539268, -706.747283410686, -142.45420536902, -17.8041541914728, -153.103984772212, -7.06393608912815, 318.869753682887, 289.429103046769, 197.242028065803, 98.8520387616758, 87.0423547035671, -25.6526081514004, -11.7788962040243, 20.0468564719909, 97.2460817111151, 218.061172723051, -227.775267905362, 44.9371517033046, 91.6149235351464, 94.2670695914809, -208.155981259892, -186.938812809215, 235.558742523454, 235.558742523454, -293.99243799066, -564.830371284327, -278.609990863919, -268.001406638581, -222.336915650439, -261.105826892111, -220.259443562938, -250.497242666772, -215.441335903969, -230.897216470165, -60.5482692844774, -72.2177119323497, 354.317321868467, 460.961163629872, 335.734307998828, 341.895198075961, 380.406209649961, 378.061149599293, 140.042015258784, -483.080112235025, 251.566189140262, -359.254944616353, 169.095511619556, -453.906505615345, 280.620425019379, -330.081337996673, 169.215621878465, -453.906505615345, 708.385789589063, -25.729537884183, 88.2307004650038, 0.344119874166747, 12.1098335906414, 119.55962459597, -117.919671600996, 36.9807147746534, 437.669730880658, 769.3216888371, 769.3216888371, 792.660574132845, 971.474989649134, null, null, 159.904763474151, 179.530674667487, 185.895663684745, 212.947714977303, 453.65477602556, 474.34151526497, -462.041858199722, -846.444455932223, -782.800179566055, -494.772830986496, -808.663899906985, -52.6823803646843, -367.285788142642, -299.273960631975, -417.762700858662, 8.34906081694926, -348.733518883328, -224.934553957579, -581.629284366554, -552.409849800454, -565.670580082128, -424.993353442901, -419.606405290991, 15.3455479478843, -529.86094394603, -515.008852078722, -680.787325435111, -680.925149661751, -523.130676278042, -508.067340801029, -498.519614998224, -483.12718122847, -464.562158834127, 1090.640091176, 1109.20511357034, -281.589726547916, -283.711443392984, -275.75500522398, -207.860066181814, -189.295043787472, -50.8533894059778, -904.277461784495, -570.853195589533, -857.562596925816, -857.562966684988, -834.223711630071, 291.33854560673, 312.56486928821, 373.297910673173, 383.536787217551, -435.634185184296, -80.4730204134311, -434.042897550495, -78.8817327796303, -45.4646924698143, -657.247254960754, 179.867260542134, 154.788041552385, 137.346705665371, 373.211096207159, -519.168913630743, 318.792343788349, 422.337224048746, 487.049107136386, 434.527940677081, 491.283385595718, 242.090161211578, 301.497752186549, 443.571063720938, 413.392392207541, 562.362265907828, 76.9959570754892, 501.982518953129], "z": [12.3557042401564, 12.3557042401564, 32.7755971151032, -3.00593088375729, -19.3257397030938, 5.67285944941684, -26.6857385156898, -36.6907386875125, -29.8175677767956, -10.4186080908073, -16.9973397810916, -16.9973397810916, 44.0825131754266, 39.0800130895152, 11.6682630075161, 42.3865484895561, 28.4587849372529, 16.3933348066854, 14.6588832446066, 6.67303063200378, 3.26537488972928, 2.68220165369528, 3.01094562610989, 10.8702121987698, -5.25708742177628, -7.25808745614083, -7.25808745614083, 5.14890646734762, -10.6841263541739, 29.9151770542144, 29.2132156383477, 4.60600750044463, -6.52568288656121, -7.2089786845027, -8.66425143676782, -14.8790327974477, -15.8328357010304, -11.4093294058016, -16.2299203976798, -18.2404401853764, -24.4206999141949, -21.6376815971701, 1.1044204108953, -1.19010008667004, 6.67303063200378, 3.48962148642381, -28.3051458327177, 9.09718855783588, 9.09718855783588, 123.083918840302, 14.6327831892006, 13.4874989861502, 13.0327262510673, 8.79913099297419, 8.34443842897591, null, null, null, null, 5.09210501882409, 2.73876476781407, 5.09210501882409, 2.73876476781407, -12.5171435579822, 1.37444656256552, 12.7991224831187, -10.9003643238672, -19.7878918674719, -41.2593484532052, -17.4193664079415, -44.2459403921869, 6.8872982939792, 15.1108585905535, 68.0534872285665, 83.5588127345056, 31.1913002095878, 0.185781960075913, -1.85071044617411, -7.30798326716834, 9.36977738731921, 5.77758533391288, 9.08645412371407, 27.9141347282589, 19.9101506250176, 19.4553778899347, 5.67039369485367, 2.03221181419085, 2.72534309311876, 2.72534309311876, 13.7258079044951, 4.1293859879198, 11.0881260410146, 9.26903510068319, 1.11219828836576, 8.08662598946777, 1.11291232912636, 6.26753504913636, -0.0702108228496569, 3.14019708609307, 9.36533303848491, 11.3663330728495, 19.7580419381537, 1.20777773801972, 22.552064774921, 29.3162866715114, 52.6116647714606, 22.0114305215952, -50.2613421200367, -26.9949277700665, -70.805618924584, -49.2859784843833, -56.7287386710568, -31.9974278559779, -77.1847081693866, -54.2884785702946, -55.2638422059481, -31.9974278559779, -32.5900159906098, -1.13747116476688, 10.8702121987698, -5.25708742177628, -8.04018231329547, -21.1158554505531, -10.684110319957, 29.2784689677243, 16.1473723920962, 84.1154303206276, 84.1154303206276, 80.1134302518985, 96.4023358031983, null, null, -12.8846817178006, -16.2495818011799, -17.342895365999, -21.9797182632239, 4.12498704568775, 0.577759712041492, 7.20121476999948, 23.5522756306667, 12.6216412608963, 16.3731108372058, 22.3362178838148, -1.95172912419393, -4.84090679425295, 4.97003244189549, 3.38305699145096, -12.4678394959709, -8.23858762873417, -7.69938696236991, 6.56850535079692, 1.75704025564383, 4.0309039310581, -21.097899485124, -21.7050144177491, -96.2877429713369, 7.40536840775791, 4.86747182191568, -5.9101099419502, -6.37080306904248, 5.61809822146131, 3.85020242281835, 2.21302057652008, -0.563020254892101, -3.74642940047208, -22.3088574982945, -25.4922666438745, 30.6547577093337, 31.0185758974, 29.6542576921514, 18.0120756740304, 14.8286665284504, -8.95462389598325, 30.688477505089, -13.1045551417628, 22.8659218461621, 22.8217681930533, 18.863921777433, 30.1922949333199, 26.5949095786727, 11.9090911334475, 3.50936501901971, -24.5755299054064, 2.59009343233374, -24.8483935464561, 2.31722979128403, -3.41290667075991, -10.6862609875139, -0.760710030991419, -2.52347068551576, 0.16893007316665, -8.65912972638634, -34.895850015336, -34.4193752283912, -24.088090902298, -35.241945387361, -26.2208420096948, -36.0103782895093, -0.485882073119188, -10.7301910880165, -28.0122982996354, -0.422421509844722, 0.292154932134005, -41.3132464533848, -37.7705657073087], "marker": {"sizeref": 1, "sizemode": "area", "size": [72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72], "line": {"width": 0.75, "color": "rgb(0.000000,113.985000,188.955000)"}, "symbol": "circle", "color": "rgba(0,0,0,0)", "opacity": 1}, "showlegend": false}], "layout": {"autosize": false, "margin": {"pad": 0, "l": 0, "r": 0, "b": 0, "t": 0}, "showlegend": false, "width": 840, "height": 630, "paper_bgcolor": "rgb(255,255,255)", "hovermode": "closest", "xaxis1": {"side": "bottom", "zeroline": false, "autorange": false, "linecolor": "rgb(38.250000,38.250000,38.250000)", "linewidth": 1, "exponentformat": "none", "tickfont": {"size": 10, "family": "Arial, sans-serif", "color": "rgb(38.250000,38.250000,38.250000)"}, "ticklen": 6.51, "tickcolor": "rgb(38.250000,38.250000,38.250000)", "tickwidth": 1, "tickangle": -0, "ticks": "outside", "showgrid": true, "gridwidth": 1, "gridcolor": "rgba(38.250000,,38.250000,38.250000,0.150000)", "type": "linear", "showticklabels": true, "tickmode": "array", "tickvals": [-1000, -500, 0, 500, 1000], "range": [-1091.54967739205, 1483.46816488866], "mirror": false, "ticktext": ["-1000", "-500", "0", "500", "1000"], "title": "1st Principal Component", "titlefont": {"color": "rgb(38.250000,38.250000,38.250000)", "size": 11, "family": "Arial, sans-serif"}, "showline": true, "domain": [0.13, 0.905], "anchor": "y1"}, "scene1": {"domain": {"x": [0.13, 0.905], "y": [0.11, 0.925]}, "aspectratio": {"x": 11.7381516874851, "y": 9.17840781588137, "z": 1}, "camera": {"eye": {"x": -9.26190074800544, "y": -12.2381516874851, "z": 9.00265151277708}, "up": {"x": 0, "y": 0, "z": 1}}, "xaxis": {"range": [-1091.54967739205, 1483.46816488866], "zeroline": false, "showline": true, "ticklabelposition": "outside", "title": "1st Principal Component", "titlefont": {"color": "rgba(0,0,0,1)", "size": 11, "family": "Arial, sans-serif"}, "tickvals": [-1000, -500, 0, 500, 1000], "ticktext": ["-1000", "-500", "0", "500", "1000"], "tickcolor": "rgba(0,0,0,1)", "tickfont": {"size": 10, "family": "Arial, sans-serif"}}, "yaxis": {"range": [-904.277461784495, 1109.20511357034], "zeroline": false, "showline": true, "ticklabelposition": "outside", "title": "2nd Principal Component", "titlefont": {"color": "rgba(0,0,0,1)", "size": 11, "family": "Arial, sans-serif"}, "tickvals": [-500, 0, 500, 1000], "ticktext": ["-500", "0", "500", "1000"], "tickcolor": "rgba(0,0,0,1)", "tickfont": {"size": 10, "family": "Arial, sans-serif"}}, "zaxis": {"range": [-96.2877429713369, 123.083918840302], "zeroline": false, "showline": true, "ticklabelposition": "outside", "title": "3rd Principal Component", "titlefont": {"color": "rgba(0,0,0,1)", "size": 11, "family": "Arial, sans-serif"}, "tickvals": [-50, 0, 50, 100], "ticktext": ["-50", "0", "50", "100"], "tickcolor": "rgba(0,0,0,1)", "tickfont": {"size": 10, "family": "Arial, sans-serif"}}}, "yaxis1": {"side": "left", "zeroline": false, "autorange": false, "linecolor": "rgb(38.250000,38.250000,38.250000)", "linewidth": 1, "exponentformat": "none", "tickfont": {"size": 10, "family": "Arial, sans-serif", "color": "rgb(38.250000,38.250000,38.250000)"}, "ticklen": 6.51, "tickcolor": "rgb(38.250000,38.250000,38.250000)", "tickwidth": 1, "tickangle": -0, "ticks": "outside", "showgrid": true, "gridwidth": 1, "gridcolor": "rgba(38.250000,,38.250000,38.250000,0.150000)", "type": "linear", "showticklabels": true, "tickmode": "array", "tickvals": [-500, 0, 500, 1000], "range": [-904.277461784495, 1109.20511357034], "mirror": false, "ticktext": ["-500", "0", "500", "1000"], "title": "2nd Principal Component", "titlefont": {"color": "rgb(38.250000,38.250000,38.250000)", "size": 11, "family": "Arial, sans-serif"}, "showline": true, "domain": [0.11, 0.925], "anchor": "x1"}, "annotations": [{"showarrow": false, "xref": "paper", "yref": "paper", "xanchor": "center", "align": "center", "yanchor": "bottom", "text": "<b><b><\/b><\/b>", "x": 0.5175, "y": 0.935, "font": {"color": "rgb(0,0,0)", "family": "Arial, sans-serif", "size": 11}, "bordercolor": "rgba(0,0,0,0)", "textangle": 0, "borderwidth": 0.5, "borderpad": 3}]}, "frames": []} , {"responsive": true} ).then(function() { var gd = document.getElementById("plot-179669"); var x = new MutationObserver(function(mutations, observer) { { var display = window.getComputedStyle(gd).display; if (!display || display === 'none') { { console.log([gd, 'removed!']); Plotly.purge(gd); observer.disconnect(); } } } }); // Listen for the removal of the full notebook cells var notebookContainer = gd.closest('#notebook-container'); if (notebookContainer) { { x.observe(notebookContainer, { childList: true }); } } // Listen for the clearing of the current output cell var outputEl = gd.closest('.output'); if (outputEl) { { x.observe(outputEl, { childList: true }); } } }) }; }); </script> <p>The data shows the largest variability along the first principal component axis. This is the largest possible variance among all possible choices of the first axis. The variability along the second principal component axis is the largest among all possible remaining choices of the second axis. The third principal component axis has the third largest variability, which is significantly smaller than the variability along the second principal component axis. The fourth through thirteenth principal component axes are not worth inspecting, because they explain only 0.05% of all variability in the data.</p> <p>To skip any of the outputs, you can use <code>~</code> instead in the corresponding element. For example, if you don’t want to get the T-squared values, specify </p> <div class="highlight"><pre><code class="language-matlab" data-lang="matlab"><span class="nb">load</span> <span class="n">imports</span><span class="o">-</span><span class="mi">85</span> <span class="p">[</span><span class="n">coeff</span><span class="p">,</span><span class="n">score</span><span class="p">,</span><span class="n">latent</span><span class="p">,</span><span class="o">~</span><span class="p">,</span><span class="n">explained</span><span class="p">]</span> <span class="o">=</span> <span class="n">pca</span><span class="p">(</span><span class="n">X</span><span class="p">(:,</span><span class="mi">3</span><span class="p">:</span><span class="mi">15</span><span class="p">));</span> </code></pre></div> </section> <!--End Plotly Basics Section--> </section> </div> </main> <script> var array = []; $('.tutorial-content :header:not(h6)').each(function (i, e) { var item = $(e); var itemText = item.text(); var hash = itemText.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-').replace(/^-+|-+$/g, '').toLowerCase(); item.attr("id", hash); array.push({text: itemText, tag: item.prop("tagName"), hash: hash}); }); $("#nav_header_insertion_list").html(array.map(function(entry) { var text = entry.text.replace(/[^a-z0-9\s\.:\-\?\!\(\))]/gi, ''); if(entry.tag.toLowerCase() < "h4"){ return('<li class="--sidebar-item"><a href="#' + entry.hash + '">' + text + '</a></li>'); } else { return('<li class="--sidebar-item"><a href="#' + entry.hash + '">' + text + '</a></li>'); } }).join("")); //$(".tutorial-content :header:not(h6)").append( "\<div class=\"icon copy\" data-tooltip=\"Click to copy direct link\"><svg style=\"width:24px;height:24px\" viewBox=\"0 0 24 24\"><path fill=\"#000000\" d=\"M10.59,13.41C11,13.8 11,14.44 10.59,14.83C10.2,15.22 9.56,15.22 9.17,14.83C7.22,12.88 7.22,9.71 9.17,7.76V7.76L12.71,4.22C14.66,2.27 17.83,2.27 19.78,4.22C21.73,6.17 21.73,9.34 19.78,11.29L18.29,12.78C18.3,11.96 18.17,11.14 17.89,10.36L18.36,9.88C19.54,8.71 19.54,6.81 18.36,5.64C17.19,4.46 15.29,4.46 14.12,5.64L10.59,9.17C9.41,10.34 9.41,12.24 10.59,13.41M13.41,9.17C13.8,8.78 14.44,8.78 14.83,9.17C16.78,11.12 16.78,14.29 14.83,16.24V16.24L11.29,19.78C9.34,21.73 6.17,21.73 4.22,19.78C2.27,17.83 2.27,14.66 4.22,12.71L5.71,11.22C5.7,12.04 5.83,12.86 6.11,13.65L5.64,14.12C4.46,15.29 4.46,17.19 5.64,18.36C6.81,19.54 8.71,19.54 9.88,18.36L13.41,14.83C14.59,13.66 14.59,11.76 13.41,10.59C13,10.2 13,9.56 13.41,9.17Z\"/> </svg> </div>"); </script> <footer class="--footer-main"> <section class="--footer-top"> <div class="--wrap"> <ul class="--footer-body"> <li class="--footer-column"> <h6 style="color:#119dff" class="--footer-heading">JOIN OUR MAILING LIST</h6>&#x9;&#x9;&#x9; <ul> &#x9;&#x9;&#x9;&#x9; <li> <p class="subscribe-text"> Sign up to stay in the loop with all things Plotly — from Dash Club to product updates, webinars, and more!</p> <a href="https://go.plot.ly/subscription" class="subscribe-button" target="_blank"> Subscribe </a> </li> </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#e763fa" class="--footer-heading">Products</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://plotly.com/dash/" target="_self">Dash</a></li> &#x9;&#x9;&#x9;&#x9; &#x9;&#x9;&#x9;&#x9; <li><a href="https://plotly.com/consulting-and-oem/" target="_self">Consulting and Training</a></li> </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#636efa" class="--footer-heading">Pricing</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://plotly.com/get-pricing/" target="_self">Enterprise Pricing</a></li> &#x9;&#x9;&#x9;&#x9; </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#00cc96" class="--footer-heading">About Us</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://plotly.com/careers" target="_self">Careers</a></li> &#x9;&#x9;&#x9;&#x9; <li><a href="https://plotly.com/resources/" target="_self">Resources</a></li> &#x9;&#x9;&#x9;&#x9; <li><a href="https://medium.com/@plotlygraphs" target="_self">Blog</a></li> &#x9;&#x9;&#x9;&#x9; </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#EF553B" class="--footer-heading">Support</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://community.plot.ly/" target="_self">Community Support</a></li> &#x9;&#x9;&#x9;&#x9; <li><a href="https://plotly.com/graphing-libraries" target="_self">Documentation</a></li> &#x9;&#x9;&#x9;&#x9; </ul> </li> </ul> </div> </section> <section class="--footer-meta"> <div class="--wrap"> <div class="left"> <article class="--copyright">Copyright &copy; 2024 Plotly. All rights reserved.</article> </div> <div class="right"> <article class="--tos"><a href="https://community.plotly.com/tos" target="_blank">Terms of Service</a> </article> <article class="--privacy"><a href="https://plotly.com/privacy/" target="_blank">Privacy Policy</a> </article> </div> </div> <div id="markprompt" /> </section> </footer> <div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content" id="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <span style="float: left; padding-top:13px; padding-right:10px;"><i class="fa fa-search fa-lg"></i></span> <input id="search-input" class="search-input" type="text" placeholder="" /> </div> <div class="modal-body" id="modal-body"> <div id="search-results" class="search-results"> <div id="primary-search-results" class="primary-search-results"></div> <div id="schema-search-results" class="schema-search-results"></div> </div> </div> </div> </div> </div> <script> window.plotly_doc_language = "matlab"; </script> <!-- ALGOLIA SEARCH --> <script> window.ALGOLIA_CONFIG = { 'applicationId': '7EK9KHJW8M', 'indexName': 'matlab_docs', 'apiKey': '4dae07ded6a721de73bde7356eec9280', 'baseurl': '/' } </script> <script id="algolia__template" type="text/template"> <div class="algolia__result"> <a class="algolia__result-link" onClick="$('#myModal').modal('toggle')" href="/{{ permalink }}">{{{ _highlightResult.name.value }}}</a> <div class="algolia__result-text">{{{ _highlightResult.description.value }}}</div> </div> </script> <script id="algolia__secondary-template" type="text/template"> <div class="algolia__secondary-result"> <a class="algolia__result-link" onClick="$('#myModal').modal('toggle')" href="/{{ permalink }}">{{{ _highlightResult.name.value }}}</a> <div class="algolia__result-text">{{{ _highlightResult.description.value }}}</div> </div> </script> <script id="algolia__template--no-results" type="text/template">No results found.</script> <script src="//cdn.jsdelivr.net/hogan.js/3.0.2/hogan.min.js"></script> <script src="/all_static/javascripts/algolia/algolia.js"></script> <!-- Hash offset Script --> <script src="/all_static//javascripts/hash_offset.js"></script> <!-- Image Hover Script --> <script src="/all_static/javascripts/imghover.js"></script> <script src="/all_static/javascripts/improve.js?version=2024-11-27-15-11"></script> <!-- code highlighting --> <!--<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"></script> <script src="/all_static/javascripts/highlight.line-numbers.js"></script>--> <script src="/all_static/javascripts/highlight/highlight.min.js"></script> <script src="/all_static/javascripts/highlight/julia.min.js"></script> <script src="/all_static/javascripts/highlight.line-numbers.js"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10