how to test a hypothesis with t-test or p value
131 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
the cyclist
2017 年 3 月 22 日
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 件のコメント
the cyclist
2017 年 3 月 22 日
編集済み: the cyclist
2017 年 3 月 22 日
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!