Storing p-values from multiple 2 sample t-tests in R












1















Good evening,
I'm working on a class project and I am trying to do multiple unpaired 2 sample t-tests and then storing their p-values so that I can work with just the p-values later
Below is the code I have been trying:



pVals_1Beta <-vector("numeric", length = nrow(group1_Y_Beta))

for (i in 1:nrow(group1_Y_Beta)) {
pVals_1Beta[i] <- t.test(x = group1_Y_Beta$values[i,],
y = group1_N_Beta$values[i,],
paired = FALSE,
var.equal =FALSE,
conf.level = 0.95)$p.value
}


where group1_Y_Beta and group1_N_Beta have two columns(values and ind) and about 110312 rows and I want to do run unpaired t-test comparing the two groups values and store all 110312 p-values. When I try running this I get:




Error in group1_Y_Beta$values[i, ] : incorrect number of dimensions




Any help on how to tweak my code to get it to work would be greatly appreciated.



THanks, LIz










share|improve this question





























    1















    Good evening,
    I'm working on a class project and I am trying to do multiple unpaired 2 sample t-tests and then storing their p-values so that I can work with just the p-values later
    Below is the code I have been trying:



    pVals_1Beta <-vector("numeric", length = nrow(group1_Y_Beta))

    for (i in 1:nrow(group1_Y_Beta)) {
    pVals_1Beta[i] <- t.test(x = group1_Y_Beta$values[i,],
    y = group1_N_Beta$values[i,],
    paired = FALSE,
    var.equal =FALSE,
    conf.level = 0.95)$p.value
    }


    where group1_Y_Beta and group1_N_Beta have two columns(values and ind) and about 110312 rows and I want to do run unpaired t-test comparing the two groups values and store all 110312 p-values. When I try running this I get:




    Error in group1_Y_Beta$values[i, ] : incorrect number of dimensions




    Any help on how to tweak my code to get it to work would be greatly appreciated.



    THanks, LIz










    share|improve this question



























      1












      1








      1








      Good evening,
      I'm working on a class project and I am trying to do multiple unpaired 2 sample t-tests and then storing their p-values so that I can work with just the p-values later
      Below is the code I have been trying:



      pVals_1Beta <-vector("numeric", length = nrow(group1_Y_Beta))

      for (i in 1:nrow(group1_Y_Beta)) {
      pVals_1Beta[i] <- t.test(x = group1_Y_Beta$values[i,],
      y = group1_N_Beta$values[i,],
      paired = FALSE,
      var.equal =FALSE,
      conf.level = 0.95)$p.value
      }


      where group1_Y_Beta and group1_N_Beta have two columns(values and ind) and about 110312 rows and I want to do run unpaired t-test comparing the two groups values and store all 110312 p-values. When I try running this I get:




      Error in group1_Y_Beta$values[i, ] : incorrect number of dimensions




      Any help on how to tweak my code to get it to work would be greatly appreciated.



      THanks, LIz










      share|improve this question
















      Good evening,
      I'm working on a class project and I am trying to do multiple unpaired 2 sample t-tests and then storing their p-values so that I can work with just the p-values later
      Below is the code I have been trying:



      pVals_1Beta <-vector("numeric", length = nrow(group1_Y_Beta))

      for (i in 1:nrow(group1_Y_Beta)) {
      pVals_1Beta[i] <- t.test(x = group1_Y_Beta$values[i,],
      y = group1_N_Beta$values[i,],
      paired = FALSE,
      var.equal =FALSE,
      conf.level = 0.95)$p.value
      }


      where group1_Y_Beta and group1_N_Beta have two columns(values and ind) and about 110312 rows and I want to do run unpaired t-test comparing the two groups values and store all 110312 p-values. When I try running this I get:




      Error in group1_Y_Beta$values[i, ] : incorrect number of dimensions




      Any help on how to tweak my code to get it to work would be greatly appreciated.



      THanks, LIz







      r for-loop p-value t-test






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 7:09









      jacky_learns_to_code

      4692620




      4692620










      asked Nov 23 '18 at 2:14









      Liz M.Liz M.

      82




      82
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Since group1_N_Beta and group1_Y_Beta are 2D objects, you need (1) row and (2) column identifier in order to obtain a specific cell's value. But since you already specified the name of the column using the $ notation, you only need to provide one number (or a vector of numbers) to complete the query. Replace [i,] ("ith row, all columns") with [i]






          share|improve this answer
























          • Thank you so much for responding so i tried out your suggestion and am now getting the error: Error in t.test.default(x = group1_Y_Beta$values[i], y = group1_N_Beta$values[i], : not enough 'x' observations

            – Liz M.
            Nov 24 '18 at 15:10













          • What's the size of each vector? You can find that out by passing the name of the vector (group1_Y_Beta$values[i]) to length ()

            – 12b345b6b78
            Nov 24 '18 at 19:17











          • When I pass it through it returns 1

            – Liz M.
            Nov 24 '18 at 20:03











          • Is it supposed to return 1 ?

            – Liz M.
            Nov 26 '18 at 14:38











          • It's not! It means you either have one observation only (not enough for a t-test), or it's something else (data-structure-wise). If you could update the original post with sample data, that would help greatly!

            – 12b345b6b78
            Nov 26 '18 at 15:28











          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%2f53439897%2fstoring-p-values-from-multiple-2-sample-t-tests-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














          Since group1_N_Beta and group1_Y_Beta are 2D objects, you need (1) row and (2) column identifier in order to obtain a specific cell's value. But since you already specified the name of the column using the $ notation, you only need to provide one number (or a vector of numbers) to complete the query. Replace [i,] ("ith row, all columns") with [i]






          share|improve this answer
























          • Thank you so much for responding so i tried out your suggestion and am now getting the error: Error in t.test.default(x = group1_Y_Beta$values[i], y = group1_N_Beta$values[i], : not enough 'x' observations

            – Liz M.
            Nov 24 '18 at 15:10













          • What's the size of each vector? You can find that out by passing the name of the vector (group1_Y_Beta$values[i]) to length ()

            – 12b345b6b78
            Nov 24 '18 at 19:17











          • When I pass it through it returns 1

            – Liz M.
            Nov 24 '18 at 20:03











          • Is it supposed to return 1 ?

            – Liz M.
            Nov 26 '18 at 14:38











          • It's not! It means you either have one observation only (not enough for a t-test), or it's something else (data-structure-wise). If you could update the original post with sample data, that would help greatly!

            – 12b345b6b78
            Nov 26 '18 at 15:28
















          0














          Since group1_N_Beta and group1_Y_Beta are 2D objects, you need (1) row and (2) column identifier in order to obtain a specific cell's value. But since you already specified the name of the column using the $ notation, you only need to provide one number (or a vector of numbers) to complete the query. Replace [i,] ("ith row, all columns") with [i]






          share|improve this answer
























          • Thank you so much for responding so i tried out your suggestion and am now getting the error: Error in t.test.default(x = group1_Y_Beta$values[i], y = group1_N_Beta$values[i], : not enough 'x' observations

            – Liz M.
            Nov 24 '18 at 15:10













          • What's the size of each vector? You can find that out by passing the name of the vector (group1_Y_Beta$values[i]) to length ()

            – 12b345b6b78
            Nov 24 '18 at 19:17











          • When I pass it through it returns 1

            – Liz M.
            Nov 24 '18 at 20:03











          • Is it supposed to return 1 ?

            – Liz M.
            Nov 26 '18 at 14:38











          • It's not! It means you either have one observation only (not enough for a t-test), or it's something else (data-structure-wise). If you could update the original post with sample data, that would help greatly!

            – 12b345b6b78
            Nov 26 '18 at 15:28














          0












          0








          0







          Since group1_N_Beta and group1_Y_Beta are 2D objects, you need (1) row and (2) column identifier in order to obtain a specific cell's value. But since you already specified the name of the column using the $ notation, you only need to provide one number (or a vector of numbers) to complete the query. Replace [i,] ("ith row, all columns") with [i]






          share|improve this answer













          Since group1_N_Beta and group1_Y_Beta are 2D objects, you need (1) row and (2) column identifier in order to obtain a specific cell's value. But since you already specified the name of the column using the $ notation, you only need to provide one number (or a vector of numbers) to complete the query. Replace [i,] ("ith row, all columns") with [i]







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 3:51









          12b345b6b7812b345b6b78

          782115




          782115













          • Thank you so much for responding so i tried out your suggestion and am now getting the error: Error in t.test.default(x = group1_Y_Beta$values[i], y = group1_N_Beta$values[i], : not enough 'x' observations

            – Liz M.
            Nov 24 '18 at 15:10













          • What's the size of each vector? You can find that out by passing the name of the vector (group1_Y_Beta$values[i]) to length ()

            – 12b345b6b78
            Nov 24 '18 at 19:17











          • When I pass it through it returns 1

            – Liz M.
            Nov 24 '18 at 20:03











          • Is it supposed to return 1 ?

            – Liz M.
            Nov 26 '18 at 14:38











          • It's not! It means you either have one observation only (not enough for a t-test), or it's something else (data-structure-wise). If you could update the original post with sample data, that would help greatly!

            – 12b345b6b78
            Nov 26 '18 at 15:28



















          • Thank you so much for responding so i tried out your suggestion and am now getting the error: Error in t.test.default(x = group1_Y_Beta$values[i], y = group1_N_Beta$values[i], : not enough 'x' observations

            – Liz M.
            Nov 24 '18 at 15:10













          • What's the size of each vector? You can find that out by passing the name of the vector (group1_Y_Beta$values[i]) to length ()

            – 12b345b6b78
            Nov 24 '18 at 19:17











          • When I pass it through it returns 1

            – Liz M.
            Nov 24 '18 at 20:03











          • Is it supposed to return 1 ?

            – Liz M.
            Nov 26 '18 at 14:38











          • It's not! It means you either have one observation only (not enough for a t-test), or it's something else (data-structure-wise). If you could update the original post with sample data, that would help greatly!

            – 12b345b6b78
            Nov 26 '18 at 15:28

















          Thank you so much for responding so i tried out your suggestion and am now getting the error: Error in t.test.default(x = group1_Y_Beta$values[i], y = group1_N_Beta$values[i], : not enough 'x' observations

          – Liz M.
          Nov 24 '18 at 15:10







          Thank you so much for responding so i tried out your suggestion and am now getting the error: Error in t.test.default(x = group1_Y_Beta$values[i], y = group1_N_Beta$values[i], : not enough 'x' observations

          – Liz M.
          Nov 24 '18 at 15:10















          What's the size of each vector? You can find that out by passing the name of the vector (group1_Y_Beta$values[i]) to length ()

          – 12b345b6b78
          Nov 24 '18 at 19:17





          What's the size of each vector? You can find that out by passing the name of the vector (group1_Y_Beta$values[i]) to length ()

          – 12b345b6b78
          Nov 24 '18 at 19:17













          When I pass it through it returns 1

          – Liz M.
          Nov 24 '18 at 20:03





          When I pass it through it returns 1

          – Liz M.
          Nov 24 '18 at 20:03













          Is it supposed to return 1 ?

          – Liz M.
          Nov 26 '18 at 14:38





          Is it supposed to return 1 ?

          – Liz M.
          Nov 26 '18 at 14:38













          It's not! It means you either have one observation only (not enough for a t-test), or it's something else (data-structure-wise). If you could update the original post with sample data, that would help greatly!

          – 12b345b6b78
          Nov 26 '18 at 15:28





          It's not! It means you either have one observation only (not enough for a t-test), or it's something else (data-structure-wise). If you could update the original post with sample data, that would help greatly!

          – 12b345b6b78
          Nov 26 '18 at 15:28




















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439897%2fstoring-p-values-from-multiple-2-sample-t-tests-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

          Costa Masnaga

          Fotorealismo

          Sidney Franklin