how to test a hypothesis with t-test or p value
132 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
the cyclist
il 22 Mar 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 Commenti
the cyclist
il 22 Mar 2017
Modificato: the cyclist
il 22 Mar 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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!