Calculating T2 statistics in R












2














I have a matrix x:



> x
x1 x2
[1,] 6 9
[2,] 10 6
[3,] 8 3


I am trying to T^2 statistics:



> library(DescTools)
> HotellingsT2Test(x)

Hotelling's one sample T2-test for mu' = [9, 5]

data: x
T.2 = 28, df1 = 2, df2 = 1, p-value = 0.1325
alternative hypothesis: true location is not equal to c(0,0)


The statistics seems to be off (the correct answer is 7/9). What am I doing wrong?



Other variables:



 > mu
[1] 9 5
> means
x1 x2
8 6
> S # variance-covariance matrix
[,1] [,2]
[1,] 4 -3
[2,] -3 9
> S_inv # inverse matrix
[,1] [,2]
[1,] 0.3333333 0.1111111
[2,] 0.1111111 0.1481481









share|improve this question



























    2














    I have a matrix x:



    > x
    x1 x2
    [1,] 6 9
    [2,] 10 6
    [3,] 8 3


    I am trying to T^2 statistics:



    > library(DescTools)
    > HotellingsT2Test(x)

    Hotelling's one sample T2-test for mu' = [9, 5]

    data: x
    T.2 = 28, df1 = 2, df2 = 1, p-value = 0.1325
    alternative hypothesis: true location is not equal to c(0,0)


    The statistics seems to be off (the correct answer is 7/9). What am I doing wrong?



    Other variables:



     > mu
    [1] 9 5
    > means
    x1 x2
    8 6
    > S # variance-covariance matrix
    [,1] [,2]
    [1,] 4 -3
    [2,] -3 9
    > S_inv # inverse matrix
    [,1] [,2]
    [1,] 0.3333333 0.1111111
    [2,] 0.1111111 0.1481481









    share|improve this question

























      2












      2








      2







      I have a matrix x:



      > x
      x1 x2
      [1,] 6 9
      [2,] 10 6
      [3,] 8 3


      I am trying to T^2 statistics:



      > library(DescTools)
      > HotellingsT2Test(x)

      Hotelling's one sample T2-test for mu' = [9, 5]

      data: x
      T.2 = 28, df1 = 2, df2 = 1, p-value = 0.1325
      alternative hypothesis: true location is not equal to c(0,0)


      The statistics seems to be off (the correct answer is 7/9). What am I doing wrong?



      Other variables:



       > mu
      [1] 9 5
      > means
      x1 x2
      8 6
      > S # variance-covariance matrix
      [,1] [,2]
      [1,] 4 -3
      [2,] -3 9
      > S_inv # inverse matrix
      [,1] [,2]
      [1,] 0.3333333 0.1111111
      [2,] 0.1111111 0.1481481









      share|improve this question













      I have a matrix x:



      > x
      x1 x2
      [1,] 6 9
      [2,] 10 6
      [3,] 8 3


      I am trying to T^2 statistics:



      > library(DescTools)
      > HotellingsT2Test(x)

      Hotelling's one sample T2-test for mu' = [9, 5]

      data: x
      T.2 = 28, df1 = 2, df2 = 1, p-value = 0.1325
      alternative hypothesis: true location is not equal to c(0,0)


      The statistics seems to be off (the correct answer is 7/9). What am I doing wrong?



      Other variables:



       > mu
      [1] 9 5
      > means
      x1 x2
      8 6
      > S # variance-covariance matrix
      [,1] [,2]
      [1,] 4 -3
      [2,] -3 9
      > S_inv # inverse matrix
      [,1] [,2]
      [1,] 0.3333333 0.1111111
      [2,] 0.1111111 0.1481481






      r matrix mean covariance variance






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 19:59









      Feyzi BagirovFeyzi Bagirov

      3901722




      3901722
























          1 Answer
          1






          active

          oldest

          votes


















          1














          First, you are not providing the mu parameter to the function. But then



          HotellingsT2Test(x, mu = mu)
          #
          # Hotelling's one sample T2-test
          #
          # data: x
          # T.2 = 0.19444, df1 = 2, df2 = 1, p-value = 0.8485
          # alternative hypothesis: true location is not equal to c(9,5)


          still isn't what you expect, and that is because by default the decision is based on the F-distribution, in which case the statistic is multiplied by another factor (which is (n - p)/(p * (n - 1)), with n = 3 and p = 2 in your case). Using chi-squared approximation we get, as needed,



          HotellingsT2Test(x, mu = mu, test = "chi")
          #
          # Hotelling's one sample T2-test
          #
          # data: x
          # T.2 = 0.77778, df = 2, p-value = 0.6778
          # alternative hypothesis: true location is not equal to c(9,5)





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452343%2fcalculating-t2-statistics-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









            1














            First, you are not providing the mu parameter to the function. But then



            HotellingsT2Test(x, mu = mu)
            #
            # Hotelling's one sample T2-test
            #
            # data: x
            # T.2 = 0.19444, df1 = 2, df2 = 1, p-value = 0.8485
            # alternative hypothesis: true location is not equal to c(9,5)


            still isn't what you expect, and that is because by default the decision is based on the F-distribution, in which case the statistic is multiplied by another factor (which is (n - p)/(p * (n - 1)), with n = 3 and p = 2 in your case). Using chi-squared approximation we get, as needed,



            HotellingsT2Test(x, mu = mu, test = "chi")
            #
            # Hotelling's one sample T2-test
            #
            # data: x
            # T.2 = 0.77778, df = 2, p-value = 0.6778
            # alternative hypothesis: true location is not equal to c(9,5)





            share|improve this answer


























              1














              First, you are not providing the mu parameter to the function. But then



              HotellingsT2Test(x, mu = mu)
              #
              # Hotelling's one sample T2-test
              #
              # data: x
              # T.2 = 0.19444, df1 = 2, df2 = 1, p-value = 0.8485
              # alternative hypothesis: true location is not equal to c(9,5)


              still isn't what you expect, and that is because by default the decision is based on the F-distribution, in which case the statistic is multiplied by another factor (which is (n - p)/(p * (n - 1)), with n = 3 and p = 2 in your case). Using chi-squared approximation we get, as needed,



              HotellingsT2Test(x, mu = mu, test = "chi")
              #
              # Hotelling's one sample T2-test
              #
              # data: x
              # T.2 = 0.77778, df = 2, p-value = 0.6778
              # alternative hypothesis: true location is not equal to c(9,5)





              share|improve this answer
























                1












                1








                1






                First, you are not providing the mu parameter to the function. But then



                HotellingsT2Test(x, mu = mu)
                #
                # Hotelling's one sample T2-test
                #
                # data: x
                # T.2 = 0.19444, df1 = 2, df2 = 1, p-value = 0.8485
                # alternative hypothesis: true location is not equal to c(9,5)


                still isn't what you expect, and that is because by default the decision is based on the F-distribution, in which case the statistic is multiplied by another factor (which is (n - p)/(p * (n - 1)), with n = 3 and p = 2 in your case). Using chi-squared approximation we get, as needed,



                HotellingsT2Test(x, mu = mu, test = "chi")
                #
                # Hotelling's one sample T2-test
                #
                # data: x
                # T.2 = 0.77778, df = 2, p-value = 0.6778
                # alternative hypothesis: true location is not equal to c(9,5)





                share|improve this answer












                First, you are not providing the mu parameter to the function. But then



                HotellingsT2Test(x, mu = mu)
                #
                # Hotelling's one sample T2-test
                #
                # data: x
                # T.2 = 0.19444, df1 = 2, df2 = 1, p-value = 0.8485
                # alternative hypothesis: true location is not equal to c(9,5)


                still isn't what you expect, and that is because by default the decision is based on the F-distribution, in which case the statistic is multiplied by another factor (which is (n - p)/(p * (n - 1)), with n = 3 and p = 2 in your case). Using chi-squared approximation we get, as needed,



                HotellingsT2Test(x, mu = mu, test = "chi")
                #
                # Hotelling's one sample T2-test
                #
                # data: x
                # T.2 = 0.77778, df = 2, p-value = 0.6778
                # alternative hypothesis: true location is not equal to c(9,5)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 20:13









                Julius VainoraJulius Vainora

                33.3k75979




                33.3k75979






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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.


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





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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.


                    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%2fstackoverflow.com%2fquestions%2f53452343%2fcalculating-t2-statistics-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

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)