Calculating T2 statistics in R
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
add a comment |
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
add a comment |
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
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
r matrix mean covariance variance
asked Nov 23 '18 at 19:59
Feyzi BagirovFeyzi Bagirov
3901722
3901722
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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)
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%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
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)
add a comment |
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)
add a comment |
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)
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)
answered Nov 23 '18 at 20:13
Julius VainoraJulius Vainora
33.3k75979
33.3k75979
add a comment |
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.
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.
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%2f53452343%2fcalculating-t2-statistics-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