Storing p-values from multiple 2 sample t-tests in R
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
add a comment |
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
add a comment |
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
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
r for-loop p-value t-test
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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]
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]
) tolength ()
– 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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]
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]
) tolength ()
– 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
add a comment |
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]
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]
) tolength ()
– 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
add a comment |
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]
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]
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]
) tolength ()
– 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
add a comment |
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]
) tolength ()
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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