'manual' t-test gives different result for same t-value
10 views (last 30 days)
Show older comments
Philipp Zelger
on 30 Nov 2021
Edited: John D'Errico
on 30 Nov 2021
Hello, maybe someon can help. Why do I get a different result for the p-value if I enter the tstat-value in to the tpdf-distribution?
mu=500;
sigma=25;
Sample1 = [486,520,497,510,515,521,512,490,520,496];
t_val = sqrt(length(Sample1))*(mean(Sample1) - mu)/sqrt(var(Sample1));
disp(['t-value = ',num2str(t_val)])
p_val = tpdf(t_val,9);
disp(['p-value = ',num2str(p_val)])
[~,p,~,stats]=ttest(Sample1,mu)
disp(['p-value = ',num2str(p)])
Shouldn't the results be the same, since the t-value is the same?
0 Comments
Accepted Answer
John D'Errico
on 30 Nov 2021
Edited: John D'Errico
on 30 Nov 2021
I think you misunderstand what a pdf is, when to use a cdf versus a pdf, or perhaps how the t-test works. Maybe all of those are issues here.
mu=500;
sigma=25;
Sample1 = [486,520,497,510,515,521,512,490,520,496];
t_val = sqrt(length(Sample1))*(mean(Sample1) - mu)/sqrt(var(Sample1))
So we have tval.
But now you did this:
p_val = tpdf(t_val,9)
I'm not certain what you think that does. Do you think that sets some p value for the ttest? The ttest function does not know anything about the variable p_val, nor does it care. Hmm. I see. It looks like you expected p_val to be the same thing as the number p as returned from ttest?
[~,p,~,stats]=ttest(Sample1,mu)
The variable p that is returned from ttest comes from an integral of the t pdf. That 0.1445 is derived from the tcdf function. We can get that value as:
tcdf(stats.tstat,9,'upper')*2
So a two sided t-test, since the t-distribution is symmetrical.
Using the pdf there as you did is simply incorrect.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!