'manual' t-test gives different result for same t-value
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
John D'Errico
2021-11-30
编辑:John D'Errico
2021-11-30
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!