Completing MDS manually in R












5












$begingroup$


Given a matrix A, I want to complete Multidimensional Scaling by hand, instead of using any given R functions.



As such, I have calculated the centered matrix B with the following code:



 n<-nrow(A)
id<-diag(n)
e<-diag(id)
H <- id - (1/n)*e %*% etranspose
B <- (-1/2)* H %*% A %*% H


My question is: how can I use my B matrix to complete multidimensional scaling on my A matrix, without the cmdscale function or anything along those lines?










share|improve this question











$endgroup$




bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    5












    $begingroup$


    Given a matrix A, I want to complete Multidimensional Scaling by hand, instead of using any given R functions.



    As such, I have calculated the centered matrix B with the following code:



     n<-nrow(A)
    id<-diag(n)
    e<-diag(id)
    H <- id - (1/n)*e %*% etranspose
    B <- (-1/2)* H %*% A %*% H


    My question is: how can I use my B matrix to complete multidimensional scaling on my A matrix, without the cmdscale function or anything along those lines?










    share|improve this question











    $endgroup$




    bumped to the homepage by Community 4 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      5












      5








      5





      $begingroup$


      Given a matrix A, I want to complete Multidimensional Scaling by hand, instead of using any given R functions.



      As such, I have calculated the centered matrix B with the following code:



       n<-nrow(A)
      id<-diag(n)
      e<-diag(id)
      H <- id - (1/n)*e %*% etranspose
      B <- (-1/2)* H %*% A %*% H


      My question is: how can I use my B matrix to complete multidimensional scaling on my A matrix, without the cmdscale function or anything along those lines?










      share|improve this question











      $endgroup$




      Given a matrix A, I want to complete Multidimensional Scaling by hand, instead of using any given R functions.



      As such, I have calculated the centered matrix B with the following code:



       n<-nrow(A)
      id<-diag(n)
      e<-diag(id)
      H <- id - (1/n)*e %*% etranspose
      B <- (-1/2)* H %*% A %*% H


      My question is: how can I use my B matrix to complete multidimensional scaling on my A matrix, without the cmdscale function or anything along those lines?







      machine-learning statistics dimensionality-reduction






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 28 '18 at 0:50









      Alex L

      1478




      1478










      asked Nov 16 '15 at 1:53









      potatosouppotatosoup

      262




      262





      bumped to the homepage by Community 4 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 4 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          If you're interested in the classic MDS algorithm, it is spelled out very nicely on the Wikipedia page:




          Classical MDS uses the fact that the coordinate matrix can be derived
          by eigenvalue decomposition from $B=XX'$. And the matrix $B$ can be
          computed from proximity matrix $D$ by using double centering.




          1. Set up the squared proximity matrix $D^{(2)}=[d_{ij}^{2}]$

          2. Apply double centering: $B=-{frac {1}{2}}JD^{(2)}J$ using the centering matrix $J=I-{frac {1}{n}}11'$, where $n$ is the number of
            objects.


          3. Determine the $m$ largest eigenvalues $lambda _{1},lambda _{2},...,lambda _{m}$ and corresponding eigenvectors $e_{1},e_{2},...,e_{m}$ of $B$ (where $m$ is the number of dimensions
            desired for the output).


          4. Now, $X=E_{m}Lambda _{m}^{1/2}$, where $E_{m}$ is the matrix of $m$ eigenvectors and $Lambda _{m}$ is the diagonal matrix of $m$
            eigenvalues of $B$.





          I can't really tell what your $A$ matrix is, but if each entry is a measure of the distance from the $i^{th}$ to $j^{th}$ entry, then that would be your proximity matrix.



          Also, $11'$ is an n-by-n matrix of all 1's. This should be fairly self-explanatory, however most of these terms can be Googled if you're unsure. It really shouldn't be any more than about 10 lines of code.






          share|improve this answer









          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "557"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f8853%2fcompleting-mds-manually-in-r%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0












            $begingroup$

            If you're interested in the classic MDS algorithm, it is spelled out very nicely on the Wikipedia page:




            Classical MDS uses the fact that the coordinate matrix can be derived
            by eigenvalue decomposition from $B=XX'$. And the matrix $B$ can be
            computed from proximity matrix $D$ by using double centering.




            1. Set up the squared proximity matrix $D^{(2)}=[d_{ij}^{2}]$

            2. Apply double centering: $B=-{frac {1}{2}}JD^{(2)}J$ using the centering matrix $J=I-{frac {1}{n}}11'$, where $n$ is the number of
              objects.


            3. Determine the $m$ largest eigenvalues $lambda _{1},lambda _{2},...,lambda _{m}$ and corresponding eigenvectors $e_{1},e_{2},...,e_{m}$ of $B$ (where $m$ is the number of dimensions
              desired for the output).


            4. Now, $X=E_{m}Lambda _{m}^{1/2}$, where $E_{m}$ is the matrix of $m$ eigenvectors and $Lambda _{m}$ is the diagonal matrix of $m$
              eigenvalues of $B$.





            I can't really tell what your $A$ matrix is, but if each entry is a measure of the distance from the $i^{th}$ to $j^{th}$ entry, then that would be your proximity matrix.



            Also, $11'$ is an n-by-n matrix of all 1's. This should be fairly self-explanatory, however most of these terms can be Googled if you're unsure. It really shouldn't be any more than about 10 lines of code.






            share|improve this answer









            $endgroup$


















              0












              $begingroup$

              If you're interested in the classic MDS algorithm, it is spelled out very nicely on the Wikipedia page:




              Classical MDS uses the fact that the coordinate matrix can be derived
              by eigenvalue decomposition from $B=XX'$. And the matrix $B$ can be
              computed from proximity matrix $D$ by using double centering.




              1. Set up the squared proximity matrix $D^{(2)}=[d_{ij}^{2}]$

              2. Apply double centering: $B=-{frac {1}{2}}JD^{(2)}J$ using the centering matrix $J=I-{frac {1}{n}}11'$, where $n$ is the number of
                objects.


              3. Determine the $m$ largest eigenvalues $lambda _{1},lambda _{2},...,lambda _{m}$ and corresponding eigenvectors $e_{1},e_{2},...,e_{m}$ of $B$ (where $m$ is the number of dimensions
                desired for the output).


              4. Now, $X=E_{m}Lambda _{m}^{1/2}$, where $E_{m}$ is the matrix of $m$ eigenvectors and $Lambda _{m}$ is the diagonal matrix of $m$
                eigenvalues of $B$.





              I can't really tell what your $A$ matrix is, but if each entry is a measure of the distance from the $i^{th}$ to $j^{th}$ entry, then that would be your proximity matrix.



              Also, $11'$ is an n-by-n matrix of all 1's. This should be fairly self-explanatory, however most of these terms can be Googled if you're unsure. It really shouldn't be any more than about 10 lines of code.






              share|improve this answer









              $endgroup$
















                0












                0








                0





                $begingroup$

                If you're interested in the classic MDS algorithm, it is spelled out very nicely on the Wikipedia page:




                Classical MDS uses the fact that the coordinate matrix can be derived
                by eigenvalue decomposition from $B=XX'$. And the matrix $B$ can be
                computed from proximity matrix $D$ by using double centering.




                1. Set up the squared proximity matrix $D^{(2)}=[d_{ij}^{2}]$

                2. Apply double centering: $B=-{frac {1}{2}}JD^{(2)}J$ using the centering matrix $J=I-{frac {1}{n}}11'$, where $n$ is the number of
                  objects.


                3. Determine the $m$ largest eigenvalues $lambda _{1},lambda _{2},...,lambda _{m}$ and corresponding eigenvectors $e_{1},e_{2},...,e_{m}$ of $B$ (where $m$ is the number of dimensions
                  desired for the output).


                4. Now, $X=E_{m}Lambda _{m}^{1/2}$, where $E_{m}$ is the matrix of $m$ eigenvectors and $Lambda _{m}$ is the diagonal matrix of $m$
                  eigenvalues of $B$.





                I can't really tell what your $A$ matrix is, but if each entry is a measure of the distance from the $i^{th}$ to $j^{th}$ entry, then that would be your proximity matrix.



                Also, $11'$ is an n-by-n matrix of all 1's. This should be fairly self-explanatory, however most of these terms can be Googled if you're unsure. It really shouldn't be any more than about 10 lines of code.






                share|improve this answer









                $endgroup$



                If you're interested in the classic MDS algorithm, it is spelled out very nicely on the Wikipedia page:




                Classical MDS uses the fact that the coordinate matrix can be derived
                by eigenvalue decomposition from $B=XX'$. And the matrix $B$ can be
                computed from proximity matrix $D$ by using double centering.




                1. Set up the squared proximity matrix $D^{(2)}=[d_{ij}^{2}]$

                2. Apply double centering: $B=-{frac {1}{2}}JD^{(2)}J$ using the centering matrix $J=I-{frac {1}{n}}11'$, where $n$ is the number of
                  objects.


                3. Determine the $m$ largest eigenvalues $lambda _{1},lambda _{2},...,lambda _{m}$ and corresponding eigenvectors $e_{1},e_{2},...,e_{m}$ of $B$ (where $m$ is the number of dimensions
                  desired for the output).


                4. Now, $X=E_{m}Lambda _{m}^{1/2}$, where $E_{m}$ is the matrix of $m$ eigenvectors and $Lambda _{m}$ is the diagonal matrix of $m$
                  eigenvalues of $B$.





                I can't really tell what your $A$ matrix is, but if each entry is a measure of the distance from the $i^{th}$ to $j^{th}$ entry, then that would be your proximity matrix.



                Also, $11'$ is an n-by-n matrix of all 1's. This should be fairly self-explanatory, however most of these terms can be Googled if you're unsure. It really shouldn't be any more than about 10 lines of code.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 27 '18 at 22:48









                Alex LAlex L

                1478




                1478






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f8853%2fcompleting-mds-manually-in-r%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to label and detect the document text images

                    Vallis Paradisi

                    Tabula Rosettana