how to test a hypothesis with t-test or p value

253 visualizaciones (últimos 30 días)
farfar
farfar el 22 de Mzo. de 2017
Comentada: farfar el 22 de Mzo. de 2017
Hello I am testing the null hypothesis mu=3.4 against mu>3.4, for a sample of size 9. I want to test this with both t-distribution table and p-value but its giving me NaN instead of 0 or 1.this is the code im using :
mu = 3.4; % Population mean
sample=[3.4,3.6,3.8, 3.3,3.4,3.5,3.7,3.6,3.7]
n = numel(sample)
xobs = mean(sample) % Sample mean
s = std(sample) % Sample standard deviation
t = (xobs - mu)/(s/sqrt(n))
p = 1-tcdf(t,n-1)
[h,ptest] = ttest(xobs,mu,0.05,'right')
Thank you

Respuesta aceptada

the cyclist
the cyclist el 22 de Mzo. de 2017
I can't look at this fully right now, but one thing I notice immediately is that you are putting the mean value of the sample as the first argument of ttest(), but you should be putting the sample itself:
ttest(sample,mu,0.05,'right')
I don't know if that is the only problem with your code, but is is definitely a problem with it. :-)
  4 comentarios
the cyclist
the cyclist el 22 de Mzo. de 2017
Editada: the cyclist el 22 de Mzo. de 2017
You can't do a t-test with just the sample mean. You need the distribution. This is pretty obvious if you consider the two samples
sample = [10 10 10 10 10 10 10];
and
sample = [-8 0 7 10 13 20 28];
which have the same mean, but obviously different likelihood of being different from the population mean.
The specific reason you get NaN from what you are doing is that you are putting in a "sample" of one value, and the t-test is ill-defined for a sample size of one.
farfar
farfar el 22 de Mzo. de 2017
Tnx!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by