'manual' t-test gives different result for same t-value

9 visualizaciones (últimos 30 días)
Philipp Zelger
Philipp Zelger el 30 de Nov. de 2021
Editada: John D'Errico el 30 de Nov. de 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)])
t-value = 1.598
p_val = tpdf(t_val,9);
disp(['p-value = ',num2str(p_val)])
p-value = 0.1113
[~,p,~,stats]=ttest(Sample1,mu)
p = 0.1445
stats = struct with fields:
tstat: 1.5980 df: 9 sd: 13.2585
disp(['p-value = ',num2str(p)])
p-value = 0.14451
Shouldn't the results be the same, since the t-value is the same?

Respuesta aceptada

John D'Errico
John D'Errico el 30 de Nov. de 2021
Editada: John D'Errico el 30 de Nov. de 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))
t_val = 1.5980
So we have tval.
But now you did this:
p_val = tpdf(t_val,9)
p_val = 0.1113
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)
p = 0.1445
stats = struct with fields:
tstat: 1.5980 df: 9 sd: 13.2585
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
ans = 0.1445
So a two sided t-test, since the t-distribution is symmetrical.
Using the pdf there as you did is simply incorrect.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by