Calculating relative difference between two data sets which include negative numbers












0












$begingroup$


I need to determine the relative difference between each element in vector 'A' and its corresponding element in 'B'. The vectors are:



A = 18.40,6.06,12.46,25.25,60.00,30.77,48.95,35.77,29.73,38.40,36.36,35.33,20.18,82.46,34.25,10.83,49.08,25.00,63.06,-5.31,15.55,35.02,15.96
B = -2.40,-43.94,-2.36,-6.57,21.82,11.83,20.92,15.45,17.57,24.80,24.24,24,14.8,74.85,33.33,10.83,49.21,25.56,64.72,-5.54,16.39,40.11,36.17


Normally I would simply divide A by B to get the ratio between the two numbers, however these data vectors contain negative numbers meaning the magnitude of the absolute difference (A-B) between A and B is not being captured. Is there a way to transform the data such that I always get a positive ratio between the two numbers and that for example A=6.06 and B=-43.94 (absolute difference = 50.00) gives a larger ratio than e.g. A=60.00 and B=21.82?



Thank you for your time,



Laura










share|cite|improve this question









$endgroup$

















    0












    $begingroup$


    I need to determine the relative difference between each element in vector 'A' and its corresponding element in 'B'. The vectors are:



    A = 18.40,6.06,12.46,25.25,60.00,30.77,48.95,35.77,29.73,38.40,36.36,35.33,20.18,82.46,34.25,10.83,49.08,25.00,63.06,-5.31,15.55,35.02,15.96
    B = -2.40,-43.94,-2.36,-6.57,21.82,11.83,20.92,15.45,17.57,24.80,24.24,24,14.8,74.85,33.33,10.83,49.21,25.56,64.72,-5.54,16.39,40.11,36.17


    Normally I would simply divide A by B to get the ratio between the two numbers, however these data vectors contain negative numbers meaning the magnitude of the absolute difference (A-B) between A and B is not being captured. Is there a way to transform the data such that I always get a positive ratio between the two numbers and that for example A=6.06 and B=-43.94 (absolute difference = 50.00) gives a larger ratio than e.g. A=60.00 and B=21.82?



    Thank you for your time,



    Laura










    share|cite|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      I need to determine the relative difference between each element in vector 'A' and its corresponding element in 'B'. The vectors are:



      A = 18.40,6.06,12.46,25.25,60.00,30.77,48.95,35.77,29.73,38.40,36.36,35.33,20.18,82.46,34.25,10.83,49.08,25.00,63.06,-5.31,15.55,35.02,15.96
      B = -2.40,-43.94,-2.36,-6.57,21.82,11.83,20.92,15.45,17.57,24.80,24.24,24,14.8,74.85,33.33,10.83,49.21,25.56,64.72,-5.54,16.39,40.11,36.17


      Normally I would simply divide A by B to get the ratio between the two numbers, however these data vectors contain negative numbers meaning the magnitude of the absolute difference (A-B) between A and B is not being captured. Is there a way to transform the data such that I always get a positive ratio between the two numbers and that for example A=6.06 and B=-43.94 (absolute difference = 50.00) gives a larger ratio than e.g. A=60.00 and B=21.82?



      Thank you for your time,



      Laura










      share|cite|improve this question









      $endgroup$




      I need to determine the relative difference between each element in vector 'A' and its corresponding element in 'B'. The vectors are:



      A = 18.40,6.06,12.46,25.25,60.00,30.77,48.95,35.77,29.73,38.40,36.36,35.33,20.18,82.46,34.25,10.83,49.08,25.00,63.06,-5.31,15.55,35.02,15.96
      B = -2.40,-43.94,-2.36,-6.57,21.82,11.83,20.92,15.45,17.57,24.80,24.24,24,14.8,74.85,33.33,10.83,49.21,25.56,64.72,-5.54,16.39,40.11,36.17


      Normally I would simply divide A by B to get the ratio between the two numbers, however these data vectors contain negative numbers meaning the magnitude of the absolute difference (A-B) between A and B is not being captured. Is there a way to transform the data such that I always get a positive ratio between the two numbers and that for example A=6.06 and B=-43.94 (absolute difference = 50.00) gives a larger ratio than e.g. A=60.00 and B=21.82?



      Thank you for your time,



      Laura







      ratio






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Jul 5 '17 at 14:40









      Laura Laura

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          You may use the formula for relative difference:
          $$frac{|x-y|}{max(|x|,|y|)}.$$
          It is always positive but between the values of $x, y$ at least one must be non-zero.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y?
            $endgroup$
            – Laura
            Jul 6 '17 at 9:19










          • $begingroup$
            Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum.
            $endgroup$
            – aleph
            Jul 6 '17 at 10:18










          • $begingroup$
            Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be: (18.40--2.40) / 18.4 I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?
            $endgroup$
            – Laura
            Jul 6 '17 at 10:29












          • $begingroup$
            Yes, that is correct :)
            $endgroup$
            – aleph
            Jul 6 '17 at 10:53












          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: "69"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          },
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2347368%2fcalculating-relative-difference-between-two-data-sets-which-include-negative-num%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$

          You may use the formula for relative difference:
          $$frac{|x-y|}{max(|x|,|y|)}.$$
          It is always positive but between the values of $x, y$ at least one must be non-zero.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y?
            $endgroup$
            – Laura
            Jul 6 '17 at 9:19










          • $begingroup$
            Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum.
            $endgroup$
            – aleph
            Jul 6 '17 at 10:18










          • $begingroup$
            Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be: (18.40--2.40) / 18.4 I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?
            $endgroup$
            – Laura
            Jul 6 '17 at 10:29












          • $begingroup$
            Yes, that is correct :)
            $endgroup$
            – aleph
            Jul 6 '17 at 10:53
















          0












          $begingroup$

          You may use the formula for relative difference:
          $$frac{|x-y|}{max(|x|,|y|)}.$$
          It is always positive but between the values of $x, y$ at least one must be non-zero.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y?
            $endgroup$
            – Laura
            Jul 6 '17 at 9:19










          • $begingroup$
            Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum.
            $endgroup$
            – aleph
            Jul 6 '17 at 10:18










          • $begingroup$
            Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be: (18.40--2.40) / 18.4 I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?
            $endgroup$
            – Laura
            Jul 6 '17 at 10:29












          • $begingroup$
            Yes, that is correct :)
            $endgroup$
            – aleph
            Jul 6 '17 at 10:53














          0












          0








          0





          $begingroup$

          You may use the formula for relative difference:
          $$frac{|x-y|}{max(|x|,|y|)}.$$
          It is always positive but between the values of $x, y$ at least one must be non-zero.






          share|cite|improve this answer









          $endgroup$



          You may use the formula for relative difference:
          $$frac{|x-y|}{max(|x|,|y|)}.$$
          It is always positive but between the values of $x, y$ at least one must be non-zero.







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Jul 5 '17 at 15:41









          alephaleph

          177




          177












          • $begingroup$
            Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y?
            $endgroup$
            – Laura
            Jul 6 '17 at 9:19










          • $begingroup$
            Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum.
            $endgroup$
            – aleph
            Jul 6 '17 at 10:18










          • $begingroup$
            Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be: (18.40--2.40) / 18.4 I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?
            $endgroup$
            – Laura
            Jul 6 '17 at 10:29












          • $begingroup$
            Yes, that is correct :)
            $endgroup$
            – aleph
            Jul 6 '17 at 10:53


















          • $begingroup$
            Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y?
            $endgroup$
            – Laura
            Jul 6 '17 at 9:19










          • $begingroup$
            Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum.
            $endgroup$
            – aleph
            Jul 6 '17 at 10:18










          • $begingroup$
            Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be: (18.40--2.40) / 18.4 I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?
            $endgroup$
            – Laura
            Jul 6 '17 at 10:29












          • $begingroup$
            Yes, that is correct :)
            $endgroup$
            – aleph
            Jul 6 '17 at 10:53
















          $begingroup$
          Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y?
          $endgroup$
          – Laura
          Jul 6 '17 at 9:19




          $begingroup$
          Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y?
          $endgroup$
          – Laura
          Jul 6 '17 at 9:19












          $begingroup$
          Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum.
          $endgroup$
          – aleph
          Jul 6 '17 at 10:18




          $begingroup$
          Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum.
          $endgroup$
          – aleph
          Jul 6 '17 at 10:18












          $begingroup$
          Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be: (18.40--2.40) / 18.4 I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?
          $endgroup$
          – Laura
          Jul 6 '17 at 10:29






          $begingroup$
          Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be: (18.40--2.40) / 18.4 I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?
          $endgroup$
          – Laura
          Jul 6 '17 at 10:29














          $begingroup$
          Yes, that is correct :)
          $endgroup$
          – aleph
          Jul 6 '17 at 10:53




          $begingroup$
          Yes, that is correct :)
          $endgroup$
          – aleph
          Jul 6 '17 at 10:53


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematics 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%2fmath.stackexchange.com%2fquestions%2f2347368%2fcalculating-relative-difference-between-two-data-sets-which-include-negative-num%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

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter