difference in test statistic and p-value R and Python script Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)ADF: Reject or keep null hypothesis (difference p-value & test statistic)What is the difference between $t$-statistic and test-statistic?Hypothesis testing: t-test and p-value conflictWhich test to calculate the p-value?Conflicting results of summary() and anova() for a mixed model with interactions in lmer+lmerTestks_2samp test in Python scipy - low D statistic, low p-value?Calculating a p-value from the t-statistic of a two sided test?P Value query, Independent t-testReproducing t-test in R gives different result than built-in functionHow are degrees of freedom used in the Welch's t-test to determine p-value?
Find 108 by using 3,4,6
Is this another way of expressing the side limit?
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
Take 2! Is this homebrew Lady of Pain warlock patron balanced?
How were pictures turned from film to a big picture in a picture frame before digital scanning?
Why is Nikon 1.4g better when Nikon 1.8g is sharper?
Most bit efficient text communication method?
How to improve on this Stylesheet Manipulation for Message Styling
I want to complete my figure
What is "gratricide"?
What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?
How does light 'choose' between wave and particle behaviour?
How often does castling occur in grandmaster games?
Effects on objects due to a brief relocation of massive amounts of mass
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
What is this clumpy 20-30cm high yellow-flowered plant?
How to draw/optimize this graph with tikz
A term for a woman complaining about things/begging in a cute/childish way
"Lost his faith in humanity in the trenches of Verdun" — last line of an SF story
An adverb for when you're not exaggerating
What is the meaning of 'breadth' in breadth first search?
If Windows 7 doesn't support WSL, then what does Linux subsystem option mean?
Strange behavior of Object.defineProperty() in JavaScript
Why is it faster to reheat something than it is to cook it?
difference in test statistic and p-value R and Python script
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)ADF: Reject or keep null hypothesis (difference p-value & test statistic)What is the difference between $t$-statistic and test-statistic?Hypothesis testing: t-test and p-value conflictWhich test to calculate the p-value?Conflicting results of summary() and anova() for a mixed model with interactions in lmer+lmerTestks_2samp test in Python scipy - low D statistic, low p-value?Calculating a p-value from the t-statistic of a two sided test?P Value query, Independent t-testReproducing t-test in R gives different result than built-in functionHow are degrees of freedom used in the Welch's t-test to determine p-value?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I am trying to compute welch's t-test statistic and p-value manually for educational purpose.
I have written a function for welch's t-test as follows,
def welch_t_test(vec_a, vec_b):
mean_a = vec_a.mean()
mean_b = vec_b.mean()
var_a = vec_a.var()
var_b = vec_b.var()
T = (mean_a - mean_b)/((var_a-vec_a.size) + (var_b-vec_b.size))
return T
This function returns T-test statistic. To find p-value, I am using pt
function from R-3.3.3
.
My example inputs:
A = [6,3,0,7,7,0,5,7,7,6]
B = [10,18,14,18,12,13,15,18,16,18]
My test statisitc is:
Test statistic: -7.065217391304347
When I try to compute p-value using pt
of R like pt(-7.06521,19)
I get 5.038877e-07
whereas My R
s defualt t.test
function result yields test statistic of -8.1321
and p-value of 1.95e07
. I see the qualitatively both are similar but there exists a quantitative difference. Could someone point out why is that so? And also df
in R shows some fractional number, in my case df
of R is 17.987
which I suppose 19
following n-1
formula for degrees of freedom.
t-test p-value
$endgroup$
add a comment |
$begingroup$
I am trying to compute welch's t-test statistic and p-value manually for educational purpose.
I have written a function for welch's t-test as follows,
def welch_t_test(vec_a, vec_b):
mean_a = vec_a.mean()
mean_b = vec_b.mean()
var_a = vec_a.var()
var_b = vec_b.var()
T = (mean_a - mean_b)/((var_a-vec_a.size) + (var_b-vec_b.size))
return T
This function returns T-test statistic. To find p-value, I am using pt
function from R-3.3.3
.
My example inputs:
A = [6,3,0,7,7,0,5,7,7,6]
B = [10,18,14,18,12,13,15,18,16,18]
My test statisitc is:
Test statistic: -7.065217391304347
When I try to compute p-value using pt
of R like pt(-7.06521,19)
I get 5.038877e-07
whereas My R
s defualt t.test
function result yields test statistic of -8.1321
and p-value of 1.95e07
. I see the qualitatively both are similar but there exists a quantitative difference. Could someone point out why is that so? And also df
in R shows some fractional number, in my case df
of R is 17.987
which I suppose 19
following n-1
formula for degrees of freedom.
t-test p-value
$endgroup$
1
$begingroup$
At first glance--In your first block of code, I think your denominator for the Welch t statistic is incorrect. I will give it a try. It's always a good idea to make sure software is giving answers that agree with known formulas.
$endgroup$
– BruceET
3 hours ago
add a comment |
$begingroup$
I am trying to compute welch's t-test statistic and p-value manually for educational purpose.
I have written a function for welch's t-test as follows,
def welch_t_test(vec_a, vec_b):
mean_a = vec_a.mean()
mean_b = vec_b.mean()
var_a = vec_a.var()
var_b = vec_b.var()
T = (mean_a - mean_b)/((var_a-vec_a.size) + (var_b-vec_b.size))
return T
This function returns T-test statistic. To find p-value, I am using pt
function from R-3.3.3
.
My example inputs:
A = [6,3,0,7,7,0,5,7,7,6]
B = [10,18,14,18,12,13,15,18,16,18]
My test statisitc is:
Test statistic: -7.065217391304347
When I try to compute p-value using pt
of R like pt(-7.06521,19)
I get 5.038877e-07
whereas My R
s defualt t.test
function result yields test statistic of -8.1321
and p-value of 1.95e07
. I see the qualitatively both are similar but there exists a quantitative difference. Could someone point out why is that so? And also df
in R shows some fractional number, in my case df
of R is 17.987
which I suppose 19
following n-1
formula for degrees of freedom.
t-test p-value
$endgroup$
I am trying to compute welch's t-test statistic and p-value manually for educational purpose.
I have written a function for welch's t-test as follows,
def welch_t_test(vec_a, vec_b):
mean_a = vec_a.mean()
mean_b = vec_b.mean()
var_a = vec_a.var()
var_b = vec_b.var()
T = (mean_a - mean_b)/((var_a-vec_a.size) + (var_b-vec_b.size))
return T
This function returns T-test statistic. To find p-value, I am using pt
function from R-3.3.3
.
My example inputs:
A = [6,3,0,7,7,0,5,7,7,6]
B = [10,18,14,18,12,13,15,18,16,18]
My test statisitc is:
Test statistic: -7.065217391304347
When I try to compute p-value using pt
of R like pt(-7.06521,19)
I get 5.038877e-07
whereas My R
s defualt t.test
function result yields test statistic of -8.1321
and p-value of 1.95e07
. I see the qualitatively both are similar but there exists a quantitative difference. Could someone point out why is that so? And also df
in R shows some fractional number, in my case df
of R is 17.987
which I suppose 19
following n-1
formula for degrees of freedom.
t-test p-value
t-test p-value
asked 5 hours ago
RussellBRussellB
1226
1226
1
$begingroup$
At first glance--In your first block of code, I think your denominator for the Welch t statistic is incorrect. I will give it a try. It's always a good idea to make sure software is giving answers that agree with known formulas.
$endgroup$
– BruceET
3 hours ago
add a comment |
1
$begingroup$
At first glance--In your first block of code, I think your denominator for the Welch t statistic is incorrect. I will give it a try. It's always a good idea to make sure software is giving answers that agree with known formulas.
$endgroup$
– BruceET
3 hours ago
1
1
$begingroup$
At first glance--In your first block of code, I think your denominator for the Welch t statistic is incorrect. I will give it a try. It's always a good idea to make sure software is giving answers that agree with known formulas.
$endgroup$
– BruceET
3 hours ago
$begingroup$
At first glance--In your first block of code, I think your denominator for the Welch t statistic is incorrect. I will give it a try. It's always a good idea to make sure software is giving answers that agree with known formulas.
$endgroup$
– BruceET
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Welch t statistic:
Using R as a calculator:
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
m = length(A); n = length(B)
t = ( mean(A) - mean(B) ) / sqrt( var(A)/m + var(B)/n ); t
[1] -8.132062
From t.test
in R, where Welch is the default 2-sample t test.
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
t.test(A, B)
Welch Two Sample t-test
data: A and B
t = -8.1321, df = 17.987, p-value = 1.95e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-13.086987 -7.713013
sample estimates:
mean of x mean of y
4.8 15.2
So the two versions agree that $T = -8.1321.$
Welch degrees of freedom and P-values:
Traditionally, t distributions had integer degrees of freedom, but the
approximate DF for the Welch t test gives non-integer DF and there is no
problem extending the formula for the density function of t to accommodate
non-integer DF.
The (moderately messy) formula for DF of the Welch test can be found in
many statistics texts and in Wikipedia. This formula gives degrees of freedom $nu$ with
$$ min(m-1, n-1) le nu le m + n - 2.$$
Roughly speaking $nu$ is near the upper limit when sample sizes and sample variances are nearly equal.
Two-sided alternative. For the default 2-sided t test, the P-value in R
is obtained using the CDF function pt
. The result agrees with the rounded
value given in the printout. For closer comparison, the unrounded P-value can be obtained using $
-notation. (I think the very slight difference is that
R does not print the fractional degrees of freedom to more decimal places.)
2 * pt(-8.1321, 17.987)
[1] 1.949439e-07
t.test(A,B)$p.value
[1] 1.949789e-07
Left-sided alternative. For a left-sided test, the P-values from pt
and t.test
are again in
substantial agreement:
pt(-8.1321, 17.987)
[1] 9.747197e-08
t.test(A,B, alt="less")$p.value
[1] 9.748945e-08 # P-value captured from 't.test' procedure
t.test(A,B, alt="less")$parameter
df
17.98672
pt(t.test(A,B, alt="less")$statistic, t.test(A,B, alt="less")$parameter)
t
9.748945e-08 # exact agreement with exact DF
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "65"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fstats.stackexchange.com%2fquestions%2f403917%2fdifference-in-test-statistic-and-p-value-r-and-python-script%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
$begingroup$
Welch t statistic:
Using R as a calculator:
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
m = length(A); n = length(B)
t = ( mean(A) - mean(B) ) / sqrt( var(A)/m + var(B)/n ); t
[1] -8.132062
From t.test
in R, where Welch is the default 2-sample t test.
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
t.test(A, B)
Welch Two Sample t-test
data: A and B
t = -8.1321, df = 17.987, p-value = 1.95e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-13.086987 -7.713013
sample estimates:
mean of x mean of y
4.8 15.2
So the two versions agree that $T = -8.1321.$
Welch degrees of freedom and P-values:
Traditionally, t distributions had integer degrees of freedom, but the
approximate DF for the Welch t test gives non-integer DF and there is no
problem extending the formula for the density function of t to accommodate
non-integer DF.
The (moderately messy) formula for DF of the Welch test can be found in
many statistics texts and in Wikipedia. This formula gives degrees of freedom $nu$ with
$$ min(m-1, n-1) le nu le m + n - 2.$$
Roughly speaking $nu$ is near the upper limit when sample sizes and sample variances are nearly equal.
Two-sided alternative. For the default 2-sided t test, the P-value in R
is obtained using the CDF function pt
. The result agrees with the rounded
value given in the printout. For closer comparison, the unrounded P-value can be obtained using $
-notation. (I think the very slight difference is that
R does not print the fractional degrees of freedom to more decimal places.)
2 * pt(-8.1321, 17.987)
[1] 1.949439e-07
t.test(A,B)$p.value
[1] 1.949789e-07
Left-sided alternative. For a left-sided test, the P-values from pt
and t.test
are again in
substantial agreement:
pt(-8.1321, 17.987)
[1] 9.747197e-08
t.test(A,B, alt="less")$p.value
[1] 9.748945e-08 # P-value captured from 't.test' procedure
t.test(A,B, alt="less")$parameter
df
17.98672
pt(t.test(A,B, alt="less")$statistic, t.test(A,B, alt="less")$parameter)
t
9.748945e-08 # exact agreement with exact DF
$endgroup$
add a comment |
$begingroup$
Welch t statistic:
Using R as a calculator:
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
m = length(A); n = length(B)
t = ( mean(A) - mean(B) ) / sqrt( var(A)/m + var(B)/n ); t
[1] -8.132062
From t.test
in R, where Welch is the default 2-sample t test.
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
t.test(A, B)
Welch Two Sample t-test
data: A and B
t = -8.1321, df = 17.987, p-value = 1.95e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-13.086987 -7.713013
sample estimates:
mean of x mean of y
4.8 15.2
So the two versions agree that $T = -8.1321.$
Welch degrees of freedom and P-values:
Traditionally, t distributions had integer degrees of freedom, but the
approximate DF for the Welch t test gives non-integer DF and there is no
problem extending the formula for the density function of t to accommodate
non-integer DF.
The (moderately messy) formula for DF of the Welch test can be found in
many statistics texts and in Wikipedia. This formula gives degrees of freedom $nu$ with
$$ min(m-1, n-1) le nu le m + n - 2.$$
Roughly speaking $nu$ is near the upper limit when sample sizes and sample variances are nearly equal.
Two-sided alternative. For the default 2-sided t test, the P-value in R
is obtained using the CDF function pt
. The result agrees with the rounded
value given in the printout. For closer comparison, the unrounded P-value can be obtained using $
-notation. (I think the very slight difference is that
R does not print the fractional degrees of freedom to more decimal places.)
2 * pt(-8.1321, 17.987)
[1] 1.949439e-07
t.test(A,B)$p.value
[1] 1.949789e-07
Left-sided alternative. For a left-sided test, the P-values from pt
and t.test
are again in
substantial agreement:
pt(-8.1321, 17.987)
[1] 9.747197e-08
t.test(A,B, alt="less")$p.value
[1] 9.748945e-08 # P-value captured from 't.test' procedure
t.test(A,B, alt="less")$parameter
df
17.98672
pt(t.test(A,B, alt="less")$statistic, t.test(A,B, alt="less")$parameter)
t
9.748945e-08 # exact agreement with exact DF
$endgroup$
add a comment |
$begingroup$
Welch t statistic:
Using R as a calculator:
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
m = length(A); n = length(B)
t = ( mean(A) - mean(B) ) / sqrt( var(A)/m + var(B)/n ); t
[1] -8.132062
From t.test
in R, where Welch is the default 2-sample t test.
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
t.test(A, B)
Welch Two Sample t-test
data: A and B
t = -8.1321, df = 17.987, p-value = 1.95e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-13.086987 -7.713013
sample estimates:
mean of x mean of y
4.8 15.2
So the two versions agree that $T = -8.1321.$
Welch degrees of freedom and P-values:
Traditionally, t distributions had integer degrees of freedom, but the
approximate DF for the Welch t test gives non-integer DF and there is no
problem extending the formula for the density function of t to accommodate
non-integer DF.
The (moderately messy) formula for DF of the Welch test can be found in
many statistics texts and in Wikipedia. This formula gives degrees of freedom $nu$ with
$$ min(m-1, n-1) le nu le m + n - 2.$$
Roughly speaking $nu$ is near the upper limit when sample sizes and sample variances are nearly equal.
Two-sided alternative. For the default 2-sided t test, the P-value in R
is obtained using the CDF function pt
. The result agrees with the rounded
value given in the printout. For closer comparison, the unrounded P-value can be obtained using $
-notation. (I think the very slight difference is that
R does not print the fractional degrees of freedom to more decimal places.)
2 * pt(-8.1321, 17.987)
[1] 1.949439e-07
t.test(A,B)$p.value
[1] 1.949789e-07
Left-sided alternative. For a left-sided test, the P-values from pt
and t.test
are again in
substantial agreement:
pt(-8.1321, 17.987)
[1] 9.747197e-08
t.test(A,B, alt="less")$p.value
[1] 9.748945e-08 # P-value captured from 't.test' procedure
t.test(A,B, alt="less")$parameter
df
17.98672
pt(t.test(A,B, alt="less")$statistic, t.test(A,B, alt="less")$parameter)
t
9.748945e-08 # exact agreement with exact DF
$endgroup$
Welch t statistic:
Using R as a calculator:
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
m = length(A); n = length(B)
t = ( mean(A) - mean(B) ) / sqrt( var(A)/m + var(B)/n ); t
[1] -8.132062
From t.test
in R, where Welch is the default 2-sample t test.
A = c(6,3,0,7,7,0,5,7,7,6)
B = c(10,18,14,18,12,13,15,18,16,18)
t.test(A, B)
Welch Two Sample t-test
data: A and B
t = -8.1321, df = 17.987, p-value = 1.95e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-13.086987 -7.713013
sample estimates:
mean of x mean of y
4.8 15.2
So the two versions agree that $T = -8.1321.$
Welch degrees of freedom and P-values:
Traditionally, t distributions had integer degrees of freedom, but the
approximate DF for the Welch t test gives non-integer DF and there is no
problem extending the formula for the density function of t to accommodate
non-integer DF.
The (moderately messy) formula for DF of the Welch test can be found in
many statistics texts and in Wikipedia. This formula gives degrees of freedom $nu$ with
$$ min(m-1, n-1) le nu le m + n - 2.$$
Roughly speaking $nu$ is near the upper limit when sample sizes and sample variances are nearly equal.
Two-sided alternative. For the default 2-sided t test, the P-value in R
is obtained using the CDF function pt
. The result agrees with the rounded
value given in the printout. For closer comparison, the unrounded P-value can be obtained using $
-notation. (I think the very slight difference is that
R does not print the fractional degrees of freedom to more decimal places.)
2 * pt(-8.1321, 17.987)
[1] 1.949439e-07
t.test(A,B)$p.value
[1] 1.949789e-07
Left-sided alternative. For a left-sided test, the P-values from pt
and t.test
are again in
substantial agreement:
pt(-8.1321, 17.987)
[1] 9.747197e-08
t.test(A,B, alt="less")$p.value
[1] 9.748945e-08 # P-value captured from 't.test' procedure
t.test(A,B, alt="less")$parameter
df
17.98672
pt(t.test(A,B, alt="less")$statistic, t.test(A,B, alt="less")$parameter)
t
9.748945e-08 # exact agreement with exact DF
edited 4 hours ago
answered 4 hours ago
BruceETBruceET
6,8911721
6,8911721
add a comment |
add a comment |
Thanks for contributing an answer to Cross Validated!
- 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.
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%2fstats.stackexchange.com%2fquestions%2f403917%2fdifference-in-test-statistic-and-p-value-r-and-python-script%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
1
$begingroup$
At first glance--In your first block of code, I think your denominator for the Welch t statistic is incorrect. I will give it a try. It's always a good idea to make sure software is giving answers that agree with known formulas.
$endgroup$
– BruceET
3 hours ago